yogthos/markdown-clj

Incorrect rendering of double hyphen within backqotes

deg opened this issue · 13 comments

deg commented

Everything within backquotes should be rendered literally, but it seems that markdown-clj is converting -- to a single en-dash.

Here's a line that fails:

* `./build-rxl-version.sh --release <release-name>` - Use release from
  `/acme/products/releases/rxl-je/Release/`.

Yeah that's a bug, the inline code should get escaped. I'll take a look.

Just pushed out 1.0.6 with the fix, let me know if it looks good on your end.

deg commented

No, sorry. It doesn't seem to have fixed the problem.

Here's the input line from my file:

* `./build-rbl-version.sh --release <release-name>` - Use release from
  `/basis/products/releases/rbl-je/Release/`.

And here's the generated html:

<li><code>./build-rbl-version.sh –release &lt;release-name&gt;</code> - Use release from  <code>/basis/products/releases/rbl-je/Release/</code>.</li>

Here's what I'm seeing with the latest version:

"<ul><li><code>./build-rbl-version.sh --release &lt;release-name&gt;</code> - Use release from  <code>/basis/products/releases/rbl-je/Release/</code>.</li></ul>"

You might need to clear the local maven cache in ~/.m2/repository/markdown-clj, and check that an older version isn't being pulled in. If you're using Leiningen, you can run lein deps :tree to see what versions of the libraries are being used.

deg commented

I'm running 1.0.6. I've tried clearing the cache and confirmed with lein deps :tree

I do notice that triple-backquoted multiline code sections do retain the --. I'm only seeing a problem with single-backqoted singled lines.

I'm really not sure what's happening unfortunately as I'm not able to reproduce the issue locally. The reason this doesn't affect code blocks is because the parser is able to set the state to code and omit other formatting. However, for inline blocks there's no state as the whole line is processed in one shot.

The fix here uses a regex to unparse the dashes, and it's passing in the unit test I added. I tried running your example locally and I'm seeing the -- inside the escaped code.

deg commented

Ok. I will try to debug this further, but probably won't be able to give it much time for at least the next couple of days.

Sounds good, I made a test project to test the issue. It's parsing markdown from both a string and a file, and appears to be working correctly with your sample input.

I'm also running into this now...

Might need to make an even smarter regex for this? :)

I did it like this:

markdown (str/replace markdown #"--" (fn [_]
                                               "$$NDASH$$"))

html (md/md-to-html-string markdown)
        ;; see issue https://github.com/yogthos/markdown-clj/issues/146
        html (str/replace html "$$NDASH$$" "--")

Ah, this trick's already being used with freeze-string, so we could just use that here as well.

Just run across a bug in -- handling that might be related?

user=> (md-to-html-string "Does this -- change to an endash?")
"<p>Does this &ndash; change to an endash?</p>"
user=> (md-to-html-string "Does <code>this</code> -- change to an endash?")
"<p>Does <code>this</code> &ndash; change to an endash?</p>"
user=> (md-to-html-string "Does <code>this</code> -- change to an <code>endash</code>?")
"<p>Does <code>this</code> -- change to an <code>endash</code>?</p>"
user=>
``` This is with markdown-clj 1.11.4 and I think it's because the regex you use to undo the -- to ndash inside `<code>` is greedy: so if there are multiple `<code>` blocks, any `--` that had been converted to `ndash` outside them gets converted back.