-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Properly parse line breaks in Markdown without adding extraneous <br> tags #485
Comments
Note that while this seems to be related to #299, I don't think it's a duplicate, because that issue has more to do with what happens when pasting text into the WYSIWYG, and not strictly with the markdown rendering. |
Currently we are supporting that 'soft line break' render like 'hard line break'. But if you needs to support 'soft line break', we will provide to option to be able.
|
Yes I definitely need this option, and it would let Toast UI conform to GFM as well, as in the spec it says "a renderer may also provide an option to render soft line breaks as hard line breaks." Thanks! |
We also are in need of this. Our users are expecting a hard line break in the wysiwyg when they create a new line. However when the generated markdown is rendered with a variety of tools, there is no line break. |
Ran into this problem as well. Unfortunately, due to this issue, it makes it nearly impossible for us to combine it with other markdown tools. |
@dnotes @parthshah31 @benjaminbaker const editor = new Editor({
el: document.querySelector('#editor'),
customHTMLRenderer: {
softbreak(_, { options }) {
return {
type: 'html',
content: options.softbreak
};
}
},
// ...
}); |
Thanks for your response. But I was more looking for a toMarkdown function that returns those as hard breaks. The above code didn't change the getMarkdown()'s result. |
For example when I write in the wysiwyg
I want the get markdown to return the following spec-compliant result:
|
@parthshah31 var editor = new Editor({
// ...
});
const default = editor.toMarkOptions.renderer;
const renderer = defaultRenderer.constructor.factory(default, {
BR(node) {
return node.previousSibling.tagName === 'BR' ? ' \n' : '\n\n';
}
});
Object.assign(editor.toMarkOptions, { renderer }); However, as mentioned above, it is not a perfect solution. |
Any news on this? Or recommendations on how to work around it? I'm currently rendering my markdown using
then the final rendering fails and just displays
edit: not actually sure it's the same bug as this issue. i'm confused 🤔 something is not following the gfm spec at least |
I think I've come up with a workaround that works well enough for now for me, I'm filtering away BR tags with a regex in the onChange handler cobudget/cobudget@f184ee9 |
Is there any update on this? I'm using the next major version, and it's still broken |
Version
2.5.3
Test Environment
Firefox (current), MacOS
Current Behavior
Writing a line break in the markdown editor results in a
<br>
being added to the html output for both the preview pane and the wysiwyg editor:is rendered as
Expected Behavior
In the GFM specification a line break is specified as a soft line break, and though viewers may choose to display such breaks as either a line break or a space, it is clear from the example that the resulting HTML should not have a
<br>
tag in it. So for the above example:should be rendered in the Toast UI preview and WYSIWYG editors as
The text was updated successfully, but these errors were encountered: