Skip to content

Commit

Permalink
feat: add plantuml language for uml plugin (close #87) (#146)
Browse files Browse the repository at this point in the history
* feat: add plantuml language for uml plugin

* refactor: apply code review (#146)
  • Loading branch information
kyuwoo-choi authored and seonim-ryu committed Jan 2, 2020
1 parent 69e3fba commit 50e1dd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
14 changes: 8 additions & 6 deletions apps/core/src/js/extensions/uml.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Editor from './editorProxy';

const {codeBlockManager} = Editor;
const DEFAULT_RENDERER_URL = 'http://www.plantuml.com/plantuml/png/';
const LANG = 'uml';
const UML_LANGUAGES = ['uml', 'plantuml'];

/**
* plant uml plugin
Expand Down Expand Up @@ -42,11 +42,13 @@ function umlExtension(editor, options = {}) {
return renderedHTML;
}

const optionLanguages = editor.options.codeBlockLanguages;
if (optionLanguages && optionLanguages.indexOf(LANG) < 0) {
optionLanguages.push(LANG);
}
codeBlockManager.setReplacer(LANG, plantUMLReplacer);
const {codeBlockLanguages} = editor.options;
UML_LANGUAGES.forEach(umlLanguage => {
if (codeBlockLanguages.indexOf(umlLanguage) < 0) {
codeBlockLanguages.push(umlLanguage);
}
codeBlockManager.setReplacer(umlLanguage, plantUMLReplacer);
});
}

Editor.defineExtension('uml', umlExtension);
Expand Down
20 changes: 19 additions & 1 deletion apps/core/test/extensions/uml.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('uml extension', () => {
});

it('create plant uml image in markdown preview', () => {
const lang = 'uml';
editor = new TuiEditor({
el: wrapper,
previewStyle: 'vertical',
Expand All @@ -33,7 +34,24 @@ describe('uml extension', () => {
exts: ['uml']
});

editor.setValue(`\`\`\`uml\nAlice -> Bob: Hello\n\`\`\``);
editor.setValue(`\`\`\`${lang}\nAlice -> Bob: Hello\n\`\`\``);

jasmine.clock().tick(800);

expect(editor.preview.$el.get(0).querySelector('pre img').getAttribute('src')).toEqual('http://www.plantuml.com/plantuml/png/Syp9J4vLqBLJSCfFibBmICt9oUS20000');
});

it('create plant uml image for code block language plantuml', () => {
const lang = 'plantuml';
editor = new TuiEditor({
el: wrapper,
previewStyle: 'vertical',
height: '100px',
initialEditType: 'markdown',
exts: ['uml']
});

editor.setValue(`\`\`\`${lang}\nAlice -> Bob: Hello\n\`\`\``);

jasmine.clock().tick(800);

Expand Down

0 comments on commit 50e1dd5

Please sign in to comment.