Skip to content
Commits on Source (8)
root = true
[*.{json,js}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
[*.md, !test/*.md]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
\ No newline at end of file
{
"extends": "standard",
"plugins": [
"standard"
],
"parserOptions": { "ecmaVersion": 5 },
"rules": {
"semi": "off",
"indent": ["warn", 2, {
"VariableDeclarator": { "var": 2 },
"SwitchCase": 1,
"outerIIFEBody": 0
}],
"space-before-function-paren": "off",
"operator-linebreak": ["error", "before", { "overrides": { "=": "after" } }],
"no-cond-assign": "off",
"no-useless-escape": "off",
"no-return-assign": "off",
"one-var": "off",
"no-control-regex": "off"
},
"env": {
"node": true,
"browser": true,
"amd": true,
"jasmine": true
}
}
test/* linguist-vendored
**Marked version:**
**Markdown flavor:** Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a
<!-- The NPM version or commit hash having the issue -->
<!--
If submitting something other than a defect with Marked itself, please use the following:
**Proposal type:** new feature | project operations | other
## What pain point are you perceiving?
## What solution are you suggesting?
-->
## Expectation
**CommonMark Demo:** [demo](https://spec.commonmark.org/dingus/)
<!-- You can replace the link above with a permalink from: https://spec.commonmark.org/dingus/ -->
<!-- Describe the output you are expecting from marked -->
## Result
**Marked Demo:** [demo](https://marked.js.org/demo/)
<!-- You can replace the link above with a permalink from: https://marked.js.org/demo/ -->
<!-- Describe the output you received from marked -->
## What was attempted
<!-- Describe what code combination got you there -->
<!--
If error is thrown add the following:
## Call stack & console log
-->
---
name: Bug report
about: Marked says it does this thing but does not
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
<!-- If possible, use the Marked Demo permalink and compare to the CommonMark Dingus permalink to demonstrate the bug -->
<!--
1. [Marked Demo](https://marked.js.org/demo/)
2. [CommonMark Demo](https://spec.commonmark.org/dingus/)
-->
<!-- If you need a specific version and options to reproduce the bug, use the following template -->
<!--
1. Install marked `npm install --save marked@0.3.19` with the version you are using
2. Run marked with input string and options such as `marked('hello *world*', {gfm: true})`
3. Actual output (or error) is...
-->
**Expected behavior**
A clear and concise description of what you expected to happen.
---
name: Feature request
about: Marked doesn't do this thing and I think it should
---
**Describe the feature**
A clear and concise description of what you would like.
**Why is this feature necessary?**
A clear and concise description of why.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
---
name: Proposal
about: Marked doesn't do this thing and I think it should
---
**What pain point are you perceiving?.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
<!--
If release PR, add ?template=release.md to the PR url to use the release PR template.
If badging PR, add ?template=badges.md to the PR url to use the badges PR template.
Otherwise, you are stating this PR fixes an issue that has been submitted; or,
describes the issue or proposal under consideration and contains the project-related code to implement.
-->
**Marked version:**
<!-- The NPM version or commit hash having the issue -->
**Markdown flavor:** Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a
## Description
- Fixes #### (if fixing a known issue; otherwise, describe issue using the following format)
<!--
If no issue exists that you're aware of. The maintainers should be able to figure out if it's a duplicate.
## Expectation
Describe the output you are expecting from marked
## Result
Describe the output you received from marked
## What was attempted
Describe what code combination got you there
-->
## Contributor
- [ ] Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
- [ ] no tests required for this PR.
- [ ] If submitting new feature, it has been documented in the appropriate places.
## Committer
In most cases, this should be a different person than the contributor.
- [ ] Draft GitHub release notes have been updated.
- [ ] CI is green (no forced merge required).
- [ ] Merge PR
**@mention the contributor:**
## Recommendation to:
- [ ] Change user group
- [ ] Add a badge
- [ ] Remove a badge
<!--
Explain your reasoning behind tagging that person.
Preferably by citing objective examples, like PRs, Issues, and so on.
-->
## As the one mentioned, I would like to:
- [ ] accept the recommendation; or,
- [ ] graciously decline; or,
- [ ] dispute the recommendation
within 30 days, if you have not indicated which option you are taking one of the following will happen:
1. If adding a badge, we will assume you are graciously declining.
2. If removing a badge, we will assume you do not want to dispute the recommendation; therefore, the badge will be removed.
<!--
Why would someone not accept a badge? Loads of reasons depending on the circumstances.
1. If you're a committer and someone puts a badge for you on having decision making authority in an area, do you really a) think you earned it and b) think you can do that *and* all the other stuff you got going as a committer, admin, or publisher (not to even mention your outside life)? Maybe not. And that's okay. Thank them for the recognition, explain you aren't able to take more on at the moment. It's cool to get recognized though.
2. Maybe you don't feel you actually earned it yet. I remember being in an interview once. The interviewer asked me to give an example of going above and beyond the call of duty. I said, "That's hard. Because what you consider going above and beyond may be what I consider to be 'just rising to'. If we're in battle and you get wounded and I pull you out of the frey before heading back into it, I don't consider that going above and beyond; I consider that rising to."
Why would someone remove their own badge? Loads of reasons...
1. Maybe you got a lot going on right now and want to broadcast to the Marked community that, "Hey, I don't want to say I'm going to do this unless I can really commit to it right now in a way that serves the project well." That's awesome! That takes courage! Because a) saying "no" is hard for most humans ("people pleasers") and b) the alternative, well, for those of us here since about October of 2017 (and prior), we know what the alternative can look like.
2. Maybe you just think you've done all you can to help and learned all you can from the experience. Again, very awesome and courageous. It takes courage to know when to walk away on your own accord.
Why would you want to remove someone's badge? Loads of reasons...
1. Maybe they have decision making authority on something. You asked for their advice. And, you ended up waiting almost a month before receiving a response.
2. Maybe it was relevant at the time (Master of Marked, for example) but you think they've lost their former level of skill (fell out of practice, for example). They could always get it back.
3. Maybe to signal to them that, "Hey, you seem to have forgotten about us. Are you still around (or alive)?"
Anyway, you get the idea. This isn't about good or bad...it's just about giving the community a simple game mechanic by which to publicly say, "Thank you" or "Here's what my status is" in the community or "Hey, I think something's wrong here" in a civil manner.
-->
Note: All committers must approve via review before merging, the disapproving committer can simply close the PR.
\ No newline at end of file
## Publisher
- [ ] `$ npm version` has been run.
- [ ] Release notes in [draft GitHub release](https://github.com/markedjs/marked/releases) are up to date
- [ ] Release notes include which flavors and versions of Markdown are supported by this release
- [ ] Committer checklist is complete.
- [ ] Merge PR.
- [ ] Publish GitHub release using `master` with correct version number.
- [ ] `$ npm publish` has been run.
- [ ] Create draft GitHub release to prepare next release.
Note: If merges to `master` occur after submitting this PR and before running `$ npm pubish` you should be able to
1. pull from `upstream/master` (`git pull upstream master`) into the branch holding this version,
2. run `$ npm run build` to regenerate the `min` file, and
3. commit and push the updated changes.
## Committer
In most cases, this should be someone different than the publisher.
- [ ] Version in `package.json` has been updated (see [PUBLISHING.md](https://github.com/markedjs/marked/blob/master/docs/PUBLISHING.md)).
- [ ] The `marked.min.js` has been updated; or,
- [ ] release does not change library.
- [ ] CI is green (no forced merge required).
.DS_Store
node_modules/
test/compiled_tests
.git*
test/
docs
\ No newline at end of file
language: node_js
node_js:
- "0.10"
- "0.8"
- "0.6"
jobs:
fast_finish: true
allow_failures:
- stage: security scan 🔐
include:
- stage: unit tests 👩🏽‍💻
script: npm run test:unit
node_js: lts/*
- stage: spec tests 👩🏽‍💻
script: npm run test:specs
node_js: v0.10
- node_js: v4
- node_js: lts/*
- node_js: node
- stage: lint ✨
script: npm run test:lint
node_js: lts/*
- stage: minify 🗜️
script: |
npm run build
if ! git diff --quiet; then
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis-CI"
git config credential.helper "store --file=.git/credentials"
echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials
git commit -am '🗜️ minify [skip ci]'
git push origin HEAD:${TRAVIS_BRANCH}
fi
node_js: lts/*
if: branch = master AND type = push
- stage: security scan 🔐
script: npm run test:redos
node_js: lts/*
cache:
directories:
- node_modules
git:
depth: 3
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var preserveFirstComment = function() {
var set = false;
return function() {
if (set) return false;
set = true;
return true;
};
};
gulp.task('uglify', function() {
gulp.src('lib/marked.js')
.pipe(uglify({preserveComments: preserveFirstComment()}))
.pipe(concat('marked.min.js'))
.pipe(gulp.dest('.'));
});
gulp.task('default', ['uglify']);
......@@ -9,4 +9,7 @@ clean:
bench:
@node test --bench
man/marked.1.txt:
groff -man -Tascii man/marked.1 | col -b > man/marked.1.txt
.PHONY: clean all
# marked
<a href="https://marked.js.org">
<img width="60px" height="60px" src="https://marked.js.org/img/logo-black.svg" align="right" />
</a>
> A full-featured markdown parser and compiler, written in JavaScript. Built
> for speed.
# Marked
[![NPM version](https://badge.fury.io/js/marked.png)][badge]
[![npm](https://badgen.net/npm/v/marked)](https://www.npmjs.com/package/marked)
[![gzip size](https://badgen.net/badgesize/gzip/https://cdn.jsdelivr.net/npm/marked/marked.min.js)](https://cdn.jsdelivr.net/npm/marked/marked.min.js)
[![install size](https://badgen.net/packagephobia/install/marked)](https://packagephobia.now.sh/result?p=marked)
[![downloads](https://badgen.net/npm/dt/marked)](https://www.npmjs.com/package/marked)
[![dep](https://badgen.net/david/dep/markedjs/marked)](https://david-dm.org/markedjs/marked)
[![dev dep](https://badgen.net/david/dev/markedjs/marked)](https://david-dm.org/markedjs/marked?type=dev)
[![travis](https://badgen.net/travis/markedjs/marked)](https://travis-ci.org/markedjs/marked)
## Install
- ⚡ built for speed
- ⬇️ low-level compiler for parsing markdown without caching or blocking for long periods of time
- ⚖️ light-weight while implementing all markdown features from the supported flavors & specifications
- 🌐 works in a browser, on a server, or from a command line interface (CLI)
``` bash
npm install marked --save
```
## Demo
## Usage
Checkout the [demo page](https://marked.js.org/demo/) to see marked in action ⛹️
Minimal usage:
## Docs
```js
var marked = require('marked');
console.log(marked('I am using __markdown__.'));
// Outputs: <p>I am using <strong>markdown</strong>.</p>
```
Our [documentation pages](https://marked.js.org) are also rendered using marked 💯
Also read about:
* [Options](https://marked.js.org/#/USING_ADVANCED.md)
* [Extensibility](https://marked.js.org/#/USING_PRO.md)
## Installation
**CLI:** `npm install -g marked`
Example setting options with default values:
**In-browser:** `npm install marked --save`
```js
var marked = require('marked');
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
## Usage
### Warning: 🚨 Marked does not [sanitize](https://marked.js.org/#/USING_ADVANCED.md#options) the output HTML by default 🚨
**CLI**
console.log(marked('I am using __markdown__.'));
``` bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```
### Browser
**Browser**
```html
<!doctype html>
......@@ -47,360 +58,18 @@ console.log(marked('I am using __markdown__.'));
<head>
<meta charset="utf-8"/>
<title>Marked in the browser</title>
<script src="lib/marked.js"></script>
</head>
<body>
<div id="content"></div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
document.getElementById('content').innerHTML =
marked('# Marked in browser\n\nRendered by **marked**.');
marked('# Marked in the browser\n\nRendered by **marked**.');
</script>
</body>
</html>
```
## marked(markdownString [,options] [,callback])
### markdownString
Type: `string`
String of markdown source to be compiled.
### options
Type: `object`
Hash of options. Can also be set using the `marked.setOptions` method as seen
above.
### callback
Type: `function`
Function called when the `markdownString` has been fully parsed when using
async highlighting. If the `options` argument is omitted, this can be used as
the second argument.
## Options
### highlight
Type: `function`
A function to highlight code blocks. The first example below uses async highlighting with
[node-pygmentize-bundled][pygmentize], and the second is a synchronous example using
[highlight.js][highlight]:
```js
var marked = require('marked');
var markdownString = '```js\n console.log("hello"); \n```';
// Async highlighting with pygmentize-bundled
marked.setOptions({
highlight: function (code, lang, callback) {
require('pygmentize-bundled')({ lang: lang, format: 'html' }, code, function (err, result) {
callback(err, result.toString());
});
}
});
// Using async version of marked
marked(markdownString, function (err, content) {
if (err) throw err;
console.log(content);
});
// Synchronous highlighting with highlight.js
marked.setOptions({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
});
console.log(marked(markdownString));
```
#### highlight arguments
`code`
Type: `string`
The section of code to pass to the highlighter.
`lang`
Type: `string`
The programming language specified in the code block.
`callback`
Type: `function`
The callback function to call when using an async highlighter.
### renderer
Type: `object`
Default: `new Renderer()`
An object containing functions to render tokens to HTML.
#### Overriding renderer methods
The renderer option allows you to render tokens in a custom manner. Here is an
example of overriding the default heading token rendering by adding an embedded anchor tag like on GitHub:
```javascript
var marked = require('marked');
var renderer = new marked.Renderer();
renderer.heading = function (text, level) {
var escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
return '<h' + level + '><a name="' +
escapedText +
'" class="anchor" href="#' +
escapedText +
'"><span class="header-link"></span></a>' +
text + '</h' + level + '>';
},
console.log(marked('# heading+', { renderer: renderer }));
```
This code will output the following HTML:
```html
<h1>
<a name="heading-" class="anchor" href="#heading-">
<span class="header-link"></span>
</a>
heading+
</h1>
```
#### Block level renderer methods
- code(*string* code, *string* language)
- blockquote(*string* quote)
- html(*string* html)
- heading(*string* text, *number* level)
- hr()
- list(*string* body, *boolean* ordered)
- listitem(*string* text)
- paragraph(*string* text)
- table(*string* header, *string* body)
- tablerow(*string* content)
- tablecell(*string* content, *object* flags)
`flags` has the following properties:
```js
{
header: true || false,
align: 'center' || 'left' || 'right'
}
```
#### Inline level renderer methods
- strong(*string* text)
- em(*string* text)
- codespan(*string* code)
- br()
- del(*string* text)
- link(*string* href, *string* title, *string* text)
- image(*string* href, *string* title, *string* text)
### gfm
Type: `boolean`
Default: `true`
Enable [GitHub flavored markdown][gfm].
### tables
Type: `boolean`
Default: `true`
Enable GFM [tables][tables].
This option requires the `gfm` option to be true.
### breaks
Type: `boolean`
Default: `false`
Enable GFM [line breaks][breaks].
This option requires the `gfm` option to be true.
### pedantic
Type: `boolean`
Default: `false`
Conform to obscure parts of `markdown.pl` as much as possible. Don't fix any of
the original markdown bugs or poor behavior.
### sanitize
Type: `boolean`
Default: `false`
Sanitize the output. Ignore any HTML that has been input.
### smartLists
Type: `boolean`
Default: `true`
Use smarter list behavior than the original markdown. May eventually be
default with the old behavior moved into `pedantic`.
### smartypants
Type: `boolean`
Default: `false`
Use "smart" typographic punctuation for things like quotes and dashes.
## Access to lexer and parser
You also have direct access to the lexer and parser if you so desire.
``` js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```
``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```
## CLI
``` bash
$ marked -o hello.html
hello world
^D
$ cat hello.html
<p>hello world</p>
```
## Philosophy behind marked
The point of marked was to create a markdown compiler where it was possible to
frequently parse huge chunks of markdown without having to worry about
caching the compiled output somehow...or blocking for an unnecessarily long time.
marked is very concise and still implements all markdown features. It is also
now fully compatible with the client-side.
marked more or less passes the official markdown test suite in its
entirety. This is important because a surprising number of markdown compilers
cannot pass more than a few tests. It was very difficult to get marked as
compliant as it is. It could have cut corners in several areas for the sake
of performance, but did not in order to be exactly what you expect in terms
of a markdown rendering. In fact, this is why marked could be considered at a
disadvantage in the benchmarks above.
Along with implementing every markdown feature, marked also implements [GFM
features][gfmf].
## Benchmarks
node v0.8.x
``` bash
$ node test --bench
marked completed in 3411ms.
marked (gfm) completed in 3727ms.
marked (pedantic) completed in 3201ms.
robotskirt completed in 808ms.
showdown (reuse converter) completed in 11954ms.
showdown (new converter) completed in 17774ms.
markdown-js completed in 17191ms.
```
__Marked is now faster than Discount, which is written in C.__
For those feeling skeptical: These benchmarks run the entire markdown test suite 1000 times. The test suite tests every feature. It doesn't cater to specific aspects.
### Pro level
You also have direct access to the lexer and parser if you so desire.
``` js
var tokens = marked.lexer(text, options);
console.log(marked.parser(tokens));
```
``` js
var lexer = new marked.Lexer(options);
var tokens = lexer.lex(text);
console.log(tokens);
console.log(lexer.rules);
```
``` bash
$ node
> require('marked').lexer('> i am using marked.')
[ { type: 'blockquote_start' },
{ type: 'paragraph',
text: 'i am using marked.' },
{ type: 'blockquote_end' },
links: {} ]
```
## Running Tests & Contributing
If you want to submit a pull request, make sure your changes pass the test
suite. If you're adding a new feature, be sure to add your own test.
The marked test suite is set up slightly strangely: `test/new` is for all tests
that are not part of the original markdown.pl test suite (this is where your
test should go if you make one). `test/original` is only for the original
markdown.pl tests. `test/tests` houses both types of tests after they have been
combined and moved/generated by running `node test --fix` or `marked --test
--fix`.
In other words, if you have a test to add, add it to `test/new/` and then
regenerate the tests with `node test --fix`. Commit the result. If your test
uses a certain feature, for example, maybe it assumes GFM is *not* enabled, you
can add `.nogfm` to the filename. So, `my-test.text` becomes
`my-test.nogfm.text`. You can do this with any marked option. Say you want
line breaks and smartypants enabled, your filename should be:
`my-test.breaks.smartypants.text`.
To run the tests:
``` bash
cd marked/
node test
```
### Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`
## License
Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
See LICENSE for more info.
[gfm]: https://help.github.com/articles/github-flavored-markdown
[gfmf]: http://github.github.com/github-flavored-markdown/
[pygmentize]: https://github.com/rvagg/node-pygmentize-bundled
[highlight]: https://github.com/isagalaev/highlight.js
[badge]: http://badge.fury.io/js/marked
[tables]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#wiki-tables
[breaks]: https://help.github.com/articles/github-flavored-markdown#newlines
Copyright (c) 2011-2018, Christopher Jeffrey. (MIT License)
......@@ -5,9 +5,9 @@
* Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
*/
var fs = require('fs')
, util = require('util')
, marked = require('../');
var fs = require('fs'),
path = require('path'),
marked = require('../');
/**
* Man Page
......@@ -20,12 +20,16 @@ function help() {
cwd: process.cwd(),
env: process.env,
setsid: false,
customFds: [0, 1, 2]
stdio: 'inherit'
};
spawn('man',
[__dirname + '/../man/marked.1'],
options);
spawn('man', [path.resolve(__dirname, '/../man/marked.1')], options)
.on('error', function() {
fs.readFile(path.resolve(__dirname, '/../man/marked.1.txt'), 'utf8', function(err, data) {
if (err) throw err;
console.log(data);
});
});
}
/**
......@@ -33,13 +37,14 @@ function help() {
*/
function main(argv, callback) {
var files = []
, options = {}
, input
, output
, arg
, tokens
, opt;
var files = [],
options = {},
input,
output,
string,
arg,
tokens,
opt;
function getarg() {
var arg = argv.shift();
......@@ -82,6 +87,10 @@ function main(argv, callback) {
case '--input':
input = argv.shift();
break;
case '-s':
case '--string':
string = argv.shift();
break;
case '-t':
case '--tokens':
tokens = true;
......@@ -114,6 +123,9 @@ function main(argv, callback) {
function getData(callback) {
if (!input) {
if (files.length <= 2) {
if (string) {
return callback(null, string);
}
return getStdin(callback);
}
input = files.pop();
......@@ -142,8 +154,8 @@ function main(argv, callback) {
*/
function getStdin(callback) {
var stdin = process.stdin
, buff = '';
var stdin = process.stdin,
buff = '';
stdin.setEncoding('utf8');
......
{
"name": "marked",
"homepage": "https://github.com/chjj/marked",
"homepage": "https://github.com/markedjs/marked",
"authors": [
"Christopher Jeffrey <chjjeffrey@gmail.com>"
],
......
{
"name": "marked",
"version": "0.3.4",
"repo": "chjj/marked",
"repo": "markedjs/marked",
"description": "A markdown parser built for speed",
"keywords": ["markdown", "markup", "html"],
"scripts": ["lib/marked.js"],
......