Added support for UML charts

This commit is contained in:
benweet 2014-04-25 00:43:57 +01:00
parent 274c9457b9
commit fd901e07ba
5 changed files with 94 additions and 9 deletions

View File

@ -27,6 +27,12 @@
"rangy": "~1.2.3", "rangy": "~1.2.3",
"google-diff-match-patch-js": "~1.0.0", "google-diff-match-patch-js": "~1.0.0",
"jsondiffpatch": "https://github.com/benweet/jsondiffpatch.git#fb9dddf7cd076d8ec89d376c0e9de9223e9888f9", "jsondiffpatch": "https://github.com/benweet/jsondiffpatch.git#fb9dddf7cd076d8ec89d376c0e9de9223e9888f9",
"hammerjs": "~1.0.10" "hammerjs": "~1.0.10",
"raphael": "~2.1.2",
"js-sequence-diagrams": "https://github.com/bramp/js-sequence-diagrams.git#1.0.4",
"flowchart": "https://github.com/adrai/flowchart.js.git#~1.2.10"
},
"resolutions": {
"js-sequence-diagrams": "1.0.3"
} }
} }

View File

@ -3,12 +3,16 @@ define([
"jquery", "jquery",
"underscore", "underscore",
"utils", "utils",
"logger",
"classes/Extension", "classes/Extension",
"text!html/markdownExtraSettingsBlock.html", "text!html/markdownExtraSettingsBlock.html",
'google-code-prettify', 'google-code-prettify',
'highlightjs', 'highlightjs',
'crel',
'sequence-diagram',
'flow-chart',
'pagedown-extra', 'pagedown-extra',
], function($, _, utils, Extension, markdownExtraSettingsBlockHTML, prettify, hljs) { ], function($, _, utils, logger, Extension, markdownExtraSettingsBlockHTML, prettify, hljs, crel, sequenceDiagram, flowChart) {
var markdownExtra = new Extension("markdownExtra", "Markdown Extra", true); var markdownExtra = new Extension("markdownExtra", "Markdown Extra", true);
markdownExtra.settingsBlock = markdownExtraSettingsBlockHTML; markdownExtra.settingsBlock = markdownExtraSettingsBlockHTML;
@ -67,6 +71,11 @@ define([
eventMgr = eventMgrParameter; eventMgr = eventMgrParameter;
}; };
var previewContentsElt;
markdownExtra.onReady = function() {
previewContentsElt = document.getElementById('preview-contents');
};
markdownExtra.onPagedownConfigure = function(editor) { markdownExtra.onPagedownConfigure = function(editor) {
var converter = editor.getConverter(); var converter = editor.getConverter();
if(markdownExtra.config.intraword === true) { if(markdownExtra.config.intraword === true) {
@ -86,14 +95,49 @@ define([
}); });
}); });
} }
var extraOptions = { var extraOptions = {
extensions: markdownExtra.config.extensions extensions: markdownExtra.config.extensions
}; };
function doSequenceDiagrams() {
_.each(previewContentsElt.querySelectorAll('.prettyprint > .language-sequence'), function(elt) {
try {
var diagram = sequenceDiagram.parse(elt.textContent);
var preElt = elt.parentNode;
var containerElt = crel('div', {
class: 'sequence-diagram'
});
preElt.parentNode.replaceChild(containerElt, preElt);
diagram.drawSVG(containerElt, {
theme: 'simple'
});
}
catch(e) {
console.error(e);
}
});
_.each(previewContentsElt.querySelectorAll('.prettyprint > .language-flow'), function(elt) {
try {
var chart = flowChart.parse(elt.textContent);
var preElt = elt.parentNode;
var containerElt = crel('div', {
class: 'flow-chart'
});
preElt.parentNode.replaceChild(containerElt, preElt);
chart.drawSVG(containerElt, {
'line-width': 2
});
}
catch(e) {
console.error(e);
}
});
}
if(markdownExtra.config.highlighter == "highlight") { if(markdownExtra.config.highlighter == "highlight") {
extraOptions.highlighter = "prettify"; extraOptions.highlighter = "prettify";
var previewContentsElt = document.getElementById('preview-contents');
editor.hooks.chain("onPreviewRefresh", function() { editor.hooks.chain("onPreviewRefresh", function() {
doSequenceDiagrams();
_.each(previewContentsElt.querySelectorAll('.prettyprint > code'), function(elt) { _.each(previewContentsElt.querySelectorAll('.prettyprint > code'), function(elt) {
!elt.highlighted && hljs.highlightBlock(elt); !elt.highlighted && hljs.highlightBlock(elt);
elt.highlighted = true; elt.highlighted = true;
@ -102,10 +146,13 @@ define([
} }
else if(markdownExtra.config.highlighter == "prettify") { else if(markdownExtra.config.highlighter == "prettify") {
extraOptions.highlighter = "prettify"; extraOptions.highlighter = "prettify";
editor.hooks.chain("onPreviewRefresh", prettify.prettyPrint); editor.hooks.chain("onPreviewRefresh", function() {
doSequenceDiagrams();
prettify.prettyPrint();
});
} }
Markdown.Extra.init(converter, extraOptions); Markdown.Extra.init(converter, extraOptions);
}; };
return markdownExtra; return markdownExtra;
}); });

View File

@ -16,7 +16,8 @@ Prism.languages.md = (function() {
md['pre gfm'] = { md['pre gfm'] = {
pattern: /^ {0,3}`{3}.*?\n(.*?\n)*? {0,3}`{3} *$/gm, pattern: /^ {0,3}`{3}.*?\n(.*?\n)*? {0,3}`{3} *$/gm,
inside: { inside: {
"md md-pre": /`{3}/ "md md-pre": /`{3}/,
lf: /\n/gm,
} }
}; };
md['h1 alt'] = { md['h1 alt'] = {

View File

@ -60,7 +60,11 @@ requirejs.config({
diff_match_patch: 'bower-libs/google-diff-match-patch-js/diff_match_patch', diff_match_patch: 'bower-libs/google-diff-match-patch-js/diff_match_patch',
diff_match_patch_uncompressed: 'bower-libs/google-diff-match-patch-js/diff_match_patch_uncompressed', diff_match_patch_uncompressed: 'bower-libs/google-diff-match-patch-js/diff_match_patch_uncompressed',
jsondiffpatch: 'bower-libs/jsondiffpatch/build/bundle', jsondiffpatch: 'bower-libs/jsondiffpatch/build/bundle',
hammerjs: 'bower-libs/hammerjs/hammer' hammerjs: 'bower-libs/hammerjs/hammer',
'sequence-diagram': 'bower-libs/js-sequence-diagrams/build/sequence-diagram-min',
raphael: 'bower-libs/raphael/raphael',
'flow-chart': 'bower-libs/flowchart/release/flowchart.amd-1.2.10.min',
flowchart: 'bower-libs/flowchart/release/flowchart-1.2.10.min'
}, },
shim: { shim: {
underscore: { underscore: {
@ -144,7 +148,17 @@ requirejs.config({
], ],
'pagedown-extra': [ 'pagedown-extra': [
'libs/Markdown.Converter' 'libs/Markdown.Converter'
] ],
'sequence-diagram': {
deps: [
'underscore',
'raphael'
],
exports: 'Diagram'
},
'flow-chart': [
'raphael'
],
} }
}); });

View File

@ -130,6 +130,23 @@ hr {
margin: 2em 0; margin: 2em 0;
} }
.sequence-diagram, .flow-chart {
text-align: center;
text {
font-size: 1em !important;
font-family: @font-family-sans-serif !important;
}
[fill="#ffffff"] {
fill: none;
}
[stroke="#000000"] {
stroke: @text-color;
}
[fill="#000"], [fill="#000000"], [fill="black"] {
fill: @text-color;
}
}
code, pre { code, pre {
font-family: @font-family-monospace; font-family: @font-family-monospace;
font-size: 0.9em; font-size: 0.9em;