1 Star 0 Fork 0

小弟调调 / markdown-to-html

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Convert Markdown to HTML.

CI jsDelivr CDN npm version Open in unpkg

Converts markdown text to HTML.

Installation

This package v2+ is ESM only: Node 12+ is needed to use it and it must be import instead of require.

$ npm i @wcj/markdown-to-html

Usage

import markdown, { getCodeString } from '@wcj/markdown-to-html';

markdown('# Markdown String')
// => <h1>Markdown String</h1>

Or manually download and link markdown-to-html in your HTML, It can also be downloaded via UNPKG:

CDN: UNPKG | jsDelivr | Githack | Statically

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.0/dist/katex.min.css">
<link rel="stylesheet" href="https://unpkg.com/@wcj/markdown-to-html/dist/marked.css">

<script src="https://unpkg.com/@wcj/markdown-to-html/dist/markdown.min.js"></script>
<script type="text/javascript">
  ;(() => {
    const str = '# Markdown to HTML\n\nConverts markdown text to HTML.\n\n';
    const div = document.createElement('div');
    div.className = 'markdown-body';
    div.innerHTML = markdown.default(str)
    document.body.appendChild(div)
  })()
</script>

Add Markdown Style

① Import the css file.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.0/dist/katex.min.css">
<link rel="stylesheet" href="https://unpkg.com/@wcj/markdown-to-html/dist/marked.css">

② Or use <markdown-style> components.

npm version Github Source Code

<script src="https://unpkg.com/@wcj/markdown-style"></script>
<markdown-style>
  <!-- markdown html is here -->
  <h1>Markdown HTML</h1>
</markdown-style>

API

import { PluggableList } from 'unified';
import { Options as RemarkRehypeOptions } from 'remark-rehype';
import { RehypeRewriteOptions, getCodeString } from 'rehype-rewrite';
export { getCodeString };
export interface Options {
  /** [remark-rehype](https://github.com/remarkjs/remark-rehype) options */
  remarkRehypeOptions?: RemarkRehypeOptions;
  /** List of [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins) to use. See the next section for examples on how to pass options */
  remarkPlugins?: PluggableList;
  /** List of [rehype plugins](https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins) to use. See the next section for examples on how to pass options */
  rehypePlugins?: PluggableList;
  /** Used to filter default plugins */
  filterPlugins?: (type: 'remark' | 'rehype', plugins?: PluggableList) => PluggableList;
  /** Resulting Node tree. */
  hastNode?: boolean;
  /** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */
  rewrite?: RehypeRewriteOptions['rewrite'];
}
export default function markdown(markdownStr?: string, options?: Options): string | import("hast").Root;

Markdown Features

Supports for CSS Style

Use HTML comments <!--rehype:xxx--> to let Markdown support style customization.

## Title
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->

Markdown Supports **Style**<!--rehype:style=color: red;-->

Support for GFM footnotes

Here is a simple footnote[^1]. With some additional text after it.

[^1]: My reference.

Support for KaTeX

Support markdown syntax to render math. You can combine it with KaTeX in markdown, add `KaTeX:string` and ```markdown classes in markdown.

\`KaTeX:c = \\pm\\sqrt{a^2 + b^2}\`
\`\`\`KaTeX
c = \\pm\\sqrt{a^2 + b^2}

L = \\frac{1}{2} \\rho v^2 S C_L
\`\`\`

Contributors

As always, thanks to our amazing contributors!

Made with github-action-contributors.

License

Licensed under the MIT License.

空文件

简介

Converts markdown text to HTML. 展开 收起
TypeScript 等 4 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/jaywcjlove/markdown-to-html.git
git@gitee.com:jaywcjlove/markdown-to-html.git
jaywcjlove
markdown-to-html
markdown-to-html
main

搜索帮助