Skip to content

Commit b1d8f6e

Browse files
committed
ALso sanitize dots and parenthesises for slug generation
1 parent feacb99 commit b1d8f6e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

platform/lib/samples/CodeSection.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,13 @@ module.exports = class CodeSection {
271271
return;
272272
}
273273
const name = matches[1].trim().replace(/`/g, '');
274+
let id = name.toLowerCase();
275+
id = id.replace(/\s+/g, '-');
276+
id = id.replace(/\./g, '-');
277+
id = id.replace(/[\(\)]/g, '');
274278
const heading = {
275-
id: name.toLowerCase().replace(/\s+/g, '-'),
276-
name: name,
279+
id,
280+
name,
277281
};
278282
this.headings.push(heading);
279283
}

platform/lib/samples/CodeSection.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ describe('CodeSection', () => {
184184
},
185185
]);
186186
});
187+
it('escapes the heading', () => {
188+
section.appendDoc('##Some Doc amp.getState()');
189+
expect(section.headings).toEqual([
190+
{
191+
id: 'some-doc-amp-getstate',
192+
name: 'Some Doc amp.getState()',
193+
},
194+
]);
195+
});
187196
it('adds multiple headings', () => {
188197
section.appendDoc('##Some Doc');
189198
section.appendDoc('##Another Doc');

0 commit comments

Comments
 (0)