Commit 0205c57b authored by Peter Langenkamp's avatar Peter Langenkamp

in glossery, show glossery text and process %%...^...%% syntax

parent 8ce48f40
Pipeline #17185 passed with stage
in 1 minute and 38 seconds
......@@ -123,9 +123,44 @@ async function getGlossaryTerms(files) {
let { metadata } = parseMD(content)
//keep only the required keys
if (metadata.title) {
let glossaryContent = metadata.glossaryText;
if (glossaryContent) {
// Regex for finding the pattern: %token_1,token_2%
reg = /\%%.*?\^.*?\%%/g;
// If there is at least one match between the content of the file and
// the regex, proceed
if ((regex_matches = glossaryContent.match(reg)) !== null) {
for(let regex_match of regex_matches) {
var token = regex_match.split('^');
// Find the path of the term
var reference = (token[1]).replace(/[%" ]/g, '');
var text = (token[0]).replace(/[%"]/g, '');
let referencePath = TERMS_DIR + reference + '.md';
// Get the popup text for the term
let hoverText = await getHoverText(referencePath);
const current_file_path = path.resolve(process.cwd(), filepath);
const term_path = path.resolve(process.cwd(), TERMS_DIR, reference);
const new_final_url = getRelativePath(current_file_path, term_path);
if (hoverText === undefined) {
var new_text = ('<Term reference="' + new_final_url + '">' +
text + '</Term>');
} else {
var new_text = ('<Term popup="' + hoverText + '" reference="' +
new_final_url + '">' + text + '</Term>');
}
glossaryContent = glossaryContent.replace(regex_match, new_text);
}
}
}
arr.push({
title: metadata.title,
hoverText: metadata.hoverText,
glossaryText: glossaryContent,
filepath: filepath.slice(1,-3),
});
}
......@@ -141,7 +176,7 @@ function generateGlossary(data) {
if (item.hoverText === undefined) {
content = content + `\n\n- **[${item.title}](${item.filepath})**\n`;
} else {
content = content + `\n\n- **[${item.title}](${item.filepath})**: ${item.hoverText}\n`;
content = content + `\n\n- **[${item.title}](${item.filepath})**: ${item.glossaryText}\n`;
}
}
})
......@@ -149,7 +184,9 @@ function generateGlossary(data) {
if (err) throw err;
var indexOfSecond = glossaryContent.indexOf(searchTerm, 1);
newContent = glossaryContent.slice(0, indexOfSecond + 3);
newContent = newContent + content;
var autoIncludeStatements = getAutoIncludeStatements(glossaryPath);
newContent = newContent + autoIncludeStatements + content;
// Write the list of terms to the glossary page
fs.writeFile(glossaryPath, newContent, 'utf8', function (err) {
if (err) return console.log(err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment