knockdown icon indicating copy to clipboard operation
knockdown copied to clipboard

Fenced code doesn't work unless there's a newline before it

Open mbonaci opened this issue 12 years ago • 12 comments

Github markdown recognizes two formats (although format is a little strong word for this) for code blocks, one that starts from the left margin and the other that starts indented, aligned with text. The first format is achieved by putting one or more empty lines before code fence, and the second one is achieved by not putting any empty lines between text and code fence. It seems that this second format doesn't work in knockdown:

temp

mbonaci avatar Jul 31 '13 18:07 mbonaci

At first, I thought it's similar to #9 but

the second one is achieved by not putting any empty lines between text and code fence.

I maybe misunderstood, but code block should be either unindented or placed within list item that is 'the four-space rule'

here's what Github render (no indent, no emptyline)

  • text
class Array(
   val contents: Array[String]

now with four-space rule and blank line

  • text

    class Array(
       val contents: Array[String]
    

Moreover, https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks

Keep in mind that both types of code blocks need to have a blank line before them

Anyway, I would really appreciate if you check #9 and there's link to fix I tried to make, I have not enough time to check everything, so would be nice if you let me know that fix work for you or there's something wrong.

vovkkk avatar Aug 01 '13 07:08 vovkkk

Thanks for checking this out. I must admit I did not RTFM, I simply tried both options in Github wiki and noticed the discrepancy. Will try when I get home, in 3 hrs.

On Thursday, August 1, 2013, Vova Kolobok wrote:

At first, I thought it's similar to #9https://github.com/aziz/knockdown/issues/9but

the second one is achieved by not putting any empty lines between text and code fence.

I maybe misunderstood, but code block should be either unindented or placed within list item that is 'the four-space rule'

here's what Github render (no indent, no emptyline)

  • text scala class Array( val contents: Array[String]

now with four-space rule and blank line

text

class Array( val contents: Array[String]

Moreover, https://help.github.com/articles/github-flavored-markdown#fenced-code-blocks

Keep in mind that both types of code blocks need to have a blank line before them

Anyway, I would really appreciate if you check #9https://github.com/aziz/knockdown/issues/9and there's link to fix I tried to make, I have not enough time to check everything, so would be nice if you let me know that fix work for you or there's something wrong.

— Reply to this email directly or view it on GitHubhttps://github.com/aziz/knockdown/issues/13#issuecomment-21919741 .

mbonaci avatar Aug 01 '13 09:08 mbonaci

Ok, let me demonstrate the difference in behavior between github and sublime knockout.

Here's a github MD example of adding a newline between a bullet and code block: github-edit-with-newline-after-list-item

How that actually looks: github-display-with-newline-after-list-item

Same thing, but with no newline: github-edit-no-newline-after-list-item

Which looks like this: github-display-no-newline-after-list-item

And in Sublime, with newline: sublime-with-newline-after-list-item

Sublime, without newline: sublime-no-newline-after-list-item

I hope this makes the discrepancy clearer. Thanks

mbonaci avatar Aug 01 '13 14:08 mbonaci

You're right. it seems github deviating from standard markdown in this case. in Markdown code blocks should be preceded by an empty line. I've reopened the issue.

aziz avatar Aug 01 '13 15:08 aziz

@vovkkk I cloned your repo but it works the same way as the original. Thanks

I'd like to help out, but I suck at tmlanguage syntax :)

mbonaci avatar Aug 01 '13 15:08 mbonaci

tmlanguage syntax sucks!

aziz avatar Aug 01 '13 15:08 aziz

So Github renders differently in comments and in wiki! LOL, because now if one say 'GitHub Flavored Markdown' you have ask 'which of them?'

I cloned your repo but it works the same way as the original

Mmm, did you switch branch, restart Sublime? or maybe you're on ST3? I didn't test that on ST3 yet.

vovkkk avatar Aug 02 '13 05:08 vovkkk

Well, after brief test in ST3 it works for me as well as in ST2.

@mbonaci please make sure you use right branch (not master, but code-inside-lists) and restart Sublime.

pic 2013-08-02 13 35 37

vovkkk avatar Aug 02 '13 06:08 vovkkk

Ups, you're right, I used Master, sorry about that. It works, great job! Thanks to both of you @aziz and @vovkkk

mbonaci avatar Aug 02 '13 10:08 mbonaci

@vovkkk The same thing applies to quote blocks (> ), github indents them if no newline, your knockdown code-inside-lists doesn't format it with no newline (ST3):

image

To slip you this one up, while you're in the mood... :)

mbonaci avatar Aug 02 '13 14:08 mbonaci

@mbonaci inclusion block_quote into list-paragraph should do the trick. However, list-paragraph already includes inline, and block_quote also includes inline; so some sort of recursion should be expected, rearrangement for regexes is needed, so it is far away from what I call 'easy fix'. Maybe someday I will have enough time and bravery for this issue, unless one fix it before.

Besides, fwiw, default Markdown.tmLanguage doesn't define blockqoute within lists, although it's in 'official' spec, so again it's complex issue.

vovkkk avatar Aug 03 '13 14:08 vovkkk

I understand, of course. For now, I decided to go with newline before each block quote. Let it stick out, what a hell :)

PS the only reason I'm reporting these is because I'm slightly obsessive-compulsive about formatting. I'm sure no normal person would even notice the difference ;) Great work, both of you.

mbonaci avatar Aug 03 '13 17:08 mbonaci