-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
GFM line breaks #51
Comments
I do hope there's an option given about using GFM-style line breaks. That is always better to be compatible to someone else. And usually people hit Enter for one time to make line break, isn't it? |
you can force a newline by converting each "\n" => " \n". but this quick and dirty method overrides the --- untitled
+++ (clipboard)
@@ -77,6 +77,7 @@
src = src
.replace(/\r\n|\r/g, '\n')
+ .replace(/\n/g, ' \n')
.replace(/\t/g, ' ');
return block.token(src, tokens, true); |
That's a really, really dirty option that will break all your paragraphs and lists and most everything else. |
I think markdown should use a |
the double-space line breaks also bite when your editor is set to auto-trim-trailing during save. i agree that a single |
i agree it's very dirty. I wanted to run the tests quick but GitHub's GFM does something similar, # in very clear cases, let newlines become <br /> tags
text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end |
Thanks--I didn't know where to find GFM's code. That can be directly translated into JS and will produce the same behavior. Looks something like: src = src
.replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' ')
.replace(/^[\w\<][^\n]*\n+/mg,function(m){
return /\n{2}/.test(m) ? m : m.replace(/\s+$/,"")+" \n";
}); That's not integrating with the gfm setting at all, but it will duplicate the behavior of the original GFM. (Edited to add global flag on big regexp; edited to add multi-line flag. This code actually works now: the issue @stof mentioned is fixed my the multiline flag.) |
@chjj is there any plan to fix this issue ? It is rather annoying for me as I'm using marked in an editor preview whereas the Markedown will later be rendered server-side by Sundown (which handles the GFM line-breaks) |
@midnightmonster your big regex should not be anchored at the beginning of the string, otherwise it will only handle the first newline of the string instead of handling all of them. The working solution is: src = src
.replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' ')
.replace(/[\w\<][^\n]*\n+/g,function(m){
return /\n{2}/.test(m) ? m : m.replace(/\s+$/,"")+" \n";
}); |
github-flavored-markdown implemented it with replace(/ +\n/g," <br />\n") |
@mbuttjer that code just implements the original markdown line breaks. |
I think it is slightly misleading to state that "marked also implements GFM features" in the README. I found - after integrating marked into my application - that all GFM features were supported except the most prominent one (also the one I had come looking for): GFM line-breaks. Since line break handling is the biggest difference between GFM and strict Markdown (as stated on the GFM page itself), I think marked should either implement it, or else at least mention the lack of support for this feature (and perhaps link to this issue) in the README. @midnightmonster thanks for that quick hack. |
This feature was left out because markdown already has a brilliant way of dealing with hard line breaks. I feel like I've mentioned this before. Of course it would be easy to implement, but I would want it disabled by default. We'd have to change the options around, because I really don't want a mess of options like: |
@midnightmonster there seems to be some slight error with your hack. Take for example this input:
On GitHub, this is rendered as expected: But using marked and your hack, it renders as:
# in very clear cases, let newlines become <br /> tags
text.gsub!(/(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+/m) do |x|
x.gsub(/^(.+)$/, "\\1 ")
end |
Oops, sorry. Forgot to compare the last commit date on that repository with the gist @firien posted from. So if that gist is indeed the latest version, there must be some other error. |
I agree with vickychijwani
I would not call it GFM. Call it chjj markdown ;-) |
Ok, so I've modified @midnightmonster's workaround to resolve the error mentioned in my comment earlier. Basically I've added --- marked.js 2012-12-25 19:03:55.262335239 +0530
+++ marked.2.js 2012-12-25 19:04:17.025666623 +0530
@@ -1,6 +1,6 @@
src = src
.replace(/\r\n|\r/g, '\n')
.replace(/\t/g, ' ')
- .replace(/^[\w\<][^\n]*\n+/mg,function(m) {
+ .replace(/^[\w\<\>\*][^\n]*\n+/mg,function(m) {
return /\n{2}/.test(m) ? m : m.replace(/\s+$/,"")+" \n";
}); The gist posted on the GFM page ( |
Added in 7aa7934 |
A bit strange here, but isn't
|
GFM line breaks are not supported :
Line 1
Line 2
Sould be rendered as
When the gfm flag is set to true.
The text was updated successfully, but these errors were encountered: