-
Notifications
You must be signed in to change notification settings - Fork 1
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
Update development/v0.1.4 branch with diagram creation using textual representation #336
Conversation
7438740
to
02d4c17
Compare
I will do a manual merging with |
This pull-request is closed. Do not delete the branch yet. |
Manual merging is not necessary, using iframe for rendering does not change any behaviour. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Added 2 suggestions for this pull-request. You may review the suggestion and merge the pr.
export default function setup(md, options) { | ||
const defaultRender = md.renderer.rules.fence; | ||
|
||
/* eslint no-undef: 0 */ | ||
md.renderer.rules.fence = (tokens, idx, opts, env, self) => { | ||
const token = tokens[idx]; | ||
token.content = filter(token.content); | ||
if (token.info === 'sequence') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like switch case could be beneficial here to remove the need of repeating <pre class="sequence">${token.content}</pre>
;
You can consider doing this:
switch (token.info) {
case 'sequence':
case 'flow':
case 'mermaid':
case 'graphviz': // fallthrought
return `<pre class="${token.info}">${token.content}</pre>`;
default: {
// pass token to default renderer.
return defaultRender(tokens, idx, opts, env, self);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! You gave me another idea! I store the accepted diagrams library in an array and do this:
if (diagramsLib.includes(token.info)) {
return `<pre class="${token.info}">${token.content}</pre>`;
}
const diagram = Diagram.parse(content); | ||
seqDiagrams[i].innerHTML = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using innerHTML
may not be a good practice here.
In the future, you may consider manipulating the DOM using api like "appendChild", "removeChild" etc.
See:
- http://stackoverflow.com/questions/3955229/remove-all-child-elements-of-a-dom-node-in-javascript
- http://stackoverflow.com/questions/7476638/if-people-recommend-i-shouldnt-use-innerhtml-what-then-should-i-instead-use
In this case, you may consider using a for loop to remove all the children inside seqDiagrams[i]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes yes. I have read about this before! Will go change it! :)
No description provided.