Skip to content

Commit

Permalink
Fix codeblock detection to catch blocks not on first Lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Sep 10, 2021
1 parent c62f59f commit eb226ae
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions extensions/typescript-language-features/src/utils/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,16 @@ function getTagBodyText(
return undefined;
}

// Convert to markdown code block if it is not already one
// Convert to markdown code block if it does not already contain one
function makeCodeblock(text: string): string {
if (text.match(/^\s*[~`]{3}/g)) {
if (text.match(/^\s*[~`]{3}/m)) {
return text;
}
return '```\n' + text + '\n```';
}

const text = convertLinkTags(tag.text, filePathConverter);
switch (tag.name) {
case 'example':
// check for caption tags, fix for #79704
const captionTagMatches = text.match(/<caption>(.*?)<\/caption>\s*(\r\n|\n)/);
if (captionTagMatches && captionTagMatches.index === 0) {
return captionTagMatches[1] + '\n\n' + makeCodeblock(text.substr(captionTagMatches[0].length));
} else {
return makeCodeblock(text);
}
case 'author':
// fix obsucated email address, #80898
const emailMatch = text.match(/(.+)\s<([-.\w]+@[-.\w]+)>/);
Expand All @@ -66,6 +58,7 @@ function getTagBodyText(
} else {
return `${emailMatch[1]} ${emailMatch[2]}`;
}
case 'example':
case 'default':
return makeCodeblock(text);
}
Expand Down

0 comments on commit eb226ae

Please sign in to comment.