#55 ✓resolved
rajeev.sebastian (at gmail)

Pygments Code blocks breaks indents in lists

Reported by rajeev.sebastian (at gmail) | July 3rd, 2008 @ 05:09 PM | in 0.91: Code Cleanup

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 ?

  • Comments and changes to this ticket

    • rajeev.sebastian (at gmail)

      rajeev.sebastian (at gmail) July 3rd, 2008 @ 05:10 PM

      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 ...

    • Will Larson

      Will Larson July 3rd, 2008 @ 05:20 PM

      • 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.

    • rajeev.sebastian (at gmail)

      rajeev.sebastian (at gmail) July 3rd, 2008 @ 05:51 PM

      • 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 ?

    • rajeev.sebastian (at gmail)

      rajeev.sebastian (at gmail) July 3rd, 2008 @ 05:51 PM

      thats ...

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

    • Will Larson

      Will Larson July 3rd, 2008 @ 06:44 PM

      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. :)

    • rajeev.sebastian (at gmail)

      rajeev.sebastian (at gmail) July 3rd, 2008 @ 07:47 PM

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

      Thanks for the help

    • rajeev.sebastian (at gmail)

      rajeev.sebastian (at gmail) July 4th, 2008 @ 09:49 PM

      Hi Will Larson,

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

      Thanks.

    • Will Larson

      Will Larson July 5th, 2008 @ 09:58 AM

      • 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...

    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.

    New-ticket Create new ticket

    Create your profile

    Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

    A full featured and opinionated blogging app built using the Django web framework.

    Attachments

    Tags

    Pages