2026-06-10 23:21:01 -06:00
|
|
|
|
import { visit } from 'unist-util-visit';
|
|
|
|
|
|
|
2026-06-29 20:06:57 -06:00
|
|
|
|
let currentBook = '';
|
|
|
|
|
|
|
|
|
|
|
|
function scriptureLink(node, args) {
|
|
|
|
|
|
const value = node.children?.[0]?.value.trim() || '';
|
|
|
|
|
|
let passage = (args && args.length > 0 && args[0] != '') ? args[0] : value;
|
|
|
|
|
|
passage = passage.replaceAll(/–/g, '-');
|
|
|
|
|
|
|
|
|
|
|
|
if (passage.match(/^[-0-9:]+$/)) {
|
|
|
|
|
|
passage = `${currentBook} ${passage}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
passage = passage.toLowerCase();
|
|
|
|
|
|
passage = passage.replace(/pss/, 'ps');
|
|
|
|
|
|
const match = passage.match(/^(\d?\s*[-a-zA-Z]+)\s*\d+?/)
|
|
|
|
|
|
|
|
|
|
|
|
passage = passage.replaceAll(/ /g, '+');
|
|
|
|
|
|
passage = passage.replace(/\:/, '%3A');
|
|
|
|
|
|
|
|
|
|
|
|
if (passage !== '') {
|
|
|
|
|
|
node.properties.href = `https://www.biblegateway.com/passage/?search=${passage}&version=ESV`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
|
|
currentBook = match?.[1].trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-10 23:21:01 -06:00
|
|
|
|
export const ScriptureLinks = () => {
|
|
|
|
|
|
return async tree => {
|
|
|
|
|
|
visit(tree, 'element', (node) => {
|
2026-06-28 16:45:50 -06:00
|
|
|
|
let tag = '';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
let rest = '';
|
2026-06-10 23:21:01 -06:00
|
|
|
|
const url = node.properties.href;
|
|
|
|
|
|
if (node.tagName !== 'a') {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-06-28 16:45:50 -06:00
|
|
|
|
if (!url.startsWith(':')) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (url.indexOf('=') != -1) {
|
2026-06-29 20:06:57 -06:00
|
|
|
|
tag = url.substring(1, url.indexOf('='));
|
|
|
|
|
|
rest = url.substring(url.indexOf('=')+1);
|
2026-06-28 16:45:50 -06:00
|
|
|
|
} else {
|
|
|
|
|
|
tag = url.substring(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.class = 'scripture';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
switch (tag) {
|
|
|
|
|
|
// Scripture reference.
|
|
|
|
|
|
case 'scripture':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
scriptureLink(node, rest.split(','));
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Quoting Jesus' words.
|
|
|
|
|
|
case 'jesus':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
case 'christ':
|
|
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' christ';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Bible quote.
|
|
|
|
|
|
case 'quote':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' quote';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
// Source citation.
|
|
|
|
|
|
case 'cite':
|
2026-06-29 20:06:57 -06:00
|
|
|
|
node.properties.href = null;
|
|
|
|
|
|
node.properties.title = 'Scriptural citation or fragmentary citation';
|
|
|
|
|
|
node.properties.class += ' citation';
|
2026-06-29 16:13:41 -06:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-06-10 23:21:01 -06:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|