Skip to content

Removing escaping characters in markdown generation. #1016

Closed
@Jessica0813

Description

@Jessica0813

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions