12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- function fixMermaid(render = false) {
- let mermaids = [];
-
- [].push.apply(mermaids, document.getElementsByClassName('language-mermaid'));
- for (let i = 0; i < mermaids.length; i++) {
-
- let mermaidCodeElement = mermaids[i];
- let newElement = document.createElement('div');
- newElement.innerHTML = mermaidCodeElement.innerHTML;
- newElement.classList.add('mermaid');
- if (render) {
- window.mermaid.mermaidAPI.render(`mermaid-${i}`, newElement.textContent, function (svgCode) {
- newElement.innerHTML = svgCode;
- });
- }
- mermaidCodeElement.parentNode.replaceWith(newElement);
- }
- console.debug(`Processed ${mermaids.length} Mermaid code blocks`);
- }
- function scrollParentToChild(parent, child) {
-
- const parentRect = parent.getBoundingClientRect();
-
- const parentViewableArea = {
- height: parent.clientHeight,
- width: parent.clientWidth,
- };
-
- const childRect = child.getBoundingClientRect();
-
- const isChildInView =
- childRect.top >= parentRect.top && childRect.bottom <= parentRect.top + parentViewableArea.height;
-
- if (!isChildInView) {
-
- parent.scrollTop = childRect.top + parent.scrollTop - parentRect.top;
- }
- }
- export {fixMermaid, scrollParentToChild};
|