npm.io
5.0.4 • Published 9 months agoCLI

markdown-to-html-cli

Licence
MIT
Version
5.0.4
Deps
16
Size
204 kB
Vulns
1
Weekly
0
Stars
95
Using my app is also a way to support me:
Screen Test Deskmark Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Mousio Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe

markdown-to-html-cli

Buy me a coffee Downloads npm version Build and Test Coverage Status 中文文档

Converts markdown text to HTML, Provide command line tools and methods. If you are simply converting a small number of Markdown files (or text) into HTML pages, this is very helpful for you.

Usage

Used in Github Actions.

- run: npm i markdown-to-html-cli -g
- run: markdown-to-html --output coverage/index.html
- run: markdown-to-html --source src/README.md --output coverage/index.html
# or
- name: Converts Markdown to HTML
  uses: jaywcjlove/markdown-to-html-cli@main
  with:
    source: README-zh.md
    output: coverage/action.html
    github-corners: https://github.com/jaywcjlove/markdown-to-html-cli
    favicon: data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌐</text></svg>

Using With Command.

{
  "scripts": {
    "start": "markdown-to-html --output coverage/index.html"
  },
  "devDependencies": {
    "markdown-to-html-cli": "latest"
  }
}

Used in Nodejs.

import { create } from 'markdown-to-html-cli';

const html = create({
  markdown: 'Hello World! **Bold**\n# Title',
  document: {
    style: ['body { background: red; }'],
  }
});
// => HTML String

Install

$ npm i markdown-to-html-cli

Github Actions

- name: Converts Markdown to HTML
  uses: jaywcjlove/markdown-to-html-cli@main
  with:
    source: README-zh.md
    output: coverage/action.html
    github-corners: https://github.com/jaywcjlove/markdown-to-html-cli
    favicon: data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌐</text></svg>
Input Parameters
  • output - Output static pages to the specified directory. (default: index.html)
  • source - The path of the target file "README.md". (default: README.md)
  • description - Define a description of your web page.
  • config - Specify the configuration file. (default: package.json)
  • markdown - Markdown string
  • favicon - Add a Favicon to your Site.
  • github-corners - Add a Github corner to your project page.
  • corners - Show corners. (default: true)
  • dark-mode - Disable light and dark theme styles button. (default: true)
  • markdown-style - Markdown wrapper style.
  • markdown-style-theme - Setting markdown-style light/dark theme. (dark | light)
  • style - Override default styles. css file path or css string
  • title - Define the content of the "" document title!</li> </ul> <h5 id="user-content-output-parameters" data-level="3"><a href="#user-content-output-parameters">Output Parameters</a></h5> <ul> <li><code>output</code> - Output static pages to the specified directory</li> <li><code>markdown</code> - Markdown string</li> <li><code>html</code> - HTML string</li> </ul> <h4 id="user-content-configure-in-packagejson" data-level="2"><a href="#user-content-configure-in-packagejson">Configure in package.json</a></h4> <p>The configuration can be specified through <code>--config="config/conf.json"</code>, It can be in <code>package.json</code> by default.</p> <pre class="hljs"><code class="language-js">{ <span class="hljs-string">"markdown-to-html"</span>: { <span class="hljs-string">"document"</span>: { <span class="hljs-string">"title"</span>: <span class="hljs-string">"markdown-to-html-cli"</span>, <span class="hljs-string">"description"</span>: <span class="hljs-string">"Command line tool generates markdown as html."</span>, <span class="hljs-string">"style"</span>: <span class="hljs-string">"body { color: red; }"</span>, <span class="hljs-string">"meta"</span>: [ { <span class="hljs-string">"description"</span>: <span class="hljs-string">"Command line tool generates markdown as html."</span> }, { <span class="hljs-string">"keywords"</span>: <span class="hljs-string">"store,localStorage,lightweight,JavaScript"</span> } ] }, <span class="hljs-string">"favicon"</span>: <span class="hljs-string">"data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22></text></svg>"</span>, <span class="hljs-string">"github-corners"</span>: <span class="hljs-string">"https://github.com/jaywcjlove/markdown-to-html-cli"</span>, <span class="hljs-string">"reurls"</span>: { <span class="hljs-string">"README-zh.md"</span>: <span class="hljs-string">"index.zh.html"</span>, <span class="hljs-string">"README.md"</span>: <span class="hljs-string">"index.html"</span> } } }</code></pre> <ul> <li><a href="https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L2" rel="nofollow noreferrer noopener" target="_blank"><code>name</code></a> -> <code>'markdown-to-html'.title</code> - Define the content of the <code><title></code> document title!</li> <li><a href="https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L4" rel="nofollow noreferrer noopener" target="_blank"><code>description</code></a> -> <code>'markdown-to-html'.description</code> - Define a description of your web page.</li> <li><a href="https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L22" rel="nofollow noreferrer noopener" target="_blank"><code>repository.url</code></a> -> <code>'markdown-to-html'.github-corners</code> - Add a Github corner to your project page.</li> <li><a href="https://github.com/jaywcjlove/markdown-to-html-cli/blob/308ca37aa5b9ae846a7835092a183d0ed73a8dc4/package.json#L24-L30" rel="nofollow noreferrer noopener" target="_blank"><code>keywords</code></a> -> <code>'markdown-to-html'.document.meta</code> - Define keywords for search engines.</li> </ul> <h4 id="user-content-command-help" data-level="2"><a href="#user-content-command-help">Command Help</a></h4> <pre class="hljs"><code class="language-bash">Usage: markdown-to-html [options] [--<span class="hljs-built_in">help</span>|h] Options: --author Define the author of a page. --config, -o Specify the configuration file. Default: <span class="hljs-string">"<process.cwd()>/package.json"</span>. --description Define a description of your web page. --favicon Add a Favicon to your Site. --no-corners Hide Github corner from your project page. --github-corners Add a Github corner to your project page. --github-corners-fork Github corners style. --keywords Define keywords <span class="hljs-keyword">for</span> search engines. --no-dark-mode Disable light and dark theme styles button. --markdown Markdown string. --img-base64 Convert images <span class="hljs-keyword">in</span> HTML to <span class="hljs-built_in">base64</span>. --style Override default styles. css file path or css string. --markdown-style-theme Setting markdown-style light/dark theme. --markdown-style Markdown wrapper style --ignore-file Ignore markdown files under certain paths. Default: <span class="hljs-string">"(node_modules)"</span> --output, -o Output static pages to the specified directory. Default: <span class="hljs-string">"index.html"</span> --<span class="hljs-built_in">source</span>, -s The path of the target file <span class="hljs-string">"README.md"</span>. Default: <span class="hljs-string">"README.md"</span> --title The `<title>` tag is required <span class="hljs-keyword">in</span> HTML documents! --version, -v Show version number --<span class="hljs-built_in">help</span>, -h Displays <span class="hljs-built_in">help</span> information. Example: markdown-to-html --title=<span class="hljs-string">"Hello World!"</span> markdown-to-html --config=<span class="hljs-string">"config/conf.json"</span> npx markdown-to-html-cli npx markdown-to-html-cli **/*.md --output <span class="hljs-string">"dist"</span> npx markdown-to-html-cli **/*.md --ignore-file=<span class="hljs-string">"(test)"</span> npx markdown-to-html-cli --markdown=<span class="hljs-string">"Hello World!"</span> npx markdown-to-html-cli --no-dark-mode npx markdown-to-html-cli --dark-mode auto npx markdown-to-html-cli --dark-mode auto --markdown-style-theme dark npx markdown-to-html-cli --no-dark-mode --markdown-style-theme dark npx markdown-to-html-cli --markdown-style-theme dark npx markdown-to-html-cli --github-corners https://github.com/jaywcjlove/markdown-to-html-cli npx markdown-to-html-cli --github-corners https://github.com/jaywcjlove --github-corners-fork npx markdown-to-html-cli --output coverage/index.html npx markdown-to-html-cli --<span class="hljs-built_in">source</span> README.md npx markdown-to-html-cli --<span class="hljs-built_in">source</span> README.md --style=./style.css npx markdown-to-html-cli --<span class="hljs-built_in">source</span> README.md --style=<span class="hljs-string">'body { color: red; }'</span></code></pre> <h4 id="user-content-markdown-features" data-level="2"><a href="#user-content-markdown-features">Markdown Features</a></h4> <h5 id="user-content-supports-for-css-style" data-level="3"><a href="#user-content-supports-for-css-style">Supports for CSS Style</a></h5> <p>Use HTML comments <a href="https://github.com/jaywcjlove/rehype-attr" rel="nofollow noreferrer noopener" target="_blank"><code><!--rehype:xxx--></code></a><!--rehype:style=color: red;--> to let Markdown support style customization.</p> <pre class="hljs"><code class="language-markdown"><span class="hljs-section">## Title</span> <!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;--> Markdown Supports <span class="hljs-strong">**Style**</span><!--rehype:style=color: red;--></code></pre> <h5 id="user-content-support-for-gfm-footnotes" data-level="3"><a href="#user-content-support-for-gfm-footnotes">Support for <a href="https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/" rel="nofollow noreferrer noopener" target="_blank">GFM footnotes</a></a></h5> <pre class="hljs"><code class="language-markdown">Here is a simple footnote[^1]. With some additional text after it. [<span class="hljs-symbol">^1</span>]: <span class="hljs-link">My reference.</span></code></pre> <h5 id="user-content-task-lists" data-level="3"><a href="#user-content-task-lists"><a href="https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#task-lists" rel="nofollow noreferrer noopener" target="_blank">Task lists</a></a></h5> <p>To create a task list, preface list items with a regular space character followed by <code>[ ]</code>. To mark a task as complete, use <code>[x]</code>.</p> <pre class="hljs"><code class="language-markdown"><span class="hljs-bullet">-</span> [x] #739 <span class="hljs-bullet">-</span> [ ] https://github.com/octo-org/octo-repo/issues/740 <span class="hljs-bullet">-</span> [ ] Add delight to the experience when all tasks are complete </code></pre> <p>If a task list item description begins with a parenthesis, you'll need to escape it with <code>\</code>:</p> <pre class="hljs"><code class="language-markdown"><span class="hljs-bullet">-</span> [ ] \(Optional) Open a followup issue</code></pre> <h4 id="user-content-api" data-level="2"><a href="#user-content-api">API</a></h4> <pre class="hljs"><code class="language-ts"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">ParsedArgs</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'minimist'</span>; <span class="hljs-keyword">import</span> { <span class="hljs-title class_">Options</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'rehype-document'</span>; <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">CreateOptions</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">MDToHTMLOptions</span> { } <span class="hljs-keyword">export</span> <span class="hljs-keyword">declare</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">create</span>(<span class="hljs-params"><span class="hljs-attr">options</span>?: <span class="hljs-title class_">CreateOptions</span></span>): <span class="hljs-built_in">string</span>; <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">RunArgvs</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Omit</span><<span class="hljs-title class_">ParsedArgs</span>, '_'> { <span class="hljs-attr">version</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-attr">source</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-attr">output</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Add a Github corner to your project page. */</span> <span class="hljs-string">'github-corners'</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Github corners style. */</span> <span class="hljs-string">'github-corners-fork'</span>?: <span class="hljs-built_in">boolean</span>; <span class="hljs-comment">/** Disable light and dark theme styles button. */</span> <span class="hljs-string">'dark-mode'</span>?: <span class="hljs-built_in">boolean</span>; <span class="hljs-comment">/** Setting markdown-style light/dark theme. */</span> <span class="hljs-string">'markdown-style-theme'</span>?: <span class="hljs-string">'dark'</span> | <span class="hljs-string">'light'</span>; <span class="hljs-comment">/** Markdown string. */</span> <span class="hljs-attr">markdown</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Markdown wrapper style */</span> <span class="hljs-string">'markdown-style'</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** The `<title>` tag is required in HTML documents! */</span> <span class="hljs-attr">title</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Specify the configuration file. Default: `<process.cwd()>/package.json` */</span> <span class="hljs-attr">config</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Define a description of your web page */</span> <span class="hljs-attr">description</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Define keywords for search engines */</span> <span class="hljs-attr">keywords</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Add a Favicon to your Site */</span> <span class="hljs-attr">favicon</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Define the author of a page */</span> <span class="hljs-attr">author</span>?: <span class="hljs-built_in">string</span>; <span class="hljs-comment">/** Override default styles */</span> <span class="hljs-attr">style</span>?: <span class="hljs-built_in">string</span>; } <span class="hljs-keyword">export</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">MDToHTMLOptions</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">RunArgvs</span> { <span class="hljs-comment">/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */</span> <span class="hljs-attr">document</span>?: <span class="hljs-title class_">Options</span>; <span class="hljs-comment">/** Rewrite Element. [rehype-rewrite](https://github.com/jaywcjlove/rehype-rewrite#rewritenode-index-parent-void) */</span> <span class="hljs-attr">rewrite</span>?: <span class="hljs-title class_">RehypeRewriteOptions</span>[<span class="hljs-string">'rewrite'</span>]; <span class="hljs-comment">/** rewrite URLs of href and src attributes. */</span> <span class="hljs-attr">reurls</span>?: <span class="hljs-title class_">Record</span><<span class="hljs-built_in">string</span>, <span class="hljs-built_in">string</span>>; } <span class="hljs-keyword">export</span> <span class="hljs-keyword">declare</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">run</span>(<span class="hljs-params"><span class="hljs-attr">opts</span>?: <span class="hljs-title class_">Omit</span><<span class="hljs-title class_">RunArgvs</span>, <span class="hljs-string">"_"</span>></span>): <span class="hljs-built_in">any</span>; <span class="hljs-keyword">export</span> <span class="hljs-keyword">declare</span> <span class="hljs-keyword">const</span> <span class="hljs-attr">cliHelp</span>: <span class="hljs-built_in">string</span>; <span class="hljs-keyword">export</span> <span class="hljs-keyword">declare</span> <span class="hljs-keyword">const</span> <span class="hljs-attr">exampleHelp</span>: <span class="hljs-built_in">string</span>;</code></pre> <h4 id="user-content-related" data-level="2"><a href="#user-content-related">Related</a></h4> <ul> <li><a href="https://github.com/jaywcjlove/markdown-to-html" rel="nofollow noreferrer noopener" target="_blank">markdown-to-html</a> Converts markdown text to HTML.</li> </ul> <h4 id="user-content-development" data-level="2"><a href="#user-content-development">Development</a></h4> <pre class="hljs"><code class="language-bash">$ npm i $ npm run build $ npm run watch</code></pre> <h4 id="user-content-related-1" data-level="2"><a href="#user-content-related-1">Related</a></h4> <ul> <li><a href="https://github.com/jaywcjlove/html-to-markdown-cli" rel="nofollow noreferrer noopener" target="_blank">html-to-markdown-cli</a> Converts HTML to markdown.</li> </ul> <h4 id="user-content-contributors" data-level="2"><a href="#user-content-contributors">Contributors</a></h4> <p>As always, thanks to our amazing contributors!</p> <a href="https://github.com/jaywcjlove/markdown-to-html-cli/graphs/contributors"> <img src="https://jaywcjlove.github.io/markdown-to-html-cli/CONTRIBUTORS.svg" /> </a><p>Made with <a href="https://github.com/jaywcjlove/github-action-contributors" rel="nofollow noreferrer noopener" target="_blank">github-action-contributors</a>.</p> <h4 id="user-content-license" data-level="2"><a href="#user-content-license">License</a></h4> <p>MIT <a href="https://wangchujiang.com/" rel="nofollow noreferrer noopener" target="_blank">Kenny Wong</a></p>

Keywords