You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Marked removes non-breaking spaces in the original text #363
@daleconboy, I'm sorry to hear that, but many people lost several hours of their lives trying to figure out why their spaces weren't getting processed correctly when text was passed in from the DOM (see #52 - cc @OscarGodson), which is why this was added in the first place.
I'll consider adding an option, but I want to keep their removal the default since more people probably get bit by this "feature" of contenteditable elements than not.
Hey, thanks for the response. I definitely sympathize with anyone who's been bitten by this quirk in any way, however I would argue against the default being wholesale replacement of non-breaking spaces.
Reason being, it's not a bug with marked, but rather a browser behavior which shouldn't be the responsibility of marked to manage. Technically the responsibility should fall on the developer who's using the contenteditable elements to be aware of the quirk and to manage the white space handling, or conversion, on their end.
The W3C working draft specifically calls this out to authors working with contenteditable elements:
Authors are encouraged to set the 'white-space' property on editing hosts and on markup that was originally created through these editing mechanisms to the value 'pre-wrap' …
It seems that with contenteditable regions expected to behave in this way, you would want to preserve their expected behavior by default to avoid confusion. This, in turn, would also avoid the confusion where devs are expecting their explicitly set non-breaking spaces to behave as expected.
And, since marked may also be used in a node environment where contenteditabe does not exist, this replacement behavior by default would be unexpected.
Bottom line, I appreciate you considering it as an option. How you decide to set the default behavior is of course up to you. Any option is definitely better than no option. I'll cast my vote for the default being no replacement. :)
@daleconboy's argument is pretty convincing. Are there other use cases for no-break spaces in markdown input? I would think a set of tests would help define the severity of the issue.
@daleconboy I like your point about the browser, except, in @arturi's post he specifically points out that spaces are good to fix a browser bug haha :) Also, i wouldn't agree that it's a browser issue. Markdown's "spec" doesn't say which kind of spaces are and aren't allowed so IMO Marked, and any markdown parser, should assume all spaces (nbsp, unicode, etc) should be considered what they are: spaces. Your suggestion, unless im misunderstanding it, is wanted to specifically ignore certain kinds of spaces.
I’m working on a Markdown-based presentation tool, and I’m using marked to generate HTML.
Having control over when and where text wraps is vital in a good presentation. Currently, the only way I can do that with marked is by overriding the lexer with a custom one that does the same things as the original one, except for the NBSP replacement. This is of course far from future-proof: In case the original lexer changes, I have to adapt my code.
Therefore I’m very much in favor of making this configurable. If you’re interested in a PR, let us know. And although I think that not replacing the NBSPs is the “right” thing to do, I can understand that you don’t want to break existing code that relies on marked fixing the browser behavior. So, I don’t care what the default for this option is, but please introduce one.
@Lendar 's suggestion is wonderful and if I edit this in the source code I can fix it this way. However putting it straight into my own code complains about 'this.token' not being a function. What is the best way to implement this?
I am in the same boat as @scy — working on a Markdown-based presentation tool. I, too, want to control where lines break and where they never break. Please make an option that stops breaking non-breaking spaces.
As for browsers and/or WYSIWYG editors inserting non-breaking spaces where not expicitly requested by the user, that’s their bugs and should be fixed there.
Again, I'm not sure if the original ticket was referring to the html encoded or a unicode character discovery - not the same thing in my book. As a user, I would expect the to be preserved, but not necessarily a special character injection of UTF-8 or something similar...am I wrong there. I concur that Chris's assessment is debatable.
I'm pretty sure ` `s pass through without a problem. Whereas the
Unicode character is currently replaced by a single space. It seems it was
set this way because users somehow typed in unwanted non-breaking spaces,
but it seems to me this assumption is flimsy. Also you take away from
others the possibility to consciously use non-breaking spaces and I don't
like that. We certainly need to improve our Unicode support in general (per
commonmark), so I think this will change eventually. We need to make sure
everything works smoothly as usual.
All right. Leaving closed for now. Flagging with newly minted #1048 for when we're ready to focus there. This could also explain the Chinese character problems with header ids, yeah?
Activity
christopherscott commentedon Mar 12, 2014
+1, if anything this should be an option, or configurable
daleconboy commentedon Mar 12, 2014
Yes! I've recently lost a few hours of my life tracking this very same thing down.
chjj commentedon Mar 13, 2014
@daleconboy, I'm sorry to hear that, but many people lost several hours of their lives trying to figure out why their spaces weren't getting processed correctly when text was passed in from the DOM (see #52 - cc @OscarGodson), which is why this was added in the first place.
I'll consider adding an option, but I want to keep their removal the default since more people probably get bit by this "feature" of contenteditable elements than not.
daleconboy commentedon Mar 14, 2014
Hey, thanks for the response. I definitely sympathize with anyone who's been bitten by this quirk in any way, however I would argue against the default being wholesale replacement of non-breaking spaces.
Reason being, it's not a bug with marked, but rather a browser behavior which shouldn't be the responsibility of marked to manage. Technically the responsibility should fall on the developer who's using the contenteditable elements to be aware of the quirk and to manage the white space handling, or conversion, on their end.
The W3C working draft specifically calls this out to authors working with contenteditable elements:
http://www.w3.org/TR/html51/editing.html#best-practices-for-in-page-editors
It seems that with contenteditable regions expected to behave in this way, you would want to preserve their expected behavior by default to avoid confusion. This, in turn, would also avoid the confusion where devs are expecting their explicitly set non-breaking spaces to behave as expected.
And, since marked may also be used in a node environment where contenteditabe does not exist, this replacement behavior by default would be unexpected.
Bottom line, I appreciate you considering it as an option. How you decide to set the default behavior is of course up to you. Any option is definitely better than no option. I'll cast my vote for the default being no replacement. :)
Cheers!
drscannell commentedon Mar 14, 2014
@daleconboy's argument is pretty convincing. Are there other use cases for no-break spaces in markdown input? I would think a set of tests would help define the severity of the issue.
OscarGodson commentedon Mar 14, 2014
@daleconboy I like your point about the browser, except, in @arturi's post he specifically points out that spaces are good to fix a browser bug haha :) Also, i wouldn't agree that it's a browser issue. Markdown's "spec" doesn't say which kind of spaces are and aren't allowed so IMO Marked, and any markdown parser, should assume all spaces (nbsp, unicode, etc) should be considered what they are: spaces. Your suggestion, unless im misunderstanding it, is wanted to specifically ignore certain kinds of spaces.
scy commentedon Apr 8, 2014
I’m working on a Markdown-based presentation tool, and I’m using marked to generate HTML.
Having control over when and where text wraps is vital in a good presentation. Currently, the only way I can do that with marked is by overriding the lexer with a custom one that does the same things as the original one, except for the NBSP replacement. This is of course far from future-proof: In case the original lexer changes, I have to adapt my code.
Therefore I’m very much in favor of making this configurable. If you’re interested in a PR, let us know. And although I think that not replacing the NBSPs is the “right” thing to do, I can understand that you don’t want to break existing code that relies on marked fixing the browser behavior. So, I don’t care what the default for this option is, but please introduce one.
Lendar commentedon Jun 17, 2015
@scy suggestion is nice. Let me extend it with an example. It might be helpful for future readers...
UPDATED 2017-05-11: fixed syntax
RichardForrester commentedon Feb 15, 2016
Is anyone aware of an option or a work around for this issue?
There should definitely be an option to allow non-breaking spaces to pass to the HTML.
arturi commentedon Feb 15, 2016
I’ve solved it by extending lex, as shown here: #363 (comment).
deanvaessen commentedon Apr 29, 2017
Hello everyone,
@Lendar 's suggestion is wonderful and if I edit this in the source code I can fix it this way. However putting it straight into my own code complains about 'this.token' not being a function. What is the best way to implement this?
Cheers!
davidchambers commentedon Apr 29, 2017
I imagine the problem, @deanvaessen, is the arrow function. Try replacing
(src) => { ... }withfunction(src) { ... }. :)deanvaessen commentedon May 4, 2017
Confirmed. Thank you @davidchambers :)
Lendar commentedon May 11, 2017
@davidchambers @deanvaessen surprised it's still relevant. Updated the example in the comment ⬆️
yurikhan commentedon May 28, 2017
I am in the same boat as @scy — working on a Markdown-based presentation tool. I, too, want to control where lines break and where they never break. Please make an option that stops breaking non-breaking spaces.
As for browsers and/or WYSIWYG editors inserting non-breaking spaces where not expicitly requested by the user, that’s their bugs and should be fixed there.
12 remaining items
joshbruce commentedon Feb 11, 2018
@Feder1co5oave: Reopen or no?
Again, I'm not sure if the original ticket was referring to the html encoded
or a unicode character discovery - not the same thing in my book. As a user, I would expect the to be preserved, but not necessarily a special character injection of UTF-8 or something similar...am I wrong there. I concur that Chris's assessment is debatable.Leave it to you, brother.
Feder1co5oave commentedon Feb 11, 2018
joshbruce commentedon Feb 11, 2018
All right. Leaving closed for now. Flagging with newly minted #1048 for when we're ready to focus there. This could also explain the Chinese character problems with header ids, yeah?
Feder1co5oave commentedon Feb 11, 2018
Feder1co5oave commentedon Feb 23, 2018
Tagging as #1048
joshbruce commentedon Feb 24, 2018
Tagging #1043 as well, just because of the "header ids" comment.
UziTech commentedon Dec 5, 2018
related pr #897