mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 06:25:37 +00:00
Fix caption parsing
For #79704 - Use regexp - Handle unix line endings - Don't highlight caption as part of code block
This commit is contained in:
parent
9ab856b571
commit
8891b85518
1 changed files with 14 additions and 7 deletions
|
@ -11,19 +11,26 @@ function getTagBodyText(tag: Proto.JSDocTagInfo): string | undefined {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Convert to markdown code block if it is not already one
|
||||
function makeCodeblock(text: string): string {
|
||||
if (text.match(/^\s*[~`]{3}/g)) {
|
||||
return text;
|
||||
}
|
||||
return '```\n' + text + '\n```';
|
||||
}
|
||||
|
||||
switch (tag.name) {
|
||||
case 'example':
|
||||
// check for caption tags, fix for #79704
|
||||
const captionTagMatches = tag.text.match('<caption>(.*?)<\/caption>\r');
|
||||
const captionTagMatches = tag.text.match(/<caption>(.*?)<\/caption>\s*(\r\n|\n)/);
|
||||
if (captionTagMatches && captionTagMatches.index === 0) {
|
||||
tag.text = captionTagMatches[1] + '\r\r' + tag.text.substr(captionTagMatches[0].length);
|
||||
return captionTagMatches[1] + '\n\n' + makeCodeblock(tag.text.substr(captionTagMatches[0].length));
|
||||
} else {
|
||||
return makeCodeblock(tag.text);
|
||||
}
|
||||
|
||||
case 'default':
|
||||
// Convert to markdown code block if it is not already one
|
||||
if (tag.text.match(/^\s*[~`]{3}/g)) {
|
||||
return tag.text;
|
||||
}
|
||||
return '```\n' + tag.text + '\n```';
|
||||
return makeCodeblock(tag.text);
|
||||
}
|
||||
|
||||
return tag.text;
|
||||
|
|
Loading…
Reference in a new issue