镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.vercel
node_modules/
test/compiled_tests
public
docs/LICENSE.md

10 changes: 0 additions & 10 deletions .vercelignore

This file was deleted.

65 changes: 65 additions & 0 deletions build-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { mkdir, rmdir, readdir, stat, readFile, writeFile, copyFile } = require('fs').promises;
const { join, dirname, parse, format } = require('path');
const marked = require('./');
const { highlight, highlightAuto } = require('highlight.js');
const titleize = require('titleize');
const cwd = process.cwd();
const inputDir = join(cwd, 'docs');
const outputDir = join(cwd, 'public');
const templateFile = join(inputDir, '_document.html');
const isUppercase = str => /[A-Z_]+/.test(str);
const getTitle = str => str === 'INDEX' ? '' : titleize(str.replace(/_/g, ' ')) + ' - ';

async function init() {
console.log('Cleaning up output directory ' + outputDir);
await rmdir(outputDir, { recursive: true });
await mkdir(outputDir);
await copyFile(join(cwd, 'LICENSE.md'), join(inputDir, 'LICENSE.md'));
const tmpl = await readFile(templateFile, 'utf8');
console.log('Building markdown...');
await build(inputDir, tmpl);
console.log('Build complete!');
}

async function build(currentDir, tmpl) {
const files = await readdir(currentDir);
for (const file of files) {
const filename = join(currentDir, file);
const stats = await stat(filename);
const { mode } = stats;
if (stats.isDirectory()) {
// console.log('Found directory ' + filename);
await build(filename, tmpl);
} else {
// console.log('Reading file ' + filename);
let buffer = await readFile(filename);
const parsed = parse(filename);
if (parsed.ext === '.md' && isUppercase(parsed.name)) {
const html = marked(buffer.toString('utf8'), {
highlight: (code, lang) => {
if (!lang) {
return highlightAuto(code).value;
}
return highlight(lang, code).value;
}
});
buffer = Buffer.from(tmpl
.replace('<!--{{title}}-->', getTitle(parsed.name))
.replace('<!--{{content}}-->', html),
'utf8'
);
parsed.ext = '.html';
parsed.name = parsed.name.toLowerCase();
delete parsed.base;
}
parsed.dir = parsed.dir.replace(inputDir, outputDir);
const outfile = format(parsed);
// console.log('Ensure directory ' + dirname(outfile));
await mkdir(dirname(outfile), { recursive: true });
console.log('Writing file ' + outfile);
await writeFile(outfile, buffer, { mode });
}
}
}

init().catch(console.error);
2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team by submitting a PR with changes to the [AUTHORS](#/AUTHORS.md) page (or emailing josh@8fold.com). All
reported by contacting the project team by submitting a PR with changes to the [AUTHORS](/authors) page (or emailing josh@8fold.com). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
6 changes: 3 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ The following table lists the ticket type labels we use when there is work to be
|Ticket type label |Description |
|:----------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|L0 - security |A security vulnerability within the Marked library is discovered. |
|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](#/README.md#specifications) OR causes marked to crash AND there is no known workaround for the issue. |
|L1 - broken |Valid usage results in incorrect output compared to [supported specifications](/#specifications) OR causes marked to crash AND there is no known workaround for the issue. |
|L2 - annoying |Similar to L1 - broken only there is a known workaround available for the issue. |
|RR - refactor and re-engineer |Results in an improvement to developers using Marked (improved readability) or end-users (faster performance) or both. |
|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](#/README.md#specifications) |
|NFS - new feature (spec related) |A capability Marked does not currently provide but is in one of the [supported specifications](/#specifications) |
|NFU - new feature (user requested) |A capability Marked does not currently provide but has been requested by users of Marked. |
|NFE - new feature (should be an extension) |A capability Marked does not currently provide and is not part of a spec. |

## Test early, often, and everything

We try to write test cases to validate output (writing tests based on the [supported specifications](#/README.md#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness.
We try to write test cases to validate output (writing tests based on the [supported specifications](/#specifications)) and minimize regression (writing tests for issues fixed). Therefore, if you would like to contribute, some things you should know regarding the test harness.

|Location |Description |
|:---------------------|:--------------------------------------------------------------------------------------------------------------|
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md → docs/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ These documentation pages are also rendered using marked 💯

<h2 id="usage">Usage</h2>

### Warning: 🚨 Marked does not [sanitize](https://marked.js.org/#/USING_ADVANCED.md#options) the output HTML. Please use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the output HTML! 🚨
### Warning: 🚨 Marked does not [sanitize](/using_advanced#options) the output HTML. Please use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the output HTML! 🚨

**CLI**

Expand Down Expand Up @@ -63,7 +63,7 @@ $ marked -s "*hello world*"
```


Marked offers [advanced configurations](#/USING_ADVANCED.md) and [extensibility](#/USING_PRO.md) as well.
Marked offers [advanced configurations](/using_advanced) and [extensibility](/using_pro) as well.

<h2 id="specifications">Supported Markdown specifications</h2>

Expand All @@ -81,5 +81,5 @@ By supporting the above Markdown flavors, it's possible that Marked can help you

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 project [committers](#/AUTHORS.md) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). 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).
Therefore, please disclose potential security issues by email to the project [committers](/authors) as well as the [listed owners within NPM](https://docs.npmjs.com/cli/owner). 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).

2 changes: 1 addition & 1 deletion docs/PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Releasing Marked

- [ ] See [contributing](#/CONTRIBUTING.md)
- [ ] See [contributing](/contributing)
- [ ] Create release branch from `master` (`release-x.y.z`)
- [ ] Submit PR with minimal name: Release x.y.z
- [ ] Complete PR checklists
Expand Down
6 changes: 3 additions & 3 deletions docs/USING_ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ console.log(marked(markdownString));
|langPrefix |`string` |`'language-'`|v0.3.0|A string to prefix the className in a `<code>` block. Useful for syntax highlighting.|
|mangle |`boolean` |`true` |v0.3.4 |If true, autolinked email address is escaped with HTML character references.|
|pedantic |`boolean` |`false` |v0.2.1 |If true, conform to the original `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Turns off and overrides `gfm`.|
|renderer |`object` |`new Renderer()`|v0.3.0|An object containing functions to render tokens to HTML. See [extensibility](/#/USING_PRO.md) for more details.|
|renderer |`object` |`new Renderer()`|v0.3.0|An object containing functions to render tokens to HTML. See [extensibility](/using_pro) for more details.|
|sanitize |`boolean` |`false` |v0.2.1 |If true, sanitize the HTML passed into `markdownString` with the `sanitizer` function.<br>**Warning**: This feature is deprecated and it should NOT be used as it cannot be considered secure.<br>Instead use a sanitize library, like [DOMPurify](https://github.com/cure53/DOMPurify) (recommended), [sanitize-html](https://github.com/apostrophecms/sanitize-html) or [insane](https://github.com/bevacqua/insane) on the output HTML! |
|sanitizer |`function`|`null` |v0.3.4 |A function to sanitize the HTML passed into `markdownString`.|
|silent |`boolean` |`false` |v0.2.7 |If true, the parser does not throw any exception.|
|smartLists |`boolean` |`false` |v0.2.8 |If true, use smarter list behavior than those found in `markdown.pl`.|
|smartypants |`boolean` |`false` |v0.2.9 |If true, use "smart" typographic punctuation for things like quotes and dashes.|
|tokenizer |`object` |`new Tokenizer()`|v1.0.0|An object containing functions to create tokens from markdown. See [extensibility](/#/USING_PRO.md) for more details.|
|walkTokens |`function` |`null`|v1.1.0|A function which is called for every token. See [extensibility](/#/USING_PRO.md) for more details.|
|tokenizer |`object` |`new Tokenizer()`|v1.0.0|An object containing functions to create tokens from markdown. See [extensibility](/using_pro) for more details.|
|walkTokens |`function` |`null`|v1.1.0|A function which is called for every token. See [extensibility](/using_pro) for more details.|
|xhtml |`boolean` |`false` |v0.3.2 |If true, emit self-closing HTML tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.) with a "/" as required by XHTML.|

<h2 id="highlight">Asynchronous highlighting</h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/USING_PRO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To champion the single-responsibility and open/closed principles, we have tried

<h2 id="use">marked.use()</h2>

`marked.use(options)` is the recommended way to extend marked. The options object can contain any [option](#/USING_ADVANCED.md#options) available in marked.
`marked.use(options)` is the recommended way to extend marked. The options object can contain any [option](/using_advanced#options) available in marked.

The `renderer` and `tokenizer` options can be an object with functions that will be merged into the `renderer` and `tokenizer` respectively.

Expand Down
101 changes: 101 additions & 0 deletions docs/_document.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title><!--{{title}}-->Marked Documentation</title>
<link rel="stylesheet" href="/css/style.css" type="text/css" />
<link rel="stylesheet" href="/css/hljs-github.css" type="text/css" />
</head>
<body>
<a href="https://github.com/markedjs/marked" class="github-corner" aria-label="View source on Github">
<svg width="80" height="80" viewBox="0 0 250 250" style="fill:#202020; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path>
</svg>
</a>
<div id="container">
<header>
<a href="/">
<img alt="logo" src="/img/logo-black.svg" height="50px" width="50px" />
</a>
<h1>Marked Documentation</h1>
</header>
<div style="display: flex">
<nav>
<ul>
<li>
<a href="/">Getting Started</a>
<ul>
<li><a href="/#demo">Demo</a></li>
<li><a href="/#installation">Installation</a></li>
<li><a href="/#usage">Usage</a></li>
<li><a href="/#specifications">Specs</a></li>
<li><a href="/#security">Security</a></li>
</ul>
</li>
<li>
<a href="/using_advanced">Advanced Usage</a>
<ul>
<li><a href="/using_advanced#options">Options</a></li>
<li><a href="/using_advanced#highlight">Highlighting</a></li>
<li><a href="/using_advanced#workers">Workers</a></li>
</ul>
</li>
<li>
<a href="/using_pro">Extensibility</a>
<ul>
<li><a href="/using_pro#use">marked.use()</a></li>
<li><a href="/using_pro#renderer">Renderer</a></li>
<li><a href="/using_pro#tokenizer">Tokenizer</a></li>
<li><a href="/using_pro#walk-tokens">Walk Tokens</a></li>
<li><a href="/using_pro#lexer">Lexer</a></li>
<li><a href="/using_pro#parser">Parser</a></li>
</ul>
</li>
<li>
<a href="/contributing">Contributing</a>
<ul>
<li><a href="/contributing#design-principles">Design Principles</a></li>
<li><a href="/contributing#priorities">Priorities</a></li>
<li><a href="/contributing#test-early-often-and-everything">Testing</a></li>
</ul>
</li>
<li><a href="/code_of_conduct">Code of Conduct</a></li>
<li><a href="/authors">Authors</a></li>
<li><a href="/publishing">Publishing</a></li>
<li><a href="/license">License</a></li>
</ul>
</nav>
<div id="content"><!--{{content}}--></div>
</div>
</div>
<script>
var match = new RegExp('#/(.+)\.md(.*)', 'g').exec(window.location.hash);
if (match && match[1]) {
// Redirect from URL format to new URL, for example:
// Old: https://marked.js.org/#/USING_PRO.md#renderer
// New: https://marked.js.org/using_pro#renderer
var pageName = match[1].toLowerCase();
var sectionName = match[2];
window.location.href = '/' + pageName + sectionName;
}

var navLinks = document.querySelectorAll('nav a');

function hashChange() {
var fullUrl = window.location.href;
navLinks.forEach(function(link) {
link.className = link.href === fullUrl ? 'selected' : '';
});
}

window.addEventListener('hashchange', function (e) {
e.preventDefault();
hashChange();
});

hashChange();
</script>
</body>
</html>
99 changes: 99 additions & 0 deletions docs/css/hljs-github.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*

github.com style (c) Vasily Polovnyov <vast@whiteants.net>

*/

pre {
display: block;
overflow-x: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
}

.hljs-comment,
.hljs-quote {
color: #998;
font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-subst {
color: #333;
font-weight: bold;
}

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
color: #008080;
}

.hljs-string,
.hljs-doctag {
color: #d14;
}

.hljs-title,
.hljs-section,
.hljs-selector-id {
color: #900;
font-weight: bold;
}

.hljs-subst {
font-weight: normal;
}

.hljs-type,
.hljs-class .hljs-title {
color: #458;
font-weight: bold;
}

.hljs-tag,
.hljs-name,
.hljs-attribute {
color: #000080;
font-weight: normal;
}

.hljs-regexp,
.hljs-link {
color: #009926;
}

.hljs-symbol,
.hljs-bullet {
color: #990073;
}

.hljs-built_in,
.hljs-builtin-name {
color: #0086b3;
}

.hljs-meta {
color: #999;
font-weight: bold;
}

.hljs-deletion {
background: #fdd;
}

.hljs-addition {
background: #dfd;
}

.hljs-emphasis {
font-style: italic;
}

.hljs-strong {
font-weight: bold;
}
Loading