Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(site) internal page anchors and referencing mechanism automation #1820

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(docs): Fix variables usage, rename method
<body>
This commit put in order code according project code style guide
  • Loading branch information
HenadzV committed Aug 4, 2023
commit ff1b2bc32dfb4b0d8734fb70103452e6a58f971d
12 changes: 6 additions & 6 deletions pages/11ty/markdown.shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class MDRenderer {
static generateHeadersIds(content) {
const headers = [...content.querySelectorAll('h1, h2, h3, h4')];
const localTerms = new Map();
for (let header of headers) {
for (const header of headers) {
const text = header.textContent;
const id = MDRenderer.createIDFromText(text)
header.setAttribute('id', id);
let anchor = `#${id}`
const anchor = `#${id}`
localTerms.set(text, anchor);
}
return localTerms
Expand All @@ -97,10 +97,10 @@ class MDRenderer {
}

static findTextNodes(root) {
let all = [];
const all = [];
for (let node = root.firstChild; node; node = node.nextSibling) {
if (node.nodeType === 3) all.push(node);
else all = all.concat(MDRenderer.findTextNodes(node));
else all.push(...MDRenderer.findTextNodes(node));
}
return all
}
Expand All @@ -113,13 +113,13 @@ class MDRenderer {

for (const node of nodes) {
if (node.textContent.includes(text)) {
MDRenderer.replaceTextNode(document, node, text, link)
MDRenderer.wrapTextNode(document, node, text, link)
}
}
}
}

static replaceTextNode(document, node, text, link) {
static wrapTextNode(document, node, text, link) {
const wrapper = document.createElement('span');
const regex = new RegExp(`(^|\\s)${text}(,?\\s|\\.?\\s)`, 'g');
wrapper.innerHTML = node.textContent.replace(regex, `$1<a href="${link}">${text}</a>$2`);
Expand Down