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

Incorrect rendering of double hyphen within backqotes #146

Open
deg opened this issue Jan 10, 2019 · 13 comments
Open

Incorrect rendering of double hyphen within backqotes #146

deg opened this issue Jan 10, 2019 · 13 comments

Comments

@deg
Copy link

deg commented Jan 10, 2019

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/`.
@yogthos
Copy link
Owner

yogthos commented Jan 10, 2019

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

@yogthos
Copy link
Owner

yogthos commented Jan 11, 2019

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

@deg
Copy link
Author

deg commented Jan 11, 2019

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>

@yogthos
Copy link
Owner

yogthos commented Jan 11, 2019

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
Copy link
Author

deg commented Jan 12, 2019

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.

@yogthos
Copy link
Owner

yogthos commented Jan 13, 2019

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
Copy link
Author

deg commented Jan 13, 2019

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.

@yogthos
Copy link
Owner

yogthos commented Jan 13, 2019

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.

@borkdude
Copy link
Contributor

I'm also running into this now...

@yogthos
Copy link
Owner

yogthos commented Jun 24, 2022

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

@borkdude
Copy link
Contributor

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$$" "--")

@yogthos
Copy link
Owner

yogthos commented Jun 24, 2022

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

@seancorfield
Copy link

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.

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

No branches or pull requests

4 participants