{"id":23378075,"url":"https://github.com/powerdos/markdowntohtml","last_synced_at":"2025-04-10T19:52:35.440Z","repository":{"id":126316048,"uuid":"97465981","full_name":"PowerDos/MarkdownToHtml","owner":"PowerDos","description":"将Markdown文档转换为HTML显示","archived":false,"fork":false,"pushed_at":"2017-07-17T11:16:48.000Z","size":634,"stargazers_count":14,"open_issues_count":3,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T17:51:29.127Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PowerDos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-07-17T10:49:53.000Z","updated_at":"2024-05-21T07:31:38.000Z","dependencies_parsed_at":"2023-06-16T06:45:38.258Z","dependency_job_id":null,"html_url":"https://github.com/PowerDos/MarkdownToHtml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDos%2FMarkdownToHtml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDos%2FMarkdownToHtml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDos%2FMarkdownToHtml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDos%2FMarkdownToHtml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PowerDos","download_url":"https://codeload.github.com/PowerDos/MarkdownToHtml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248284105,"owners_count":21077996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-21T18:34:35.444Z","updated_at":"2025-04-10T19:52:35.416Z","avatar_url":"https://github.com/PowerDos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MarkdownToHtml\n\u003e 将Markdown文档转换为HTML显示\n\n## 说明\n\u003e 在程序的中，我结合了bootstrap的样式，所以稍微更改了下模块marked的源码，这也是为了显示更好。我的测试md文档放在了，public/doc下。这边用了一个代码高亮的插件：highlight.js，你也可以用一些别的。\u003cbr\u003e\u003cbr\u003e\n\u003e 本应用是采用 node.js + Express 搭建的\n\n# 准备工作\n## 安装marked\n\u003e npm install marked --save\n\n# 关键步骤\n## doc.js\n``` Javascript\nconst express = require('express');\nconst router = express.Router();\nconst fs = require('fs');\nconst marked = require('marked');\n\nrouter.get(\"/:docName\", function(req, res, next){\n    console.log('name:' + req.params.docName);\n    fs.readFile(__dirname+'/../public/doc/'+ req.params.docName +'.md', function(err, data){\n        if(err){\n            console.log(\"文件不存在！\");\n            res.send(\"文件不存在！\");\n        }else{\n            console.log(data);\n            htmlStr = marked(data.toString());\n            res.render('doc', {doc: htmlStr});\n        }\n    });\n});\n\nmodule.exports = router;\n```\n## doc.ejs\n``` HTML\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\"\u003e\n\t\u003clink rel=\"stylesheet\" href=\"https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u\" crossorigin=\"anonymous\"\u003e\n\t\u003clink rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css\"\u003e\n\t\u003cscript src=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003ehljs.initHighlightingOnLoad();\u003c/script\u003e\n    \u003clink rel=\"stylesheet\" href=\"/css/doc.css\"\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cnav class=\"navbar navbar-default navbar-fixed-top\"\u003e\n\t  \u003cdiv class=\"container\"\u003e\n\t    \u003cdiv class=\"navbar-header\"\u003e\n\t     \t\u003ca class=\"navbar-brand\" href=\"#\"\u003e Markdown\u003c/a\u003e\n\t    \u003c/div\u003e\n\t    \u003cbutton type=\"button\" class=\"btn btn-primary navbar-btn navbar-right\" id=\"download\"\u003e\u003cspan class=\"glyphicon glyphicon-download-alt\"\u003e\u003c/span\u003e Download\u003c/button\u003e\n\t  \u003c/div\u003e\n\t\u003c/nav\u003e\n\t\u003cdiv class=\"container\" id=\"doc-page\"\u003e\n\t\t\u003c%- doc %\u003e\n\t\u003c/div\u003e\n\t\u003cdiv class=\"footer\"\u003e\n\t\t\u003cspan\u003e© 2017 Gavin\u003c/span\u003e\n\t\u003c/div\u003e\n\u003c/body\u003e\n\u003c/script\u003e\n\u003c/html\u003e\n```\n\n## app.js\n\u003e 只给出路由部分\n\n``` JavaScript\nconst doc = require('./routes/doc');\napp.use('/doc', doc);\n```\n\n# Demo演示\n![](http://i.imgur.com/ODAYGbi.png)\u003cbr\u003e\n![](http://i.imgur.com/g0CeOaR.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerdos%2Fmarkdowntohtml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowerdos%2Fmarkdowntohtml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerdos%2Fmarkdowntohtml/lists"}