Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Pygments Code blocks breaks indents in lists

#55

In markdown like:

1. First Entry

Some more text

Yet more text

some code

more code

1. Second Entry

... rendering is as expected, i.e., the indented text appears within the

  • of the "First Entry", and the "Second Entry" gets the list marker "2."

    However, if I replace

     with your pygments plugin something like:
    

    1. First Entry

    Some more text

    Yet more text

    @@ bash

    some code

    more code

    @@

    1. Second Entry

    ... the indentation breaks, and the "Second Entry" gets the marker "1.".

    Heres an example page: http://206.212.244.131:8080/entr...

    Search for "Generating an ssh key" and look at the list below it, which is broken by the @@ bash @@ block

    Search for "Making a difference" and look at the list below it, which is not broken and uses the

     block.
    

    I tried to fix this bug, but I wasn't able to understand the structure of markdown in such a short time. I couldn't understand how your CodeBlockPreprocessor was different from markdown's HtmlBlockPreprocessor to cause this bug.

    Could you help me fix this bug ?

  • Reported by rajeev.sebastian (at gmail) · July 3rd, 2008 @ 05:09 PM

    State: resolved
    Milestone: 0.91: Code Cleanup
    Assigned to: Will Larson Will Larson

    Activity

    1. rajeev.sebastian (at gmail)
      rajeev.sebastian (at gmail)

      Hmm, I'm sorry, but the textile markup engine on this site really broke my ticket description. I hope you understand what I meant though ...

      July 3rd, 2008 @ 05:10 PM

    2. Will Larson
      Will Larson
      • State changed from new to open
      • Milestone changed from 0.90: LifeFlow Editor to 0.91: Code Cleanup

      Yes, I do understand what you mean, unfortunately.

      At the moment the syntax highlighting only works at the base level I.e.

      "@@ python\ndef x(a,b):\nreturn a * b\n@@\n"

      and not at " @@ python\ndef x(a,b):\nreturn a * b\n@@\n".

      I'll try to deal with that.

      July 3rd, 2008 @ 05:20 PM

    3. rajeev.sebastian (at gmail)
      rajeev.sebastian (at gmail)
      • Tag set to bug

      Hi Will Larson,

      I fixed the issue, atleast for my particular blog.

      All I had to do was add:

      (?P\s+)

      just before @@ in the regexp on line 19 of lifeflow/markdown/mdx_code.py

      This was because I noticed that the placeholders where being generated without any spaces before them, and that was causing the HtmlBlockPreprocessor to generate the wrong HTML (as if a new block was being started rather than a new indented sub-block).

      Could you confirm whether, in your mind, this would be a sufficient fix for the general case ?

      July 3rd, 2008 @ 05:51 PM

    4. rajeev.sebastian (at gmail)
      rajeev.sebastian (at gmail)

      thats ...

      (?P&lquot;spaces&rquot;\s+)

      July 3rd, 2008 @ 05:51 PM

    5. Will Larson
      Will Larson

      Thank Rajeev. I think that code isn't quite general enough, because it will add extra whitespace in front of the code.

      I think the code needs to be a bit more complex to handle this.

      1. Find the code block, by using your regex to locate code blocks that start with some spacing.

      2. Within that matched code block, strip the number of spaces preceeding the ``@@ syntax`` block. For example if it was ` @@ python`` it would strip four spaces from each line.

      3. For the Python Markdown, prefix those four spaces in front of the html placeholder (it uses a hash as placeholders for raw html, but we need to reinsert it at the right indent level so it stays within the list, etc, its supposed to be in).

      Thanks for looking into this. I realize thats a bit of an awkward set of changes I've detailed here, so I'll put them together, test them, and push them in later today when I have some time. Although, if you want to take a stab at it, you're more than welcome. :)

      July 3rd, 2008 @ 06:44 PM

    6. rajeev.sebastian (at gmail)
      rajeev.sebastian (at gmail)

      I see now what you mean. I'll try to fix it and provide a patch ...

      Thanks for the help

      July 3rd, 2008 @ 07:47 PM

    7. rajeev.sebastian (at gmail)
      rajeev.sebastian (at gmail)

      Hi Will Larson,

      I think I've completed the fix. Please see the attached file.

      Thanks.

      July 4th, 2008 @ 09:49 PM

    8. Will Larson
      Will Larson
      • State changed from open to resolved

      Hi Rajeev,

      Thanks so much for your patch. I checked it out and it fixes everything. I pushed your fix to the version at github as well.

      http://github.com/lethain/lifefl...

      July 5th, 2008 @ 09:58 AM

    Please Sign in or create a free account to add a new ticket.

    With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.