Tui.editor: getMarkdown() returns HTML for pasted content

Created on 21 Jan 2021  Â·  5Comments  Â·  Source: nhn/tui.editor

Describe the bug

When content is copy pasted to the editor, the getMarkdown() returns HTML only instead of markdown

To Reproduce

  1. Go to https://ui.toast.com/tui-editor and copy some formatted content
  2. Paste it in the editor https://jsfiddle.net/rrjanbiah/9ytodkbx/show/
  3. Click Get HTML and Get Markdown buttons

Expected behavior

getMarkdown() always return markdown. And, 'preferably', getHtml() removes unnecessary formatting

Screenshots

Check video below:

tuieditor1copy-2021-01-21_21 04 09

Desktop (please complete the following information):

  • OS: Ubuntu
  • Browser Chrome
  • Version Version 87.0.4280.141 (Official Build) (64-bit)

Additional context

  1. Refer to the code in https://jsfiddle.net/rrjanbiah/9ytodkbx/
  2. Probably related to #1334 (but not sure)
Bug Clipboard

All 5 comments

@rrjanbiah Thanks for the detailed explanation. This is a specification and Markdown allows the html inline <span> tag, so <span> is maintained when pasting.

@seonim-ryu Thank you! Are there any quick workarounds for the current version?

even i dont like those tags in markdown, and i could not find a fix.
Hence I use this code as my own code as a workaround:

editor.on("change",function(data) {
        let mdtext = editor.getMarkdown();
        cleanedup_mdtext = mdtext;
        cleanedup_mdtext = cleanedup_mdtext.replace(/<[\/]?span[^>]*>/g, "");
        cleanedup_mdtext = cleanedup_mdtext.replace(/<br[\s\/]*>/g, "");
        cleanedup_mdtext = cleanedup_mdtext.replace(/<[\/]?u>/g, "");
        if ( cleanedup_mdtext !== mdtext ) {
            //console.log(cleanedup_mdtext);
            //console.log(mdtext);
            //console.log("------");
            editor.setMarkdown(cleanedup_mdtext);
        }
});

@ankanani Thanks for sharing! Much appreciated

I'm having a similar issue where lists are rendered by getMarkdown() as <li> HTML elements instead of markdown -, and newlines rendered as <br> instead of just a blank line. It seems that the function is returning a mix of HTML and markdown. This only occurs when something has been pasted into the editor. Working on a repro case in case it is the same issue.

Ok, found an example. Copying and pasting this comment into the editor will result in a mystery <br> being inserted after What, as returned by getMarkdown(). I wouldn't really expect the getMarkdown function to return any HTML at all but especially when the origin content is all markdown.

What

  • Ok

Why

If there is anything I can do to help just let me know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

koliyo picture koliyo  Â·  4Comments

nilhave picture nilhave  Â·  3Comments

aarangara picture aarangara  Â·  3Comments

cyberjacob picture cyberjacob  Â·  4Comments

hellojsna picture hellojsna  Â·  4Comments