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

Add nomnoml rendering feature #820

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Add nomnoml rendering feature
Makes StackEdit capable of rendering nomnoml code within fences, much like
the other uml features.
  • Loading branch information
korroz committed Jun 9, 2015
commit 935c73f9020e89dd3c2633307cd0fa6253603389
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"flowchart": "https://github.com/adrai/flowchart.js.git#751717d3db6437def9a5f8b1cb73e8bb81b5833a",
"monetizejs": "~0.2.0",
"MathJax": "~2.5.0",
"alertify.js": "https://github.com/fabien-d/alertify.js.git#fc2e06fa39873363dda199204b8544119ab060bf"
"alertify.js": "https://github.com/fabien-d/alertify.js.git#fc2e06fa39873363dda199204b8544119ab060bf",
"nomnoml": "skanaar/nomnoml#d62ec1ddcb8fa3226c9147c4132fd42f9ef8de5b"
},
"main": [
"/public/res/main.js",
Expand Down
23 changes: 21 additions & 2 deletions public/res/extensions/umlDiagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ define([
"text!html/umlDiagramsSettingsBlock.html",
'crel',
'Diagram',
'flow-chart'
], function($, _, utils, logger, Extension, umlDiagramsSettingsBlockHTML, crel, Diagram, flowChart) {
'flow-chart',
'nomnoml'
], function($, _, utils, logger, Extension, umlDiagramsSettingsBlockHTML, crel, Diagram, flowChart, nomnoml) {

var umlDiagrams = new Extension("umlDiagrams", "UML Diagrams", true);
umlDiagrams.settingsBlock = umlDiagramsSettingsBlockHTML;
Expand Down Expand Up @@ -61,6 +62,24 @@ define([
catch(e) {
}
});
_.each(previewContentsElt.querySelectorAll('.prettyprint > .language-nomnoml'), function(elt) {
try {
var themeFills = '#fill: #eee; #f8f8f8\n'; // TODO: Create this from theme palette instead.
var preElt = elt.parentNode;
var canvasElt = crel('canvas');
nomnoml.draw(canvasElt, themeFills + elt.textContent);
var pElt = crel('p', // Wrap <img> in a <p> to mimic markdown image rendering.
crel('img', {
src: canvasElt.toDataURL('image/png'),
alt: 'nomnoml diagram',
title: 'nomnoml diagram' // TODO: Use value from #title directive instead.
})
);
preElt.parentNode.replaceChild(pElt, preElt);
}
catch(e) {
}
});
});
};

Expand Down
11 changes: 11 additions & 0 deletions public/res/html/umlDiagramsSettingsBlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
cond(no)->op
```</code>
</pre>

<p>nomnoml diagrams:</p>
<pre><div class="help-block pull-right"><a target="_blank" href="http:https://www.nomnoml.com/">More info</a></div><code>```nomnoml
[&lt;abstract&gt;Component|| operation()]
[Client] depends --&gt; [Component]
[Decorator|- next: Component]
[Decorator] decorates -- [ConcreteComponent]
[Component] &lt;:- [Decorator]
[Component] &lt;:- [ConcreteComponent]
```</code></pre>

<blockquote>
<p><b>Note:</b> Markdown Extra extension has to be enabled with GFM fenced code blocks option.</p>
</blockquote>
4 changes: 3 additions & 1 deletion public/res/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ requirejs.config({
paths: {
jquery: 'bower-libs/jquery/jquery',
underscore: 'bower-libs/underscore/underscore',
lodash: 'bower-libs/lodash/lodash',
crel: 'bower-libs/crel/crel',
jgrowl: 'bower-libs/jgrowl/jquery.jgrowl',
mousetrap: 'bower-libs/mousetrap/mousetrap',
Expand Down Expand Up @@ -71,7 +72,8 @@ requirejs.config({
'to-markdown': 'bower-libs/to-markdown/src/to-markdown',
waitForImages: 'bower-libs/waitForImages/dist/jquery.waitforimages',
MathJax: 'bower-libs/MathJax/MathJax',
alertify: 'bower-libs/alertify.js/lib/alertify'
alertify: 'bower-libs/alertify.js/lib/alertify',
nomnoml: 'bower-libs/nomnoml/dist/nomnoml'
},
shim: {
underscore: {
Expand Down