Skip to content

Angle Brackets Bug #240

Open
Open

Description

@gregschmit

I noticed that in some scenarios, this bug can occur:

Suppose your string is the following:

>>> string =  """
... Start of test.
...
...     for (i=0; i<3; i++) {
...         printf("Hello, world.");
...     }
...
... > This is a quote
...
... End of test.
... """

I would expect the C-code snippet to be formatted as a code block, and the quote to be formatted as a blockquote.

However, when I use safe_mode="escape" (because I want users of this to be able to use HTML in the application), markdown2 thinks that there is a big HTML tag in this block from the less than symbol to the beginning of the blockquote:

>>> import markdown2
>>> markdown2.markdown(string, safe_mode="escape")
'<p>Start of test.</p>\n\n<pre><code>for (i=0; i&lt;3; i++) {\n        printf("Hello, world.");\n    }  \n\n&gt; This is a quote\n</code></pre>\n\n<p>End of test.</p>\n'
>>> markdown2.markdown(string, safe_mode="replace")
'<p>Start of test.</p>\n\n<pre><code>for (i=0; i[HTML_REMOVED] This is a quote\n</code></pre>\n\n<p>End of test.</p>\n'
>>>

This seems to be a bug, because it means I cannot have a blockquote after a block of code that uses a < symbol.

Activity

  1. nicholasserra commented on Feb 1, 2017

    @nicholasserra
    Collaborator

    Did you try this on the latest commit? We had a bug around escaping that may have effected this.

  2. gregschmit commented on Feb 1, 2017

    @gregschmit
    Author

    I did, and the code block is extended to include the blockquote. You can try it if you want. I guess I didn't give a clear way of replicating:

    1. Enter your python3 environment
    2. set string = """, and then paste the following text into it:
    begin test
    
        for (i=0; i<3; i++) {
            printf("Hello, world!");
        }
    
    This is a sentence
    
    > This is a quote
    
    end test
    
    1. Then end it with """ and hit 'enter'.
    2. run:
    import markdown2
    markdown2.markdown(string, safe_mode="escape")
    

    Then you should see that the code block extends all the way through the quote, when it should end before the "This is a sentence".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions