Parse marker shortcodes (WIP)

This commit is contained in:
2025-10-24 10:27:28 +02:00
parent 00cedfeb85
commit 952dc3f841
4 changed files with 31 additions and 3 deletions

View File

@@ -144,6 +144,30 @@ Utils.buildBibliography = async function(recordUri, recordId) {
return bibliography;
}
/**
*
* @param {String} text - The content text from database
* Parse marker strings (pseudo-shortcodes) and convert them
* to Stimulus links
*/
Utils.parseMarkers = function(text) {
const regex = /(?<marker>\[marker coords=\"(?<coords>[\d\s\.]+)\"\](?<content>[\w\s\.;:\-]+)\[\/marker\])/mig;
let matches = [...text.matchAll(regex)];
if (matches.length) {
matches.forEach(match => {
const replacement = `
<a data-action="marker#go modal#close" data-controller="marker" data-marker-coords-value="${match.groups.coords}">
${match.groups.content}
</a>
`;
text = text.replace(match.groups.marker, replacement);
});
}
return text;
}
Utils.fetchData = async function(url) {
return await fetch(url).then(res => res.ok ? res.json() : new Error())
.catch(err => console.log(err));