Skip to content

Commit

Permalink
remove all non-word characters from heading id's. see markedjs#181.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 4, 2013
1 parent 327f07b commit 25a4531
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ Parser.prototype.tok = function() {
return '<h'
+ this.token.depth
+ ' id="'
+ this.token.text.toLowerCase().replace(/\s/g, '-')
+ this.token.text.toLowerCase().replace(/[^\w]+/g, '-')
+ '">'
+ this.inline.output(this.token.text)
+ '</h'
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function fix(options) {
.replace(/&lt;/g, '<')
.replace(/&amp;/g, '&');

id = id.toLowerCase().replace(/\s/g, '-');
id = id.toLowerCase().replace(/[^\w]+/g, '-');

return '<' + h + ' id="' + id + '">' + text + '</' + h + '>';
});
Expand Down
6 changes: 3 additions & 3 deletions test/tests/markdown_documentation_basics.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 id="markdown:-basics">Markdown: Basics</h1>
<h1 id="markdown-basics">Markdown: Basics</h1>

<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
Expand All @@ -8,7 +8,7 @@ <h1 id="markdown:-basics">Markdown: Basics</h1>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul>

<h2 id="getting-the-gist-of-markdown's-formatting-syntax">Getting the Gist of Markdown&#39;s Formatting Syntax</h2>
<h2 id="getting-the-gist-of-markdown-s-formatting-syntax">Getting the Gist of Markdown&#39;s Formatting Syntax</h2>

<p>This page offers a brief overview of what it&#39;s like to use Markdown.
The <a href="/projects/markdown/syntax" title="Markdown Syntax">syntax page</a> provides complete, detailed documentation for
Expand All @@ -24,7 +24,7 @@ <h2 id="getting-the-gist-of-markdown's-formatting-syntax">Getting the Gist of Ma
<p><strong>Note:</strong> This document is itself written using Markdown; you
can <a href="/projects/markdown/basics.text">see the source for it by adding &#39;.text&#39; to the URL</a>.</p>

<h2 id="paragraphs,-headers,-blockquotes">Paragraphs, Headers, Blockquotes</h2>
<h2 id="paragraphs-headers-blockquotes">Paragraphs, Headers, Blockquotes</h2>

<p>A paragraph is simply one or more consecutive lines of text, separated
by one or more blank lines. (A blank line is any line that looks like a
Expand Down
2 changes: 1 addition & 1 deletion test/tests/markdown_documentation_syntax.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1 id="markdown:-syntax">Markdown: Syntax</h1>
<h1 id="markdown-syntax">Markdown: Syntax</h1>

<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
Expand Down

0 comments on commit 25a4531

Please sign in to comment.