Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing escaping characters in markdown generation. #1016

Open
Jessica0813 opened this issue Aug 15, 2024 · 0 comments
Open

Removing escaping characters in markdown generation. #1016

Jessica0813 opened this issue Aug 15, 2024 · 0 comments

Comments

@Jessica0813
Copy link

Jessica0813 commented Aug 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant