Parse marker shortcodes (WIP)
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user