├── .gitignore ├── LICENSE ├── README.md ├── dockerfile ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .vscode 3 | .DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Fried rice 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 | # Markdown-server 2 | 3 | Markdown-server 提供了Markdown的数学公式 `LaTex`,以及流程图`yUML`服务端渲染支持。 4 | 5 | ## 如何使用 6 | 7 | - clone 本项目 8 | - `git clone https://github.com/sbfkcel/markdown-server` 9 | - 安装依赖 10 | - `npm install` 或 `yarn` 11 | - 启动服务 12 | - `node index.js` 13 | 14 | ## 查看服务 15 | 16 | 可以通过以下示例用来查看服务是否正常。 17 | 18 | - [(本地)LaTeX 数学公式](http://localhost:8001/?tex=x%20%3D%20%7B-b%20%5Cpm%20%5Csqrt%7Bb%5E2-4ac%7D%20%5Cover%202a%7D.) 19 | - [(本地)yUML 流程图](http://localhost:8001/?yuml=%2F%2F%20%7Btype%3Aactivity%7D%0A%2F%2F%20%7Bgenerate%3Atrue%7D%0A%0A(start)-%3E%3Ca%3E%5Bkettle%20empty%5D-%3E(Fill%20Kettle)-%3E%7Cb%7C%0A%3Ca%3E%5Bkettle%20full%5D-%3E%7Cb%7C-%3E(Boil%20Kettle)-%3E%7Cc%7C%0A%7Cb%7C-%3E(Add%20Tea%20Bag)-%3E(Add%20Milk)-%3E%7Cc%7C-%3E(Pour%20Water)%0A(Pour%20Water)-%3E(end)) 20 | 21 | --- 22 | 23 | - [(在线)LaTeX 数学公式](http://towxml.vvadd.com/?tex=x%20%3D%20%7B-b%20%5Cpm%20%5Csqrt%7Bb%5E2-4ac%7D%20%5Cover%202a%7D.) 24 | - [(在线)yUML 流程图](http://towxml.vvadd.com/?yuml=%2F%2F%20%7Btype%3Aactivity%7D%0A%2F%2F%20%7Bgenerate%3Atrue%7D%0A%0A(start)-%3E%3Ca%3E%5Bkettle%20empty%5D-%3E(Fill%20Kettle)-%3E%7Cb%7C%0A%3Ca%3E%5Bkettle%20full%5D-%3E%7Cb%7C-%3E(Boil%20Kettle)-%3E%7Cc%7C%0A%7Cb%7C-%3E(Add%20Tea%20Bag)-%3E(Add%20Milk)-%3E%7Cc%7C-%3E(Pour%20Water)%0A(Pour%20Water)-%3E(end)) 25 | 26 | ## 修改服务端口 27 | 28 | 编辑 `index.js` 最后一行的端口号即可。 29 | -------------------------------------------------------------------------------- /dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8 2 | 3 | WORKDIR /usr/src/app 4 | 5 | ADD https://github.com/sbfkcel/markdown-server/archive/refs/heads/master.zip /usr/src/app/ 6 | 7 | RUN unzip master.zip 8 | 9 | WORKDIR /usr/src/app/markdown-server-master 10 | 11 | RUN npm install 12 | 13 | EXPOSE 8001 14 | 15 | CMD [ "node", "index.js" ] 16 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const http = require("http"), 2 | url = require('url'), 3 | qs = require('querystring'), 4 | mathjax = require("mathjax-node"), 5 | yuml2svg = require('yuml2svg'); 6 | 7 | mathjax.start(); 8 | 9 | const app = http.createServer((req,res)=>{ 10 | let queryObj = qs.parse(url.parse(req.url).query), 11 | tex = queryObj.tex, 12 | yuml = queryObj.yuml, 13 | theme = queryObj.theme, 14 | errFn = (msg)=>{ 15 | res.writeHead(404,{'Content-type':'text/html;charset=utf-8'}); 16 | res.write(msg); 17 | res.end(); 18 | }, 19 | successFn = (result)=>{ 20 | res.writeHead(200,{'Content-type':'image/svg+xml;charset=utf-8'}); 21 | res.write(result); 22 | res.end(); 23 | }; 24 | 25 | if(yuml){ 26 | yuml2svg(yuml,{isDark:theme === 'dark'}).then(v => { 27 | successFn(v); 28 | }).catch(e => { 29 | errFn('Yuml formula is wrong!'); 30 | }); 31 | }else if(tex){ 32 | mathjax.typeset({ 33 | math:tex, 34 | format:'TeX', 35 | svg:true 36 | },data => { 37 | if(theme === 'dark'){ 38 | data.svg = data.svg.replace(/fill="currentColor"/g,'fill="#ffffff"'); 39 | }; 40 | successFn(data.svg); 41 | }) 42 | }else{ 43 | // 请通过`tex`参数传入LaTeX公式,或使用`yuml`参数传入`yuml`表达式。 44 | errFn('Please pass LaTeX formula via `tex` parameter or `Yuml` expression using `yuml` parameter.'); 45 | }; 46 | }); 47 | app.listen(8001); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-server", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "dependencies": { 10 | "mathjax-node": "^2.1.1", 11 | "yuml2svg": "^4.2.2" 12 | } 13 | } 14 | --------------------------------------------------------------------------------