MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.43k stars 1.09k forks source link

Code formatting not respecting indentation #892

Open ajmas opened 6 years ago

ajmas commented 6 years ago

I have the following Markdown code:

  {
    "name": "",
    "description": ""
    "entries": [{

    }]
  ]

This formats correctly in GitHub issue tracker, but not in Macdown. The attached image illustrates the behaviour

screen shot 2017-12-04 at 17 17 59

MacDown 0.7.1, macOS 10.13.1

FranklinYu commented 6 years ago

Cannot reproduce with either fenced block or indented block.

ajmas commented 6 years ago

Turns out It was an incomplete scenario. It happens when it is a child of a bullet list:

screen shot 2017-12-06 at 11 22 29

Also an issue in master branch version. GitHub editor renders fine:

FranklinYu commented 6 years ago

That's a great example. It seems like Hoedown assumes that indentation level is 4; in your example, if the code block is indented with four spaces, it will show just fine.

However, we are planning to move to CommonMark, where it is clearly defined that this is not desired, and your case should be correctly recognized as indentation with two spaces. In conclusion, this is a bug, but need some time to fix.

cori commented 6 years ago

I'm not sure if I'm seeing the same thing or if it's the same bug, but I'm seeing fenced code blocks not respecting whitespace at all when they're children of a bulleted list.

image

If this is the same issue then I won't open another, and it sure seems like it might be.

FranklinYu commented 6 years ago

@cori Does the fenced code belong to the item or not? I meant, what you intend to do?

cori commented 6 years ago

Ideally (for me in this case) it would be a part of that bullet, but would display formatted

FranklinYu commented 6 years ago

Then you should indent the fenced code block, or the parser would got confused.

cori commented 6 years ago

same result when indented 4 spaces: image

cori commented 6 years ago

here's the actual content

{
    "prop1": "thing1",
    "prop2": "thing2",
    "obj_prop": {
        "oprop1": "othing1",
        "oprop2": "othing2"
    }
}
FranklinYu commented 6 years ago

You need a blank line between the code block and everything else. Your sample is same as

a line

{ "some": "code" }

within a list item. The code above renders the “fenced block” as inline block, since there is no empty line to break the paragraph “a line”.

I’m not sure whether this meet the requirement of CommonMark, but it is a good habit anyway. I’ll further investigate the CommonMark specification.

FranklinYu commented 6 years ago

Oops, looks like CommonMark allows this:

Fenced code blocks can interrupt paragraphs, and can be followed directly by paragraphs, without a blank line between…

But that’s another bug.

uranusjr commented 6 years ago

Yeah CommonMark is more lenient with empty lines. The produced HTML is the same, however, since <pre> is a block-level element, and cannot be nested inside <p>. I would recommend users to add an empty line anyway. There’s no such thing as a code block belonging to a paragraph.

FranklinYu commented 6 years ago

The develop branch of Hoedown has it right again. So we are back to the old issue #704. That one is blocking. I think it’s better to write well-formed Markdown instead of trying the edge-cases, until we find a better Markdown implementation.