Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong code block output? #263

Open
gopar opened this issue Jun 30, 2017 · 4 comments
Open

Wrong code block output? #263

gopar opened this issue Jun 30, 2017 · 4 comments

Comments

@gopar
Copy link

gopar commented Jun 30, 2017

import markdown2
text = """
```
- (void)openWebsocketWithURL:(NSURL *)url {

    // Create a security policy that enforces SSL validation
    SRSecurityPolicy *securePolicy = [[SRSecurityPolicy alloc] initWithCertificateChainValidationEnabled:YES];
}
```
"""
print(markdown2.markdown(text))

Produces the following:

<p>```
- (void)openWebsocketWithURL:(NSURL *)url {</p>

<pre><code>// Create a security policy that enforces SSL validation
SRSecurityPolicy *securePolicy = [[SRSecurityPolicy alloc] initWithCertificateChainValidationEnabled:YES];
</code></pre>

<p>}
```</p>

From what I understand it should produce everything inside a code tag and no pre tag like so:

text = "``` a = 90 ```"
print(markdown2.markdown(text))
# Prints out
# <p><code>a = 90</code></p>

Am I incorrect or am I missing something?

@nicholasserra
Copy link
Collaborator

nicholasserra commented Jul 5, 2017

You'll need to enable the fenced-code-blocks extra to get those kind of code blocks.

Try:

markdown2.markdown(text, extras=["fenced-code-blocks"])

and let me know if that works.

@gopar
Copy link
Author

gopar commented Jul 5, 2017

Hey Yeah that works but what I'm curious about is why the extra parameter is needed? We have other snippets of code that we are passing that are similar to this one and the output is just fine.

Also, I can't really use fenced-code-blocks since what I've noticed is that when code is surrounded by 3 backticks it'll produce <code>...</code> output. But when using spaces it'll use <pre><code>...</code</pre>. We're counting on that behaviour to make decisions.

@nicholasserra
Copy link
Collaborator

The default code block formatting is to capture anything that is indented by 4 spaces. I'm wondering if the ones you're seeing that work are because of this?

@lc-soft
Copy link

lc-soft commented Aug 5, 2017

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from markdown2 import markdown as md
>>> text = '''
... ``` css
... @font-face {
...   font-family: 'my font';
...   src: '/path/to/font/file';
... }
... ```
... '''
>>> md(text, extras=['fenced-code-blocks'])
u"<p><code>css@font-face {\n   font-family: 'my font';\n   src: '/path/to/font/file';\n}\n</code></p>\n"

Why the result is not this?

u"<pre><code>@font-face {\n   font-family: 'my font';\n   src: '/path/to/font/file';\n}\n</code></pre>\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants