Skip to content

Commit

Permalink
fix quote markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ender-null committed May 7, 2024
1 parent 66b68e8 commit 9c6caae
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,28 +799,10 @@ export const htmlToMarkdown = (text: string): string => {
text = text.replace(new RegExp('<u>(.*?)</u>', 'gim'), '~$1~');
text = text.replace(new RegExp('<code>(.*?)</code>', 'gim'), '`$1`');
text = text.replace(new RegExp('<pre>(.*?)</pre>', 'gim'), '```$1```');
text = text.replace(new RegExp('<blockquote>(.*?)</blockquote>', 'gim'), '> $1');

text = text.replace(new RegExp('&lt;', 'gim'), '<');
text = text.replace(new RegExp('&gt;', 'gim'), '>');
}
return text;
};

export const htmlToMarkdownLegacy = (text: string): string => {
if (text) {
const replacements = [
{ pattern: '<code class="language-([\\w]+)">([\\S\\s]+)</code>', sub: '```$1\n$2```' },
{ pattern: '<a href="(.[^<]+)">(.[^<]+)</a>', sub: '$1' },
{ pattern: '<[/]?i>', sub: '_' },
{ pattern: '<[/]?b>', sub: '*' },
{ pattern: '<[/]?u>', sub: '~' },
{ pattern: '<[/]?code>', sub: '`' },
{ pattern: '<[/]?pre>', sub: '```' },
];
replacements.map((rep) => {
text = text.replace(new RegExp(rep['pattern'], 'gim'), rep['sub']);
text = text.replace(new RegExp('<blockquote>(.*?)</blockquote>', 'gim'), (p1) => {
return '> ' + p1.replace(/\n/g, '\n> ');
});

text = text.replace(new RegExp('&lt;', 'gim'), '<');
text = text.replace(new RegExp('&gt;', 'gim'), '>');
}
Expand Down

0 comments on commit 9c6caae

Please sign in to comment.