├── .editorconfig ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── index.js ├── lib └── renderer.js ├── package.json └── snapshot.svg /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | # Set default charset 14 | [*.js] 15 | indent_style = space 16 | indent_size = 2 17 | 18 | [*.md] 19 | trim_trailing_whitespace = false 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .DS_Store 3 | node_modules 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .DS_Store 3 | .editorconfig 4 | .npmignore 5 | .gitignore 6 | .jshintrc 7 | npm-debug.log 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 W.Y. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hexo-filter-sequence 2 | 3 | [![MIT License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat-square)](https://github.com/bubkoo/hexo-filter-sequence/blob/master/LICENSE) 4 | 5 | [![npm:](https://img.shields.io/npm/v/hexo-filter-sequence.svg?style=flat-square)](https://www.npmjs.com/packages/hexo-filter-sequence) 6 | [![Package Quality](http://npm.packagequality.com/shield/hexo-filter-sequence.svg)](http://packagequality.com/#?package=hexo-filter-sequence) 7 | 8 | > Generate UML sequence diagrams for Hexo. 9 | 10 | ## Install 11 | 12 | ``` 13 | npm install --save hexo-filter-sequence 14 | ``` 15 | 16 | ## Usage 17 | 18 | This plugin is based on [js-sequence-diagrams](https://github.com/bramp/js-sequence-diagrams), so you can defined the chart as follow: 19 | 20 | ```sequence 21 | Alice->Bob: Hello Bob, how are you? 22 | Note right of Bob: Bob thinks 23 | Bob-->Alice: I am good thanks! 24 | ``` 25 | 26 | ![snapshot.svg](https://cdn.rawgit.com/bubkoo/hexo-filter-sequence/master/snapshot.svg) 27 | 28 | ## Config 29 | 30 | In your site's `_config.yml`: 31 | 32 | ```yaml 33 | sequence: 34 | # webfont: # optional, the source url of webfontloader.js 35 | # snap: # optional, the source url of snap.svg.js 36 | # underscore: # optional, the source url of underscore.js 37 | # sequence: # optional, the source url of sequence-diagram.js 38 | # css: # optional, the url for css, such as hand drawn theme 39 | options: 40 | theme: 41 | css_class: 42 | ``` 43 | 44 | Your config will be merged into default config: 45 | 46 | ```json 47 | { 48 | "webfont": "https://cdnjs.cloudflare.com/ajax/libs/webfont/1.6.27/webfontloader.js", 49 | "snap": "https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg-min.js", 50 | "underscore": "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js", 51 | "sequence": "https://cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js", 52 | "style": "", 53 | "options": { 54 | "theme": "simple", 55 | "css_class": "" 56 | } 57 | } 58 | ``` 59 | 60 | ## Related 61 | 62 | - [hexo-toc](https://github.com/bubkoo/hexo-toc) Insert a markdown TOC before posts be rendered. 63 | - [hexo-filter-fenced-code](https://github.com/bubkoo/hexo-filter-fenced-code) Extend syntax for the native fenced code block. 64 | - [hexo-filter-flowchart](https://github.com/bubkoo/hexo-filter-flowchart) Generate flowchart diagrams for Hexo. 65 | - [hexo-filter-sub](https://github.com/bubkoo/hexo-filter-sub) Generate subscript (``) tag for Hexo. 66 | - [hexo-filter-sup](https://github.com/bubkoo/hexo-filter-sup) Generate superscript (``) tag for Hexo. 67 | - [hexo-theme-formula](https://github.com/bubkoo/hexo-theme-formula) Hexo theme base on jade and less. 68 | 69 | ## Contributing 70 | 71 | Pull requests and stars are highly welcome. 72 | 73 | For bugs and feature requests, please [create an issue](https://github.com/bubkoo/hexo-filter-sequence/issues/new). 74 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var assign = require('deep-assign'); 2 | var renderer = require('./lib/renderer'); 3 | 4 | hexo.config.flowchart = assign({ 5 | webfont: 'https://cdnjs.cloudflare.com/ajax/libs/webfont/1.6.27/webfontloader.js', 6 | snap: 'https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.4.1/snap.svg-min.js', 7 | underscore: 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js', 8 | sequence: 'https://cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js', 9 | css: '', 10 | options: { 11 | theme: 'simple' 12 | } 13 | }, hexo.config.flowchart); 14 | 15 | hexo.extend.filter.register('before_post_render', renderer.render, 9); 16 | 17 | -------------------------------------------------------------------------------- /lib/renderer.js: -------------------------------------------------------------------------------- 1 | var reg = /(\s*)(```) *(sequence) *\n?([\s\S]+?)\s*(\2)(\n+|$)/g; 2 | 3 | function ignore(data) { 4 | var source = data.source; 5 | var ext = source.substring(source.lastIndexOf('.')).toLowerCase(); 6 | return ['.js', '.css', '.html', '.htm'].indexOf(ext) > -1; 7 | } 8 | 9 | function getId(index) { 10 | return 'sequence-' + index; 11 | } 12 | 13 | exports.render = function (data) { 14 | if (!ignore(data)) { 15 | 16 | var sequences = []; 17 | 18 | data.content = data.content 19 | .replace(reg, function (raw, start, startQuote, lang, content, endQuote, end) { 20 | var seqId = getId(sequences.length); 21 | sequences.push(content); 22 | return start + '
' + end; 23 | }); 24 | 25 | if (sequences.length) { 26 | var config = this.config.flowchart; 27 | // resources 28 | data.content += ''; 29 | data.content += ''; 30 | data.content += ''; 31 | data.content += ''; 32 | if (config.css) { 33 | data.content += '' 34 | } 35 | // exec 36 | data.content += sequences.map(function (code, index) { 37 | var seqId = getId(index); 38 | var codeId = seqId + '-code'; 39 | var optionsId = seqId + '-options'; 40 | return '' + 41 | '{% raw %}' + 42 | '' + 43 | '' + 44 | '' + 50 | '{% endraw %}'; 51 | }).join(''); 52 | } 53 | } 54 | }; 55 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-filter-sequence", 3 | "version": "1.0.3", 4 | "description": "Generate UML sequence diagrams for Hexo.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/bubkoo/hexo-filter-sequence.git" 12 | }, 13 | "keywords": [ 14 | "hexo", 15 | "filter", 16 | "sequence", 17 | "diagrams", 18 | "markdown" 19 | ], 20 | "author": { 21 | "name": "bubkoo.wy", 22 | "email": "bubkoo.wy@gmail.com" 23 | }, 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/bubkoo/hexo-filter-sequence/issues" 27 | }, 28 | "homepage": "https://github.com/bubkoo/hexo-filter-sequence#readme", 29 | "dependencies": { 30 | "deep-assign": "^2.0.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /snapshot.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | # Example of a comment. 8 | Alice->Bob: Hello Bob, how are you? 9 | Note right of Bob: Bob thinks 10 | Bob-->Alice: I am good thanks! 11 | 12 | 13 | 14 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 29 | Alice 30 | 31 | 32 | 33 | 35 | 37 | Alice 38 | 39 | 40 | 42 | 43 | 45 | 47 | Bob 48 | 49 | 50 | 51 | 53 | 55 | Bob 56 | 57 | 58 | 60 | 61 | 63 | Hello Bob, how are you? 64 | 65 | 68 | 69 | 70 | 72 | 74 | Bob thinks 75 | 76 | 77 | 78 | 80 | I am good thanks! 81 | 82 | 85 | 86 | 87 | --------------------------------------------------------------------------------