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:
Matt Bierner 2019-08-27 14:49:19 -07:00
parent 9ab856b571
commit 8891b85518

View file

@ -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;