markdown-to-html by github/awesome-copilot
npx skills add https://github.com/github/awesome-copilot --skill markdown-to-html使用 marked.js 库将 Markdown 文档转换为 HTML 的专业技能,或编写数据转换脚本;在这种情况下,脚本类似于 markedJS/marked 仓库。对于自定义脚本,知识不仅限于 marked.js,还会利用来自 pandoc 和 gomarkdown/markdown 等工具的数据转换方法进行数据转换;利用 jekyll/jekyll 和 gohugoio/hugo 作为模板系统。
转换脚本或工具应能处理单个文件、批量转换和高级配置。
更多信息请参阅 basic-markdown-to-html.md
```markdown
# Level 1
## Level 2
One sentence with a [link](https://example.com), and a HTML snippet like `<p>paragraph tag</p>`.
- `ul` list item 1
- `ul` list item 2
1. `ol` list item 1
2. `ol` list item 1
| Table Item | Description |
| One | One is the spelling of the number `1`. |
| Two | Two is the spelling of the number `2`. |
```js
var one = 1;
var two = 2;
function simpleMath(x, y) {
return x + y;
}
console.log(simpleMath(one, two));
```
```
```html
<h1>Level 1</h1>
<h2>Level 2</h2>
<p>One sentence with a <a href="https://example.com">link</a>, and a HTML snippet like <code><p>paragraph tag</p></code>.</p>
<ul>
<li>`ul` list item 1</li>
<li>`ul` list item 2</li>
</ul>
<ol>
<li>`ol` list item 1</li>
<li>`ol` list item 2</li>
</ol>
<table>
<thead>
<tr>
<th>Table Item</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>One is the spelling of the number `1`.</td>
</tr>
<tr>
<td>Two</td>
<td>Two is the spelling of the number `2`.</td>
</tr>
</tbody>
</table>
<pre>
<code>var one = 1;
var two = 2;
function simpleMath(x, y) {
return x + y;
}
console.log(simpleMath(one, two));</code>
</pre>
```
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
更多信息请参阅 code-blocks-to-html.md
```markdown
your code here
```
```html
<pre><code class="language-md">
your code here
</code></pre>
```
```js
console.log("Hello world");
```
```html
<pre><code class="language-js">
console.log("Hello world");
</code></pre>
```
```markdown
```
```
visible backticks
```
```
```
```html
<pre><code>
```
visible backticks
```
</code></pre>
```
更多信息请参阅 collapsed-sections-to-html.md
```markdown
<details>
<summary>More info</summary>
### Header inside
- Lists
- **Formatting**
- Code blocks
```js
console.log("Hello");
```
</details>
```
```html
<details>
<summary>More info</summary>
<h3>Header inside</h3>
<ul>
<li>Lists</li>
<li><strong>Formatting</strong></li>
<li>Code blocks</li>
</ul>
<pre>
<code class="language-js">console.log("Hello");</code>
</pre>
</details>
```
```markdown
This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$
```
```html
<p>This sentence uses <code>$</code> delimiters to show math inline:
<math-renderer><math xmlns="http://www.w3.org/1998/Math/MathML">
<msqrt><mn>3</mn><mi>x</mi><mo>−</mo><mn>1</mn></msqrt>
<mo>+</mo><mo>(</mo><mn>1</mn><mo>+</mo><mi>x</mi>
<msup><mo>)</mo><mn>2</mn></msup>
</math>
</math-renderer>
</p>
```
```markdown
**The Cauchy-Schwarz Inequality**\
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```
```html
<p><strong>The Cauchy-Schwarz Inequality</strong><br>
<math-renderer>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow><mo>(</mo>
<munderover><mo data-mjx-texclass="OP">∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi>
</munderover>
<msub><mi>a</mi><mi>k</mi></msub>
<msub><mi>b</mi><mi>k</mi></msub>
<mo>)</mo>
</mrow>
<mn>2</mn>
</msup>
<mo>≤</mo>
<mrow><mo>(</mo>
<munderover><mo>∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow>
<mi>n</mi>
</munderover>
<msubsup><mi>a</mi><mi>k</mi><mn>2</mn></msubsup>
<mo>)</mo>
</mrow>
<mrow><mo>(</mo>
<munderover><mo>∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow>
<mi>n</mi>
</munderover>
<msubsup><mi>b</mi><mi>k</mi><mn>2</mn></msubsup>
<mo>)</mo>
</mrow>
</math>
</math-renderer></p>
```
更多信息请参阅 tables-to-html.md
```markdown
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
```
```html
<table>
<thead><tr><th>First Header</th><th>Second Header</th></tr></thead>
<tbody>
<tr><td>Content Cell</td><td>Content Cell</td></tr>
<tr><td>Content Cell</td><td>Content Cell</td></tr>
</tbody>
</table>
```
```markdown
| Left-aligned | Center-aligned | Right-aligned |
| :--- | :---: | ---: |
| git status | git status | git status |
| git diff | git diff | git diff |
```
```html
<table>
<thead>
<tr>
<th align="left">Left-aligned</th>
<th align="center">Center-aligned</th>
<th align="right">Right-aligned</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">git status</td>
<td align="center">git status</td>
<td align="right">git status</td>
</tr>
<tr>
<td align="left">git diff</td>
<td align="center">git diff</td>
<td align="right">git diff</td>
</tr>
</tbody>
</table>
```
npm install -g markednpm install marked请参阅 marked.md 快速转换方法
请参阅 marked.md 分步工作流程
创建 ~/.marked.json 用于持久化选项:
{
"gfm": true,
"breaks": true
}
或使用自定义配置:
marked -i input.md -o output.html -c config.json
| 选项 | 描述 |
|---|---|
-i, --input <file> | 输入 Markdown 文件 |
-o, --output <file> | 输出 HTML 文件 |
-s, --string <string> | 解析字符串而非文件 |
-c, --config <file> | 使用自定义配置文件 |
--gfm | 启用 GitHub 风味 Markdown |
--breaks | 将换行符转换为 <br> |
--help | 显示所有选项 |
⚠️ Marked 不会对输出的 HTML 进行消毒处理。 对于不受信任的输入,请使用消毒器:
import { marked } from 'marked';
import DOMPurify from 'dompurify';
const unsafeHtml = marked.parse(untrustedMarkdown);
const safeHtml = DOMPurify.sanitize(unsafeHtml);
推荐的消毒器:
| 风格 | 支持度 |
|---|---|
| 原始 Markdown | 100% |
| CommonMark 0.31 | 98% |
| GitHub 风味 Markdown | 97% |
| 问题 | 解决方案 |
|---|---|
| 文件开头的特殊字符 | 去除零宽度字符:content.replace(/^[\u200B\u200C\u200D\uFEFF]/,"") |
| 代码块未高亮显示 | 添加语法高亮器,如 highlight.js |
| 表格未渲染 | 确保设置了 gfm: true 选项 |
| 换行符被忽略 | 在选项中设置 breaks: true |
| XSS 漏洞担忧 | 使用 DOMPurify 对输出进行消毒 |
pandoc# 将 markdown 转换为 HTML
pandoc input.md -o output.html
# 转换为独立文档(包含页眉/页脚)
pandoc input.md -s -o output.html
# 显式指定格式
pandoc input.md -f markdown -t html -s -o output.html
# 启动 pandoc 作为过滤器
pandoc
# 输入 markdown,然后按 Ctrl-D(Linux/macOS)或 Ctrl-Z+Enter(Windows)
Hello *pandoc*!
# 输出:<p>Hello <em>pandoc</em>!</p>
# HTML 转 Markdown
pandoc -f html -t markdown input.html -o output.md
# Markdown 转 LaTeX
pandoc input.md -s -o output.tex
# Markdown 转 PDF(需要 LaTeX)
pandoc input.md -s -o output.pdf
# Markdown 转 Word
pandoc input.md -s -o output.docx
| 选项 | 描述 |
|---|---|
-f, --from <format> | 输入格式(markdown、html、latex 等) |
-t, --to <format> | 输出格式(html、latex、pdf、docx 等) |
-s, --standalone | 生成包含页眉/页脚的独立文档 |
-o, --output <file> | 输出文件(从扩展名推断) |
--mathml | 将 TeX 数学公式转换为 MathML |
--metadata title="Title" | 设置文档元数据 |
--toc | 包含目录 |
--template <file> | 使用自定义模板 |
--help | 显示所有选项 |
⚠️ Pandoc 会忠实地处理输入。 当转换不受信任的 markdown 时:
使用 --sandbox 模式以禁用外部文件访问
在处理前验证输入
如果在浏览器中显示,请对 HTML 输出进行消毒
pandoc --sandbox input.md -o output.html
| 风格 | 支持度 |
|---|---|
| Pandoc Markdown | 100%(原生) |
| CommonMark | 完全(使用 -f commonmark) |
| GitHub 风味 Markdown | 完全(使用 -f gfm) |
| MultiMarkdown | 部分 |
| 问题 | 解决方案 |
|---|---|
| PDF 生成失败 | 安装 LaTeX(MacTeX、MiKTeX 或 texlive) |
| Windows 上的编码问题 | 在使用 pandoc 前运行 chcp 65001 |
| 缺少独立文档的页眉 | 添加 -s 标志以生成完整文档 |
| 数学公式未渲染 | 使用 --mathml 或 --mathjax 选项 |
| 表格未渲染 | 确保使用正确的表格语法(包含管道符和短横线) |
go get github.com/gomarkdown/markdowngo install github.com/gomarkdown/mdtohtml@latestpackage main
import (
"fmt"
"github.com/gomarkdown/markdown"
)
func main() {
md := []byte("# Hello World\n\nThis is **bold** text.")
html := markdown.ToHTML(md, nil, nil)
fmt.Println(string(html))
}
# 安装 mdtohtml
go install github.com/gomarkdown/mdtohtml@latest
# 转换文件
mdtohtml input.md output.html
# 转换文件(输出到标准输出)
mdtohtml input.md
package main
import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)
func mdToHTML(md []byte) []byte {
// 创建带扩展的解析器
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(extensions)
doc := p.Parse(md)
// 创建带扩展的 HTML 渲染器
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
return markdown.Render(doc, renderer)
}
mdtohtml CLI 工具的选项很少:
mdtohtml input-file [output-file]
对于高级配置,请使用 Go 库以编程方式配合解析器和渲染器选项:
| 解析器扩展 | 描述 |
|---|---|
parser.CommonExtensions | 表格、围栏代码块、自动链接、删除线等 |
parser.AutoHeadingIDs | 为标题生成 ID |
parser.NoEmptyLineBeforeBlock | 块前无需空行 |
parser.MathJax | 对 LaTeX 数学公式的 MathJax 支持 |
| HTML 标志 | 描述 |
| --- | --- |
html.CommonFlags | 常见的 HTML 输出标志 |
html.HrefTargetBlank | 为链接添加 target="_blank" |
html.CompletePage | 生成完整的 HTML 页面 |
html.UseXHTML | 生成 XHTML 输出 |
⚠️ gomarkdown 不会对输出的 HTML 进行消毒处理。 对于不受信任的输入,请使用 Bluemonday:
import (
"github.com/microcosm-cc/bluemonday"
"github.com/gomarkdown/markdown"
)
maybeUnsafeHTML := markdown.ToHTML(md, nil, nil)
html := bluemonday.UGCPolicy().SanitizeBytes(maybeUnsafeHTML)
推荐的消毒器:Bluemonday
| 风格 | 支持度 |
|---|---|
| 原始 Markdown | 100% |
| CommonMark | 高(带扩展) |
| GitHub 风味 Markdown | 高(表格、围栏代码块、删除线) |
| MathJax/LaTeX 数学公式 | 通过扩展支持 |
| Mmark | 支持 |
| 问题 | 解决方案 |
|---|---|
| Windows/Mac 换行符未解析 | 使用 parser.NormalizeNewlines(input) |
| 表格未渲染 | 启用 parser.Tables 扩展 |
| 代码块未高亮显示 | 与语法高亮器(如 Chroma)集成 |
| 数学公式未渲染 | 启用 parser.MathJax 扩展 |
| XSS 漏洞 | 使用 Bluemonday 对输出进行消毒 |
jekyllgem install jekyll bundler# 创建新的 Jekyll 站点
jekyll new myblog
# 切换到站点目录
cd myblog
# 本地构建和提供服务
bundle exec jekyll serve
# 在 http://localhost:4000 访问
# 构建站点到 _site 目录
bundle exec jekyll build
# 在生产环境下构建
JEKYLL_ENV=production bundle exec jekyll build
# 使用实时重载提供服务
bundle exec jekyll serve --livereload
# 包含草稿提供服务
bundle exec jekyll serve --drafts
| 命令 | 描述 |
|---|---|
jekyll new <path> | 创建新的 Jekyll 站点 |
jekyll build | 构建站点到 _site 目录 |
jekyll serve | 本地构建和提供服务 |
jekyll clean | 移除生成的文件 |
jekyll doctor | 检查配置问题 |
| 服务选项 | 描述 |
| --- | --- |
--livereload | 更改时重新加载浏览器 |
--drafts | 包含草稿文章 |
--port <port> | 设置服务器端口(默认:4000) |
--host <host> | 设置服务器主机(默认:localhost) |
--baseurl <url> | 设置基础 URL |
⚠️ Jekyll 安全注意事项:
避免在生产环境中使用 safe: false
在 _config.yml 中使用 exclude 防止敏感文件被发布
如果接受外部输入,请对用户生成的内容进行消毒
保持 Jekyll 和插件更新
exclude:
| 风格 | 支持度 |
|---|---|
| Kramdown(默认) | 100% |
| CommonMark | 通过插件(jekyll-commonmark) |
| GitHub 风味 Markdown | 通过插件(jekyll-commonmark-ghpages) |
| RedCarpet | 通过插件(已弃用) |
在 _config.yml 中配置 markdown 处理器:
markdown: kramdown
kramdown:
input: GFM
syntax_highlighter: rouge
| 问题 | 解决方案 |
|---|---|
| Ruby 3.0+ 服务失败 | 运行 bundle add webrick |
| Gem 依赖错误 | 运行 bundle install |
| 构建缓慢 | 使用 --incremental 标志 |
| Liquid 语法错误 | 检查内容中未转义的 { |
| 插件未加载 | 添加到 _config.yml 的插件列表 |
hugo# 创建新的 Hugo 站点
hugo new site mysite
# 切换到站点目录
cd mysite
# 添加主题
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
echo "theme = 'ananke'" >> hugo.toml
# 创建内容
hugo new content posts/my-first-post.md
# 启动开发服务器
hugo server -D
# 构建站点到 public 目录
hugo
# 构建并压缩
hugo --minify
# 为特定环境构建
hugo --environment production
# 启动包含草稿的服务器
hugo server -D
# 启动实时重载并绑定到所有接口
hugo server --bind 0.0.0.0 --baseURL http://localhost:1313/
# 使用特定端口启动
hugo server --port 8080
| 命令 | 描述 |
|---|---|
hugo new site <name> | 创建新的 Hugo 站点 |
hugo new content <path> | 创建新的内容文件 |
hugo | 构建站点到 public 目录 |
hugo server | 启动开发服务器 |
hugo mod init | 初始化 Hugo 模块 |
| 构建选项 | 描述 |
| --- | --- |
-D, --buildDrafts | 包含草稿内容 |
-E, --buildExpired | 包含过期内容 |
-F, --buildFuture | 包含未来日期的内容 |
--minify | 压缩输出 |
--gc | 构建后运行垃圾回收 |
-d, --destination <path> | 输出目录 |
| 服务器选项 | 描述 |
| --- | --- |
--bind <ip> | 要绑定的接口 |
-p, --port <port> | 端口号(默认:1313) |
--liveReloadPort <port> | 实时重载端口 |
--disableLiveReload | 禁用实时重载 |
--navigateToChanged | 导航到更改的内容 |
⚠️ Hugo 安全注意事项:
在 hugo.toml 中为外部命令配置安全策略
在公共仓库中谨慎使用 --enableGitInfo
对用户生成的内容验证短代码参数
[security] enableInlineShortcodes = false [security.exec] allow = ['^go$', '^npx$', '^postcss$'] [security.funcs] getenv = ['^HUGO_', '^CI$'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*']
| 风格 | 支持度 |
|---|---|
| Goldmark(默认) | 100%(符合 CommonMark) |
| GitHub 风味 Markdown | 完全(表格、删除线、自动链接) |
| CommonMark | 100% |
| Blackfriday(旧版) | 已弃用,不推荐 |
在 hugo.toml 中配置 markdown:
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
definitionList = true
footnote = true
linkify = true
strikethrough = true
table = true
taskList = true
[markup.goldmark.renderer]
unsafe = false # 设置为 true 以允许原始 HTML
| 问题 | 解决方案 |
|---|---|
| 路径上显示“页面未找到” | 检查配置中的 baseURL |
| 主题未加载 | 验证 themes/ 中的主题或 Hugo 模块 |
| 构建缓慢 | 使用 --templateMetrics 识别瓶颈 |
| 原始 HTML 未渲染 | 在 goldmark 配置中设置 unsafe = true |
| 图片未加载 | 检查 static/ 文件夹结构 |
| 模块错误 | 运行 hugo mod tidy |
每周安装量
7.6K
仓库
GitHub 星标数
26.7K
首次出现
2026年2月2日
安全审计
安装于
codex7.5K
gemini-cli7.5K
opencode7.5K
github-copilot7.5K
kimi-cli7.4K
amp7.4K
Expert skill for converting Markdown documents to HTML using the marked.js library, or writing data conversion scripts; in this case scripts similar to markedJS/marked repository. For custom scripts knowledge is not confined to marked.js, but data conversion methods are utilized from tools like pandoc and gomarkdown/markdown for data conversion; jekyll/jekyll and gohugoio/hugo for templating systems.
The conversion script or tool should handle single files, batch conversions, and advanced configurations.
For more see basic-markdown-to-html.md
```markdown
# Level 1
## Level 2
One sentence with a [link](https://example.com), and a HTML snippet like `<p>paragraph tag</p>`.
- `ul` list item 1
- `ul` list item 2
1. `ol` list item 1
2. `ol` list item 1
| Table Item | Description |
| One | One is the spelling of the number `1`. |
| Two | Two is the spelling of the number `2`. |
```js
var one = 1;
var two = 2;
function simpleMath(x, y) {
return x + y;
}
console.log(simpleMath(one, two));
```
```
```html
<h1>Level 1</h1>
<h2>Level 2</h2>
<p>One sentence with a <a href="https://example.com">link</a>, and a HTML snippet like <code><p>paragraph tag</p></code>.</p>
<ul>
<li>`ul` list item 1</li>
<li>`ul` list item 2</li>
</ul>
<ol>
<li>`ol` list item 1</li>
<li>`ol` list item 2</li>
</ol>
<table>
<thead>
<tr>
<th>Table Item</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>One</td>
<td>One is the spelling of the number `1`.</td>
</tr>
<tr>
<td>Two</td>
<td>Two is the spelling of the number `2`.</td>
</tr>
</tbody>
</table>
<pre>
<code>var one = 1;
var two = 2;
function simpleMath(x, y) {
return x + y;
}
console.log(simpleMath(one, two));</code>
</pre>
```
For more see code-blocks-to-html.md
```markdown
your code here
```
```html
<pre><code class="language-md">
your code here
</code></pre>
```
```js
console.log("Hello world");
```
```html
<pre><code class="language-js">
console.log("Hello world");
</code></pre>
```
```markdown
```
```
visible backticks
```
```
```
```html
<pre><code>
```
visible backticks
```
</code></pre>
```
For more see collapsed-sections-to-html.md
```markdown
<details>
<summary>More info</summary>
### Header inside
- Lists
- **Formatting**
- Code blocks
```js
console.log("Hello");
```
</details>
```
```html
<details>
<summary>More info</summary>
<h3>Header inside</h3>
<ul>
<li>Lists</li>
<li><strong>Formatting</strong></li>
<li>Code blocks</li>
</ul>
<pre>
<code class="language-js">console.log("Hello");</code>
</pre>
</details>
```
For more see writing-mathematical-expressions-to-html.md
```markdown
This sentence uses `$` delimiters to show math inline: $\sqrt{3x-1}+(1+x)^2$
```
```html
<p>This sentence uses <code>$</code> delimiters to show math inline:
<math-renderer><math xmlns="http://www.w3.org/1998/Math/MathML">
<msqrt><mn>3</mn><mi>x</mi><mo>−</mo><mn>1</mn></msqrt>
<mo>+</mo><mo>(</mo><mn>1</mn><mo>+</mo><mi>x</mi>
<msup><mo>)</mo><mn>2</mn></msup>
</math>
</math-renderer>
</p>
```
```markdown
**The Cauchy-Schwarz Inequality**\
$$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$$
```
```html
<p><strong>The Cauchy-Schwarz Inequality</strong><br>
<math-renderer>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow><mo>(</mo>
<munderover><mo data-mjx-texclass="OP">∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi>
</munderover>
<msub><mi>a</mi><mi>k</mi></msub>
<msub><mi>b</mi><mi>k</mi></msub>
<mo>)</mo>
</mrow>
<mn>2</mn>
</msup>
<mo>≤</mo>
<mrow><mo>(</mo>
<munderover><mo>∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow>
<mi>n</mi>
</munderover>
<msubsup><mi>a</mi><mi>k</mi><mn>2</mn></msubsup>
<mo>)</mo>
</mrow>
<mrow><mo>(</mo>
<munderover><mo>∑</mo>
<mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow>
<mi>n</mi>
</munderover>
<msubsup><mi>b</mi><mi>k</mi><mn>2</mn></msubsup>
<mo>)</mo>
</mrow>
</math>
</math-renderer></p>
```
For more see tables-to-html.md
```markdown
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
```
```html
<table>
<thead><tr><th>First Header</th><th>Second Header</th></tr></thead>
<tbody>
<tr><td>Content Cell</td><td>Content Cell</td></tr>
<tr><td>Content Cell</td><td>Content Cell</td></tr>
</tbody>
</table>
```
```markdown
| Left-aligned | Center-aligned | Right-aligned |
| :--- | :---: | ---: |
| git status | git status | git status |
| git diff | git diff | git diff |
```
```html
<table>
<thead>
<tr>
<th align="left">Left-aligned</th>
<th align="center">Center-aligned</th>
<th align="right">Right-aligned</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">git status</td>
<td align="center">git status</td>
<td align="right">git status</td>
</tr>
<tr>
<td align="left">git diff</td>
<td align="center">git diff</td>
<td align="right">git diff</td>
</tr>
</tbody>
</table>
```
markedJS/markednpm install -g markednpm install markedSee marked.md Quick Conversion Methods
See marked.md Step-by-Step Workflows
Create ~/.marked.json for persistent options:
{
"gfm": true,
"breaks": true
}
Or use a custom config:
marked -i input.md -o output.html -c config.json
| Option | Description |
|---|---|
-i, --input <file> | Input Markdown file |
-o, --output <file> | Output HTML file |
-s, --string <string> | Parse string instead of file |
-c, --config <file> | Use custom config file |
--gfm | Enable GitHub Flavored Markdown |
--breaks | Convert newlines to |
⚠️ Marked does NOT sanitize output HTML. For untrusted input, use a sanitizer:
import { marked } from 'marked';
import DOMPurify from 'dompurify';
const unsafeHtml = marked.parse(untrustedMarkdown);
const safeHtml = DOMPurify.sanitize(unsafeHtml);
Recommended sanitizers:
| Flavor | Support |
|---|---|
| Original Markdown | 100% |
| CommonMark 0.31 | 98% |
| GitHub Flavored Markdown | 97% |
| Issue | Solution |
|---|---|
| Special characters at file start | Strip zero-width chars: content.replace(/^[\u200B\u200C\u200D\uFEFF]/,"") |
| Code blocks not highlighting | Add a syntax highlighter like highlight.js |
| Tables not rendering | Ensure gfm: true option is set |
| Line breaks ignored | Set breaks: true in options |
| XSS vulnerability concerns | Use DOMPurify to sanitize output |
pandoc# Convert markdown to HTML
pandoc input.md -o output.html
# Convert with standalone document (includes header/footer)
pandoc input.md -s -o output.html
# Explicit format specification
pandoc input.md -f markdown -t html -s -o output.html
# Start pandoc as a filter
pandoc
# Type markdown, then Ctrl-D (Linux/macOS) or Ctrl-Z+Enter (Windows)
Hello *pandoc*!
# Output: <p>Hello <em>pandoc</em>!</p>
# HTML to Markdown
pandoc -f html -t markdown input.html -o output.md
# Markdown to LaTeX
pandoc input.md -s -o output.tex
# Markdown to PDF (requires LaTeX)
pandoc input.md -s -o output.pdf
# Markdown to Word
pandoc input.md -s -o output.docx
| Option | Description |
|---|---|
-f, --from <format> | Input format (markdown, html, latex, etc.) |
-t, --to <format> | Output format (html, latex, pdf, docx, etc.) |
-s, --standalone | Produce standalone document with header/footer |
-o, --output <file> | Output file (inferred from extension) |
--mathml | Convert TeX math to MathML |
--metadata title="Title" |
⚠️ Pandoc processes input faithfully. When converting untrusted markdown:
Use --sandbox mode to disable external file access
Validate input before processing
Sanitize HTML output if displayed in browsers
pandoc --sandbox input.md -o output.html
| Flavor | Support |
|---|---|
| Pandoc Markdown | 100% (native) |
| CommonMark | Full (use -f commonmark) |
| GitHub Flavored Markdown | Full (use -f gfm) |
| MultiMarkdown | Partial |
| Issue | Solution |
|---|---|
| PDF generation fails | Install LaTeX (MacTeX, MiKTeX, or texlive) |
| Encoding issues on Windows | Run chcp 65001 before using pandoc |
| Missing standalone headers | Add -s flag for complete documents |
| Math not rendering | Use --mathml or --mathjax option |
| Tables not rendering | Ensure proper table syntax with pipes and dashes |
gomarkdown/markdowngo get github.com/gomarkdown/markdowngo install github.com/gomarkdown/mdtohtml@latestpackage main
import (
"fmt"
"github.com/gomarkdown/markdown"
)
func main() {
md := []byte("# Hello World\n\nThis is **bold** text.")
html := markdown.ToHTML(md, nil, nil)
fmt.Println(string(html))
}
# Install mdtohtml
go install github.com/gomarkdown/mdtohtml@latest
# Convert file
mdtohtml input.md output.html
# Convert file (output to stdout)
mdtohtml input.md
package main
import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)
func mdToHTML(md []byte) []byte {
// Create parser with extensions
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(extensions)
doc := p.Parse(md)
// Create HTML renderer with extensions
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
return markdown.Render(doc, renderer)
}
The mdtohtml CLI tool has minimal options:
mdtohtml input-file [output-file]
For advanced configuration, use the Go library programmatically with parser and renderer options:
| Parser Extension | Description |
|---|---|
parser.CommonExtensions | Tables, fenced code, autolinks, strikethrough, etc. |
parser.AutoHeadingIDs | Generate IDs for headings |
parser.NoEmptyLineBeforeBlock | No blank line needed before blocks |
parser.MathJax | MathJax support for LaTeX math |
| HTML Flag | Description |
| --- | --- |
html.CommonFlags | Common HTML output flags |
⚠️ gomarkdown does NOT sanitize output HTML. For untrusted input, use Bluemonday:
import (
"github.com/microcosm-cc/bluemonday"
"github.com/gomarkdown/markdown"
)
maybeUnsafeHTML := markdown.ToHTML(md, nil, nil)
html := bluemonday.UGCPolicy().SanitizeBytes(maybeUnsafeHTML)
Recommended sanitizer: Bluemonday
| Flavor | Support |
|---|---|
| Original Markdown | 100% |
| CommonMark | High (with extensions) |
| GitHub Flavored Markdown | High (tables, fenced code, strikethrough) |
| MathJax/LaTeX Math | Supported via extension |
| Mmark | Supported |
| Issue | Solution |
|---|---|
| Windows/Mac newlines not parsed | Use parser.NormalizeNewlines(input) |
| Tables not rendering | Enable parser.Tables extension |
| Code blocks without highlighting | Integrate with syntax highlighter like Chroma |
| Math not rendering | Enable parser.MathJax extension |
| XSS vulnerabilities | Use Bluemonday to sanitize output |
jekyllgem install jekyll bundler# Create a new Jekyll site
jekyll new myblog
# Change to site directory
cd myblog
# Build and serve locally
bundle exec jekyll serve
# Access at http://localhost:4000
# Build site to _site directory
bundle exec jekyll build
# Build with production environment
JEKYLL_ENV=production bundle exec jekyll build
# Serve with live reload
bundle exec jekyll serve --livereload
# Serve with drafts
bundle exec jekyll serve --drafts
| Command | Description |
|---|---|
jekyll new <path> | Create new Jekyll site |
jekyll build | Build site to _site directory |
jekyll serve | Build and serve locally |
jekyll clean | Remove generated files |
jekyll doctor | Check for configuration issues |
| Serve Options | Description |
⚠️ Jekyll security considerations:
Avoid using safe: false in production
Use exclude in _config.yml to prevent sensitive files from being published
Sanitize user-generated content if accepting external input
Keep Jekyll and plugins updated
exclude:
| Flavor | Support |
|---|---|
| Kramdown (default) | 100% |
| CommonMark | Via plugin (jekyll-commonmark) |
| GitHub Flavored Markdown | Via plugin (jekyll-commonmark-ghpages) |
| RedCarpet | Via plugin (deprecated) |
Configure markdown processor in _config.yml:
markdown: kramdown
kramdown:
input: GFM
syntax_highlighter: rouge
| Issue | Solution |
|---|---|
| Ruby 3.0+ fails to serve | Run bundle add webrick |
| Gem dependency errors | Run bundle install |
| Slow builds | Use --incremental flag |
| Liquid syntax errors | Check for unescaped { in content |
| Plugin not loading | Add to _config.yml plugins list |
hugo# Create a new Hugo site
hugo new site mysite
# Change to site directory
cd mysite
# Add a theme
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
echo "theme = 'ananke'" >> hugo.toml
# Create content
hugo new content posts/my-first-post.md
# Start development server
hugo server -D
# Build site to public directory
hugo
# Build with minification
hugo --minify
# Build for specific environment
hugo --environment production
# Start server with drafts
hugo server -D
# Start with live reload and bind to all interfaces
hugo server --bind 0.0.0.0 --baseURL http://localhost:1313/
# Start with specific port
hugo server --port 8080
| Command | Description |
|---|---|
hugo new site <name> | Create new Hugo site |
hugo new content <path> | Create new content file |
hugo | Build site to public directory |
hugo server | Start development server |
hugo mod init | Initialize Hugo Modules |
| Build Options | Description |
⚠️ Hugo security considerations:
Configure security policy in hugo.toml for external commands
Use --enableGitInfo carefully with public repositories
Validate shortcode parameters for user-generated content
[security] enableInlineShortcodes = false [security.exec] allow = ['^go$', '^npx$', '^postcss$'] [security.funcs] getenv = ['^HUGO_', '^CI$'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*']
| Flavor | Support |
|---|---|
| Goldmark (default) | 100% (CommonMark compliant) |
| GitHub Flavored Markdown | Full (tables, strikethrough, autolinks) |
| CommonMark | 100% |
| Blackfriday (legacy) | Deprecated, not recommended |
Configure markdown in hugo.toml:
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
definitionList = true
footnote = true
linkify = true
strikethrough = true
table = true
taskList = true
[markup.goldmark.renderer]
unsafe = false # Set true to allow raw HTML
| Issue | Solution |
|---|---|
| "Page not found" on paths | Check baseURL in config |
| Theme not loading | Verify theme in themes/ or Hugo Modules |
| Slow builds | Use --templateMetrics to identify bottlenecks |
| Raw HTML not rendering | Set unsafe = true in goldmark config |
| Images not loading | Check static/ folder structure |
| Module errors | Run hugo mod tidy |
markedJS/markedpandocgomarkdown/markdownjekyllhugoWeekly Installs
7.6K
Repository
GitHub Stars
26.7K
First Seen
Feb 2, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex7.5K
gemini-cli7.5K
opencode7.5K
github-copilot7.5K
kimi-cli7.4K
amp7.4K
97,600 周安装
<br>--help | Show all options |
| Set document metadata |
--toc | Include table of contents |
--template <file> | Use custom template |
--help | Show all options |
html.HrefTargetBlank | Add target="_blank" to links |
html.CompletePage | Generate complete HTML page |
html.UseXHTML | Generate XHTML output |
| --- | --- |
--livereload | Reload browser on changes |
--drafts | Include draft posts |
--port <port> | Set server port (default: 4000) |
--host <host> | Set server host (default: localhost) |
--baseurl <url> | Set base URL |
| --- | --- |
-D, --buildDrafts | Include draft content |
-E, --buildExpired | Include expired content |
-F, --buildFuture | Include future-dated content |
--minify | Minify output |
--gc | Run garbage collection after build |
-d, --destination <path> | Output directory |
| Server Options | Description |
| --- | --- |
--bind <ip> | Interface to bind to |
-p, --port <port> | Port number (default: 1313) |
--liveReloadPort <port> | Live reload port |
--disableLiveReload | Disable live reload |
--navigateToChanged | Navigate to changed content |