mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
fix(v2): strip images and footnotes for excerpt correctly (#2855)
This commit is contained in:
parent
af912f5a65
commit
1b2744570b
2 changed files with 19 additions and 5 deletions
|
@ -312,7 +312,7 @@ describe('load utils', () => {
|
||||||
import Component from '@site/src/components/Component';
|
import Component from '@site/src/components/Component';
|
||||||
import Component from '@site/src/components/Component'
|
import Component from '@site/src/components/Component'
|
||||||
|
|
||||||
Lorem **ipsum** dolor sit \`amet\`, consectetur _adipiscing_ elit. [**Vestibulum**](https://wiktionary.org/wiki/vestibulum) ex urna, ~molestie~ et sagittis ut, varius ac justo :wink:.
|
Lorem **ipsum** dolor sit \`amet\`[^1], consectetur _adipiscing_ elit. [**Vestibulum**](https://wiktionary.org/wiki/vestibulum) ex urna[^bignote], ~molestie~ et sagittis ut, varius ac justo :wink:.
|
||||||
|
|
||||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||||
`,
|
`,
|
||||||
|
@ -343,6 +343,20 @@ describe('load utils', () => {
|
||||||
`,
|
`,
|
||||||
output: 'Lorem ipsum dolor sit amet',
|
output: 'Lorem ipsum dolor sit amet',
|
||||||
},
|
},
|
||||||
|
// Content beginning with blockquote
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|
> Lorem ipsum dolor sit amet
|
||||||
|
`,
|
||||||
|
output: 'Lorem ipsum dolor sit amet',
|
||||||
|
},
|
||||||
|
// Content beginning with image (eg. blog post)
|
||||||
|
{
|
||||||
|
input: `
|
||||||
|

|
||||||
|
`,
|
||||||
|
output: 'Lorem ipsum',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
asserts.forEach((testCase) => {
|
asserts.forEach((testCase) => {
|
||||||
|
|
|
@ -204,16 +204,16 @@ export function createExcerpt(fileString: string): string | undefined {
|
||||||
.replace(/^\#{1,6}\s*([^#]*)\s*(\#{1,6})?/gm, '$1')
|
.replace(/^\#{1,6}\s*([^#]*)\s*(\#{1,6})?/gm, '$1')
|
||||||
// Remove emphasis and strikethroughs.
|
// Remove emphasis and strikethroughs.
|
||||||
.replace(/([\*_~]{1,3})(\S.*?\S{0,1})\1/g, '$2')
|
.replace(/([\*_~]{1,3})(\S.*?\S{0,1})\1/g, '$2')
|
||||||
|
// Remove images.
|
||||||
|
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
|
||||||
|
// Remove footnotes.
|
||||||
|
.replace(/\[\^.+?\](\: .*?$)?/g, '')
|
||||||
// Remove inline links.
|
// Remove inline links.
|
||||||
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
|
.replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1')
|
||||||
// Remove inline code.
|
// Remove inline code.
|
||||||
.replace(/`(.+?)`/g, '$1')
|
.replace(/`(.+?)`/g, '$1')
|
||||||
// Remove images.
|
|
||||||
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '')
|
|
||||||
// Remove blockquotes.
|
// Remove blockquotes.
|
||||||
.replace(/^\s{0,3}>\s?/g, '')
|
.replace(/^\s{0,3}>\s?/g, '')
|
||||||
// Remove footnotes.
|
|
||||||
.replace(/\[\^.+?\](\: .*?$)?/g, '')
|
|
||||||
// Remove admonition definition.
|
// Remove admonition definition.
|
||||||
.replace(/(:{3}.*)/, '')
|
.replace(/(:{3}.*)/, '')
|
||||||
// Remove Emoji names within colons include preceding whitespace.
|
// Remove Emoji names within colons include preceding whitespace.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue