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

Emphasis extent wrong when more than one per line #43

Closed
tshinnic opened this issue Sep 27, 2011 · 1 comment
Closed

Emphasis extent wrong when more than one per line #43

tshinnic opened this issue Sep 27, 2011 · 1 comment

Comments

@tshinnic
Copy link

I was trying to figure out which markdown was being used by a project, and so ended up comparing the output of markdown (python-markdown-2.0.3-3.fc15.noarch) with markdown2 (python-markdown2-1.0.1.17-3.fc15.noarch). I found that both got some emphasis wrong. I'll mention both here for orientation.

Did a diff between markdown2 and markdown outputs, so second line is markdown's. Before each I put the original source line:

To alter the environment we can set the _NODE_ENV_ environment variable, for example:

106,108c81
<
< <p>To alter the environment we can set the <em>NODE</em>ENV_ environment variable, for example:</p>
<

---
> <p>To alter the environment we can set the <em>NODE_ENV</em> environment variable, for example:</p>


Note that this method _end()_s the response, so you will want to use node's _res.write()_ for multiple writes or streaming.

971,973c738
<
< <p>Note that this method <em>end()</em>s the response, so you will want to use node's <em>res.write()</em> for multiple writes or streaming.</p>
<

---
> <p>Note that this method <em>end()_s the response, so you will want to use node's _res.write()</em> for multiple writes or streaming.</p>


connections will be accepted via _INADDR_ANY_.

1490,1491c1130
< connections will be accepted via <em>INADDR</em>ANY_.</p>
<

---
> connections will be accepted via <em>INADDR_ANY</em>.</p>

markdown2 is getting it wrong when handling tokens that have embedded '' characters, such as NODE_ENV and INADDR_ANY. Apparently it is using lazy regexs excluding '' characters.

But then markdown gets this line wrong, apparently because it is using greedy RE matching and allowing '_' characters:

Note that this method _end()_s the response, so you will want to use node's _res.write()_ for multiple writes or streaming.

The result desired was obviously as what markdown2 ended up producing.

How do you have more than one emphasis span on a line?

Ahh, got it! Changing _end()_s to _end()_'s produces <em>end()</em>'s as desired. That changed the interior '' to an ending ''.

You wouldn't believe how many times I've been told not to add 'extra' apostrophes in my writing. Now I know why I want to...

Oh, boo. Changing it to _end()_\s gives you <em>end()</em>s . Since that's closer to what the author wrote, that's better? (So I'm back to "okay, okay, I'll take out the apostrophes!")

Is there some kind of "when things don't work" FAQ you could add this to?

@waylan
Copy link
Member

waylan commented Oct 6, 2011

First of all, Markdown2 is a separate (unrelated) project from Python-Markdown. However, Python-Markdown is currently at version 2.0.3 with version 2.1.0 in alpha. I'm assuming that those two versions of Python-Markdown are what you are referring to rather than the Markdown2 project. Additionally, you appear to be using versions provided by your OS's linux package system. I'm a little concerned that they would provide an alpha package like that - which may be causing some of your confusion.

In any event, it should be noted that version 2.1.0 is the next release after 2.0.3 and so it contains numerous bug fixes. Diffing the two simply shows the bugs we already fixed. Therefore, there is nothing to report. Once 2.1.0-Final is released (soonish), that will be the official version.

I have two suggestions for you though. First, you may want to check out the smart_emphasis keyword (documented here) that we added in 2.1.0. For example:

>>> markdown.markdown("_end()_s")
u'<p>_end()_s</p>'

>>> markdown.markdown("_end()_s", smart_emphasis=False)
u'<p><em>end()</em>s</p>'

However, I prefer to put code in code spans. Using your example:

>>> markdown.markdown("Note that this method `end()`s the response, so you will want to use node's `res.write()` ...")
<p>Note that this method <code>end()</code>s the response, so you will want to use node's <code>res.write()</code> ...</p>"

I think that works nicely with no tricks needed and in older (bugger) versions of Python-Markdown.

I'm closing this as no bug was reported.

@waylan waylan closed this as completed Oct 6, 2011
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

2 participants