Skip to content

Commit

Permalink
added markdown bold converter
Browse files Browse the repository at this point in the history
  • Loading branch information
omalk98 committed Sep 23, 2023
1 parent b889d62 commit 9005b6a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/utils/file-processor/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ export default class MarkdownProcessingStrategy extends FileProcessingStrategy {
return text;
}

protected convertBold(text: string): string {
const markdownBoldRegex = /\*\*([^\*]+)\*\*/;
const markdownBoldList = text.match(new RegExp(markdownBoldRegex, "g"));
if (markdownBoldList && markdownBoldList.length > 0) {
markdownBoldList.forEach((bold) => {
const boldGroup = bold.match(markdownBoldRegex);

if (boldGroup) {
const [mdBold, mdText] = boldGroup;
const boldTag = TILvertHTMLDocument.createTag("strong", mdText);
text = text.replace(mdBold, boldTag);
}
});
}
return text;
}

protected convertInlineCodeBlocks(text: string): string {
const markdownInlineCodeBlockRegex = /`([^`]+)`/;
const markdownInlineCodeBlocks = text.match(
Expand Down Expand Up @@ -91,6 +108,7 @@ export default class MarkdownProcessingStrategy extends FileProcessingStrategy {
segments.forEach((segment) => {
segment = this.convertLinks(segment);
segment = this.convertInlineCodeBlocks(segment);
segment = this.convertBold(segment);
htmlDocument.appendToBody(TILvertHTMLDocument.createTag("p", segment));
});
return htmlDocument;
Expand Down

0 comments on commit 9005b6a

Please sign in to comment.