Skip to content

Commit

Permalink
feat(docs): Add function to generate links for globally defined terms
Browse files Browse the repository at this point in the history
<body>
This commit adds the `generateGloballyDefinedTermsLinks` function to the MDRenderer class. This function generates  links for globally defined terms
  • Loading branch information
HenadzV committed Jul 25, 2023
1 parent bfe42bc commit c8bb7d9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pages/11ty/markdown.shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class MDRenderer {
//Add headers ids
MDRenderer.generateHeadersIds(window.document.body);

// Add globally defined terms links
MDRenderer.generateGloballyDefinedTermsLinks(window.document.body);

// Resolve content links
MDRenderer.resolveLinks(window.document.body, filePath);

Expand Down Expand Up @@ -97,6 +100,18 @@ class MDRenderer {
return content;
}

static generateGloballyDefinedTermsLinks (content) {
const globallyDefinedTerms = {
ESL_Base_Element: 'https://esl-ui.com/core/esl-base-element/',
ESL_Mixin_Element: 'https://esl-ui.com/core/esl-mixin-element/'
// Add other globally defined terms as needed
};

Object.keys(globallyDefinedTerms).forEach(term => {
this.generateAnchors(content, term.replace(/_/g, " "), globallyDefinedTerms[term]);
});
}

static generateAnchors(content, text, link) {
const matches = Array.from(content.querySelectorAll('*'))
.filter(element => element.textContent.includes(text) || element.textContent.includes(text.replace(/_/g, " ")));
Expand Down

0 comments on commit c8bb7d9

Please sign in to comment.