Movatterモバイル変換


[0]ホーム

URL:


logo

Marked Documentation

Marked is

  1. built for speed.*
  2. a low-level markdown compiler for parsing markdown without caching or blocking for long periods of time.**
  3. light-weight while implementing all markdown features from the supported flavors & specifications.***
  4. available as a command line interface (CLI) and running in client- or server-side JavaScript projects.

* Still working on metrics for comparative analysis and definition.
** As few dependencies as possible.
*** Strict compliance could result in slower processing when running comparative benchmarking.

Demo

Checkout thedemo page to see marked in action ⛹️

These documentation pages are also rendered using marked 💯

Installation

CLI:npm install -g marked

In-browser:

npminstall marked

Usage

Warning: 🚨 Marked does notsanitize the output HTML. If you are processing potentially unsafe strings, it's important to filter for possible XSS attacks. Some filtering options includeDOMPurify (recommended),js-xss,sanitize-html andinsane on theoutput HTML! 🚨

DOMPurify.sanitize(marked.parse(`<imgsrc="x" onerror="alert('not happening')">`));

⚠️ Input: special ZERO WIDTH unicode characters (for example\uFEFF) might interfere with parsing. Some text editors add them at the start of the file (see:#2139).

// remove the most common zerowidth characters from the start of the filemarked.parse(  contents.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,""))

CLI

# Example with stdin input$ marked -o hello.htmlhello world^D$cat hello.html<p>hello world</p>
# Example with string input$ marked -s"*hello world*"<p><em>hello world</em></p>
# Example with file inputecho"**bold text example**" > readme.md$ marked -i readme.md -o readme.html$cat readme.html<p><strong>bold text example</strong></p>
# Print all options$ marked --help

CLI Config

A config file can be used to configure the marked cli.

If it is a.json file it should be a JSON object that will be passed to marked as options.

If.js is used it should have a default export of a marked options object or a function that takesmarked as a parameter.It can use themarked parameter to install extensions usingmarked.use.

By default the marked cli will look for a config file in your home directory in the following order.

  • ~/.marked.json
  • ~/.marked.js
  • ~/.marked/index.js
# Example with custom configecho'{ "breaks": true }' > config.json$ marked -s'line1\nline2' -c config.json<p>line1<br>line2</p>

Browser

<!doctypehtml><html><head><metacharset="utf-8"/><title>Marked in the browser</title></head><body><divid="content"></div><scriptsrc="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script>document.getElementById('content').innerHTML =      marked.parse('# Marked in browser\n\nRendered by **marked**.');</script></body></html>

or import esm module

<scripttype="module">import { marked }from"https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";document.getElementById('content').innerHTML =    marked.parse('# Marked in the browser\n\nRendered by **marked**.');</script>

Node.js

import { marked }from'marked';// or const { marked } = require('marked');const html = marked.parse('# Marked in Node.js\n\nRendered by **marked**.');

Marked offersadvanced configurations andextensibility as well.

Supported Markdown specifications

We actively support the features of the followingMarkdown flavors.

Markdown 1.0 (100%)
SectionPassingPercent
amps_and_angles_encoding1 of 1100%
auto_links1 of 1100%
backslash_escapes1 of 1100%
blockquotes_with_code_blocks1 of 1100%
code_blocks1 of 1100%
code_spans1 of 1100%
hard_wrapped_paragraphs_with_list_like_lines1 of 1100%
horizontal_rules1 of 1100%
inline_html_advanced1 of 1100%
inline_html_comments1 of 1100%
inline_html_simple1 of 1100%
links_inline_style1 of 1100%
links_reference_style1 of 1100%
links_shortcut_references1 of 1100%
literal_quotes_in_titles1 of 1100%
markdown_documentation_basics1 of 1100%
markdown_documentation_syntax1 of 1100%
nested_blockquotes1 of 1100%
ordered_and_unordered_lists1 of 1100%
tabs1 of 1100%
tidyness1 of 1100%
CommonMark 0.31 (96%)
SectionPassingPercent
Tabs11 of 11100%
Backslash escapes13 of 13100%
Entity and numeric character references15 of 1788%
Precedence1 of 1100%
Thematic breaks19 of 19100%
ATX headings18 of 18100%
Setext headings27 of 27100%
Indented code blocks12 of 12100%
Fenced code blocks29 of 29100%
HTML blocks44 of 44100%
Link reference definitions27 of 27100%
Paragraphs8 of 8100%
Blank lines1 of 1100%
Block quotes25 of 25100%
List items48 of 48100%
Lists26 of 26100%
Inlines1 of 1100%
Code spans22 of 22100%
Emphasis and strong emphasis132 of 132100%
Links75 of 9083%
Images15 of 2268%
Autolinks19 of 19100%
Raw HTML20 of 20100%
Hard line breaks15 of 15100%
Soft line breaks2 of 2100%
Textual content3 of 3100%
GitHub Flavored Markdown 0.29 (95%)
SectionPassingPercent
Tabs11 of 11100%
Backslash escapes13 of 13100%
Entity and numeric character references15 of 1788%
Precedence1 of 1100%
Thematic breaks19 of 19100%
ATX headings18 of 18100%
Setext headings27 of 27100%
Indented code blocks12 of 12100%
Fenced code blocks29 of 29100%
HTML blocks44 of 44100%
Link reference definitions27 of 27100%
Paragraphs8 of 8100%
Blank lines1 of 1100%
Block quotes25 of 25100%
List items48 of 48100%
Lists26 of 26100%
Inlines1 of 1100%
Code spans22 of 22100%
Emphasis and strong emphasis132 of 132100%
Links75 of 9083%
Images15 of 2268%
Autolinks15 of 1979%
Raw HTML20 of 20100%
Hard line breaks15 of 15100%
Soft line breaks2 of 2100%
Textual content3 of 3100%
[extension] Tables8 of 8100%
[extension] Task list items2 of 2100%
[extension] Strikethrough3 of 3100%
[extension] Autolinks11 of 1479%
[extension] Disallowed Raw HTML0 of 10%

By supporting the above Markdown flavors, it's possible that Marked can help you use other flavors as well; however, these are not actively supported by the community.

List of Tools Using Marked

We actively support the usability of Marked in super-fast markdown transformation, some of Tools usingMarked for single-page creations are

ToolsDescription
zero-mdA native markdown-to-html web component to load and display an external MD file.It uses Marked for super-fast markdown transformation.
texmeTeXMe is a lightweight JavaScript utility to create self-rendering Markdown + LaTeX documents.
StrapDown.jsStrapDown.js is an awesome on-the-fly Markdown to HTML text processor.
raitoMini Markdown Wiki/CMS in 8kb of JavaScript.
HomebreweryThe Homebrewery is a tool for making authentic looking D&D content using Markdown. It is distributed under the terms of the MIT.
marked_readermarked_reader is an open source Markdown reader packed by Electron.

Security

The only completely secure system is the one that doesn't exist in the first place. Having said that, we take the security of Marked very seriously.

Therefore, please disclose potential security issues by email to the projectcommitters as well as thelisted owners within NPM. We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue).


[8]ページ先頭

©2009-2025 Movatter.jp