Skip to content

Commit

Permalink
Fix problem with header id generation
Browse files Browse the repository at this point in the history
Header id generation should match the grow logic.
All characters but whitespace are allowed
See ampproject/amp.dev#1892
And grow/grow@62d0a6a#diff-506b8f06fee5ce1722a3c180ab3919b7
  • Loading branch information
tharders committed May 9, 2019
1 parent 76267b1 commit 7b747f6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/CodeSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const hljs = require('highlight.js');
const marked = require('marked');
const renderer = new marked.Renderer();
renderer.heading = function (text, level) {
const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-');
const escapedText = text.toLowerCase().replace(/\s+/g, '-');
return '<h' + level + ' id="' + escapedText +
'" class="www-heading pb4 mb2 relative h3">' + text + '</h' + level +
'>';
Expand Down Expand Up @@ -245,7 +245,7 @@ module.exports = class CodeSection {
}
const name = matches[1].trim().replace(/`/g, '');
const heading = {
id: name.toLowerCase().replace(/[^\w]+/g, '-'),
id: name.toLowerCase().replace(/\s+/g, '-'),
name: name
};
this.headings.push(heading);
Expand Down

0 comments on commit 7b747f6

Please sign in to comment.