diff options
author | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2018-03-12 21:44:54 +0800 |
---|---|---|
committer | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2018-03-12 21:44:54 +0800 |
commit | 5bcf92d8fe6e0b3f350a5122df92ac51c4dbe18d (patch) | |
tree | abec48081bc766df5a2b11a32bea2035a177f2d9 /src/js | |
parent | 7043881ae2a712487c0557926d75384a9d35b6ac (diff) |
feat: generate sequence diagrams from code blocks (#35)
Close #35
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/even.js | 19 | ||||
-rw-r--r-- | src/js/main.js | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/js/even.js b/src/js/even.js index ca83a93..6b544a4 100644 --- a/src/js/even.js +++ b/src/js/even.js @@ -224,4 +224,23 @@ Even.flowchart = function () { } } +Even.sequence = function () { + if (!window.Diagram) return + + const blocks = document.querySelectorAll('pre code.language-sequence') + for (let i = 0; i < blocks.length; i++) { + const block = blocks[i] + const rootElement = block.parentElement + + const container = document.createElement('div') + const id = `js-sequence-diagrams-${i}` + container.id = id + container.className = 'align-center' + rootElement.parentElement.replaceChild(container, rootElement) + + const diagram = Diagram.parse(block.childNodes[0].nodeValue) + diagram.drawSVG(id, window.sequenceDiagramsOptions ? window.sequenceDiagramsOptions : {theme: 'simple'}) + } +} + export {Even} diff --git a/src/js/main.js b/src/js/main.js index bae31d9..289b8dc 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -10,6 +10,7 @@ $(document).ready(function () { }) Even.flowchart() +Even.sequence() hljs.initHighlighting() Even.highlight() |