Skip to content

Commit

Permalink
Fix caption parsing
Browse files Browse the repository at this point in the history
For microsoft#79704

- Use regexp
- Handle unix line endings
- Don't highlight caption as part of code block
  • Loading branch information
mjbvz authored and hwhung0111 committed Aug 28, 2019
1 parent afbdf1a commit 31591bc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions extensions/typescript-language-features/src/utils/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 31591bc

Please sign in to comment.