Closed
Description
Hey everyone,
I am having an issue with showdown.
function decodeHtmlEntities(text: string): string {
textArea.innerHTML = text;
return textArea.value;
}
export function getText(editor: Editor): string {
let html = editor?.getHTML();
console.log('HTML before conversion:', html);
if (html) {
const converter = new showdown.Converter();
let _text = converter.makeMarkdown(html);
console.log('Markdown after conversion:', _text);
_text = decodeHtmlEntities(_text);
console.log('Text after decoding HTML entities:', _text);
// need to check for @<span data-type="mention" data-id="62fbac0c1fcd4f036e1679b7" data-label="Ben">Ben</span>
// and replace with <@62fbac0c1fcd4f036e1679b7> where the id is the data-id
_text = _text.replace(/@<span data-type="mention" data-id="(.+?)" data-label="(.+?)">(.+?)<\/span>/g, '<@$1>');
return _text;
}
return '';
}
HTML before conversion: <p>This is _ underscore <em> star and ^$&#</em>$*(>?.,\</p>
Markdown after conversion: This is _ underscore * star and ^$&#$\*(>?.,\
Text after decoding HTML entities: This is _ underscore * star and ^$&#$\*(>?.,\
For some reason, on underscores and stars and some other characters I get escaping backslashes injected when converting it to markdown. I have not found any settings that allow me to get the markdown from showdown. Can anyone tell me how to do this? Post processing it seems a bit dirty. Appreciate any feedback
Metadata
Metadata
Assignees
Labels
No labels