Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable heading IDs #1190

Merged
merged 15 commits into from
Apr 3, 2018
31 changes: 19 additions & 12 deletions docs/USING_ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@ console.log(myMarked('I am using __markdown__.'));

<h2 id="options">Options</h2>

|Member |Type |Notes |
|:----------|:---------|:----------------------------------------------------------------------------------------------------------------------------|
|highlight |`function`|A function to highlight code blocks. See also: <a href="#highlight">Asynchronous highlighting</a>.|
|renderer |`object` |An object containing functions to render tokens to HTML. See [extensibility](https://github.com/markedjs/marked/blob/master/docs/USING_PRO.md) for more details. Default: `new Renderer()`.|
|pedantic |`boolean` |Conform to obscure parts of `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Default: `false`.|
|gfm |`boolean` |Use approved [GitHub Flavored Markdown (GFM) specification](https://github.github.com/gfm/). Default: `true`.|
|tables |`boolean` |Use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-). Requires `gfm` be `true`. Default: `true`.|
|breaks |`boolean` |Use GFM [hard](https://github.github.com/gfm/#hard-line-breaks) and [soft](https://github.github.com/gfm/#soft-line-breaks) line breaks. Requires `gfm` be `true`. Default: `false`.|
|sanitize |`boolean` |Ignore HTML passed into `markdownString` (sanitize the input). Default: `false`.|
|smartlists |`boolean` |Use smarter list behavior than those found in `markdown.pl`. Default: `true`.|
|smartypants|`boolean` |Use "smart" typographic punctuation for things like quotes and dashes. Default: `false`.|
|xhtml |`boolean` |Self-close the tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.) with a "/" as required by XHTML. Default: `false`.|
|Member |Type |Notes |
|:-----------|:---------|:----------------------------------------------------------------------------------------------------------------------------|
|baseUrl |`??` |Default is `null` |
|breaks |`boolean` |Use GFM [hard](https://github.github.com/gfm/#hard-line-breaks) and [soft](https://github.github.com/gfm/#soft-line-breaks) line breaks. Requires `gfm` be `true`. Default: `false`|
|gfm |`boolean` |Use approved [GitHub Flavored Markdown (GFM) specification](https://github.github.com/gfm/). |
|headerIds |`boolean` |Whether to add an `id` attribute to headers. Default: `true` |
|headerPrefix|`string` |A short string to add as a prefix to the `id` attributes added to headers by default. Default: `empty string` |
|highlight |`function`|A function to highlight code blocks. See also: <a href="#highlight">Asynchronous highlighting</a>. |
|langPrefix |`??` |Default is `lang-`
|mangle |`boolean` |Default is `true`
|pedantic |`boolean` |Conform to obscure parts of `markdown.pl` as much as possible. Don't fix original markdown bugs or behavior. Default: `false`|
|renderer |`object` |An object containing functions to render tokens to HTML. See [extensibility](https://github.com/markedjs/marked/blob/master/docs/USING_PRO.md) for more details. Default: `new Renderer()`|
|sanitize |`boolean` |Ignore HTML passed into `markdownString` (sanitize the input). Default: `false` |
|sanitizer |`??` |Default is `null` |
|silent |`boolean` |Default is `false` |
|smartlists |`boolean` |Use smarter list behavior than those found in `markdown.pl`. Default: `true` |
|smartypants |`boolean` |Use "smart" typographic punctuation for things like quotes and dashes. |
|tables |`boolean` |Use [GFM Tables extension](https://github.github.com/gfm/#tables-extension-). Requires `gfm` be `true`. |
|xhtml |`boolean` |Self-close the tags for void elements (&lt;br/&gt;, &lt;img/&gt;, etc.) with a "/" as required by XHTML. Default: `false` |

<h2 id="highlight">Asynchronous highlighting</h2>

Expand Down
45 changes: 25 additions & 20 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,16 +823,20 @@ Renderer.prototype.html = function(html) {
};

Renderer.prototype.heading = function(text, level, raw) {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ text
+ '</h'
+ level
+ '>\n';
if (this.options.headerIds) {
return '<h'
+ level
+ ' id="'
+ this.options.headerPrefix
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ text
+ '</h'
+ level
+ '>\n';
}
// ignore IDs
return '<h' + level + '>' + text + '</h' + level + '>\n';
};

Renderer.prototype.hr = function() {
Expand Down Expand Up @@ -1342,22 +1346,23 @@ marked.setOptions = function(opt) {
};

marked.defaults = {
gfm: true,
tables: true,
baseUrl: null,
breaks: false,
gfm: true,
headerPrefix: '',
headerIds: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'I' comes before 'P'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch...funny enough, I got it right in the table. :)

highlight: null,
langPrefix: 'lang-',
mangle: true,
pedantic: false,
renderer: new Renderer(),
sanitize: false,
sanitizer: null,
mangle: true,
smartLists: false,
silent: false,
highlight: null,
langPrefix: 'lang-',
smartLists: false,
smartypants: false,
headerPrefix: '',
renderer: new Renderer(),
xhtml: false,
baseUrl: null
tables: true,
xhtml: false
};

/**
Expand Down
2 changes: 1 addition & 1 deletion marked.min.js

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"eslint-plugin-standard": "^3.0.1",
"front-matter": "^2.3.0",
"glob-to-regexp": "0.3.0",
"html-differ": "^1.3.4",
"jasmine": "^3.1.0",
"jasmine2-custom-message": "^0.9.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are not needed for this PR

"markdown": "*",
"markdown-it": "*",
"showdown": "*",
Expand Down
5 changes: 4 additions & 1 deletion test/integration/marked-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var marked = require('../../marked.min.js');
var HtmlDiffer = require('html-differ').HtmlDiffer,
htmlDiffer = new HtmlDiffer();
var since = require('jasmine2-custom-message');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not needed


it('should run the test', function () {
expect(marked('Hello World!')).toBe('<p>Hello World!</p>\n');
Expand All @@ -15,4 +18,4 @@ it('should start an ordered list at 0 when requested', function () {
it('indents code within an explicitly-started ordered list', function () {
expect(marked(" 10. foo\n\n bar")).
toBe("<ol start=\"10\">\n<li><p>foo</p>\n<pre><code>bar\n</code></pre></li>\n</ol>\n");
});
});
Loading