Skip to content

Commit

Permalink
Feature: Mermaid and other markdown extras
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Aug 31, 2024
1 parent f81814a commit 98c4902
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- screenshot

## later
# cache assets
- mermaid styles
- cache assets
11 changes: 11 additions & 0 deletions examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ class Main(easycli.Root):

self._parser.print_help()
```


## Mermaid

```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
7 changes: 7 additions & 0 deletions yhttp/markdown/markdown.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import markdown2


# https://github.com/trentm/python-markdown2/wiki/Extras
extras = [
'header-ids',
'tables',
'fenced-code-blocks',
'cuddled-lists',
'footnotes',
'nofollow',
'pyshell',
'smarty-pants',
'mermaid',
]


Expand Down
17 changes: 17 additions & 0 deletions yhttp/markdown/templates/master.mako
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,22 @@


<script type="text/javascript" src="/static/index.js"></script>
<script type="module" defer>
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.esm.min.mjs';
mermaid. Initialize({
securityLevel: 'loose',
startOnLoad: true
});
let observer = new MutationObserver(mutations => {
for(let mutation of mutations) {
mutation.target.style.visibility = "visible";
}
});
document.querySelectorAll("pre.mermaid-pre div.mermaid").forEach(item => {
observer.observe(item, {
attributes: true,
attributeFilter: ['data-processed'] });
});
</script>
</body>
</html>

0 comments on commit 98c4902

Please sign in to comment.