fix(v2): remove Markdown heading id from excerpt (#4862)

This commit is contained in:
Alexey Pyltsyn 2021-06-02 17:20:53 +03:00 committed by GitHub
parent d2e4e60cd5
commit 644f148a8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -121,6 +121,14 @@ describe('createExcerpt', () => {
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
); );
}); });
test('should create excerpt for heading specified with anchor-id syntax', () => {
expect(
createExcerpt(dedent`
## Markdown title {#my-anchor-id}
`),
).toEqual('Markdown title');
});
}); });
describe('parseMarkdownContentTitle', () => { describe('parseMarkdownContentTitle', () => {

View file

@ -55,6 +55,8 @@ export function createExcerpt(fileString: string): string | undefined {
.replace(/(:{3}.*)/, '') .replace(/(:{3}.*)/, '')
// Remove Emoji names within colons include preceding whitespace. // Remove Emoji names within colons include preceding whitespace.
.replace(/\s?(:(::|[^:\n])+:)/g, '') .replace(/\s?(:(::|[^:\n])+:)/g, '')
// Remove custom Markdown heading id.
.replace(/{#*[\w-]+}/, '')
.trim(); .trim();
if (cleanedLine) { if (cleanedLine) {