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

showdown.min.js interprets underscore in http links as italic #444

Closed
linw789 opened this issue Oct 11, 2017 · 6 comments
Closed

showdown.min.js interprets underscore in http links as italic #444

linw789 opened this issue Oct 11, 2017 · 6 comments
Assignees
Labels

Comments

@linw789
Copy link

linw789 commented Oct 11, 2017

<script type="text/javascript" src="showdown.min.js"></script>
<script>
    showdownMarker = new showdown.Converter({tasklists: "true"})
    let testDivElem = document.querySelector("#testdiv");
    testDivElem.innerHTML = showdownMarker.makeHtml("http://test_web_page.html");
</script>

The processed html will become something like this:
<p>http://test<em>web</em>page.html</p>
Event if simplifiedAutoLink is turned on.
This is found in the version 1.7.5.

@tivie
Copy link
Member

tivie commented Oct 11, 2017

Try the option literalmidwordunserscores

@tivie
Copy link
Member

tivie commented Oct 11, 2017

As stated in the documentation...

literalMidWordUnderscores: (boolean) [default false] Turning this on will stop showdown from interpreting underscores in the middle of words as <em> and <strong> and instead treat them as literal underscores.

@linw789
Copy link
Author

linw789 commented Oct 11, 2017

Sorry, I forgot to mention that underscores in http links are interpreted correctly in un-minified version. I tried it in the demo page. So I guess minifying the js files somehow introduced this bug?

@tivie tivie self-assigned this Oct 13, 2017
@tivie
Copy link
Member

tivie commented Oct 13, 2017

As I stated in my answer, you need to use the option literalMidWordUnderscores to prevent mid sentence underscores to be parsed as <em>.

If you check the options in the demo page (black panel on the left), you will see that, by default, literalMidWordUnderscores and simplifiedAutoLinks are turned on.

so this will work...

showdownMarker = new showdown.Converter({
    tasklists: true,
    simplifiedAutoLinks: true,
    literalMidWordUnderscores: true 
});
let testDivElem = document.querySelector("#testdiv");
testDivElem.innerHTML = showdownMarker.makeHtml("http://test_web_page.html");

@linw789
Copy link
Author

linw789 commented Oct 13, 2017

Thanks for the reply. Now I see where my confusion is.

In the demo page the first two link examples are parsed as raw texts and that's why even if I turned off literalMidWordUnderscores option the underscores are not re-interpreted.

Sorry about the time wasted.

@tivie
Copy link
Member

tivie commented Oct 24, 2017

Showdown is now smarter fetching links. You should be able to use simplifiedAutoLinks without literalMidWordUnderscores to parse links such as http://www.example.com/some__foo__bar

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

No branches or pull requests

2 participants