oscarmorrison / md-page

đź“ť create a webpage with just markdown
https://oscarmorrison.github.io/md-page/
MIT License
1.29k stars 99 forks source link

IE 11 issues #45

Closed p1ho closed 4 years ago

p1ho commented 4 years ago

It would appear that IE may require more polyfills than we initially thought. image I can try to get to the bottom of this.

Relevant:

43 #44

p1ho commented 4 years ago

Still doesn't work 100%... but no errors. This may need a deeper dive. image

p1ho commented 4 years ago

I have tried updating ./showdown.js from the showdown repo, but still doesn't change anything. I recommend testing out showdown's compatability with IE11 first, then we can go from there.

oscarmorrison commented 4 years ago

Yep sounds good. IE is a terrible browser. I don’t like accounting for it. So if people want a fix happy to accept PR. But not keen to do myself

oscarmorrison commented 4 years ago

Still doesn't work 100%... but no errors. This may need a deeper dive. image

Can you do a log of the showdown js

p1ho commented 4 years ago

sorry, what kind of log are you looking for?

oscarmorrison commented 4 years ago

Like the console output of this: https://github.com/oscarmorrison/md-page/blob/master/src/script.js#L86

To work out whether IE11 is being silly and not rendering the blocks, or because showdown is not working

p1ho commented 4 years ago

Yeah there's definitely something wrong with the way IE11 processes showdown. here's the test html

<script src="https://livejs.com/live.js"></script>
<script src="src/showdown.js"></script>
<script src="src/script.js"></script><noscript>

# test h1
## test h2
### test h3
#### test h4
##### test h5
###### test h6

IE 11 spits out

<p># test h1 ## test h2 ### test h3 #### test h4 ##### test h5 ###### test h6</p>

whereas the same file spits out the correct string in Chrome/Firefox

<h1 id="test-h1">test h1</h1>
<h2 id="test-h2">test h2</h2>
<h3 id="test-h3">test h3</h3>
<h4 id="test-h4">test h4</h4>
<h5 id="test-h5">test h5</h5>
<h6 id="test-h6">test h6</h6>
oscarmorrison commented 4 years ago

Yep. Thanks @p1ho wanted to work out what was exact error. Next steps would be to verify showdown normally works with IE11

can you try: http://demo.showdownjs.com/

If that works, then we should remove showdown manually dep, and use npm for it

p1ho commented 4 years ago

That works, yeah I'll try including it via npm, see if that works

oscarmorrison commented 4 years ago

sounds good, thankyou

p1ho commented 4 years ago

It doesn't work, it's still outputting the wrong string.

<script src="https://livejs.com/live.js"></script>
<script src="node_modules/showdown/dist/showdown.js"></script>
<script src="src/script.js"></script><noscript>
oscarmorrison commented 4 years ago

what about with:
https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js

oscarmorrison commented 4 years ago

then running in console

var converter = new showdown.Converter(),
    text      = '# hello, markdown!',
    html      = converter.makeHtml(text);
p1ho commented 4 years ago

^ That works!

oscarmorrison commented 4 years ago

So what about just

<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.9.1/showdown.min.js"></script>
<script src="src/script.js"></script><noscript>
p1ho commented 4 years ago

Found the problem, this line

    var markdown = document.querySelector('noscript').innerText

in IE 11 returns a string without new line

p1ho commented 4 years ago

Alright, I got it to work!

Basically, IE 11 will only preserve text formatting on text extraction for <pre> and <textarea>, we could try to use any of the 2 instead of <noscript>, but this breaks backward compatibility (people who still had <noscript> in their code will find that it stopped working).

So the trick is, when browser is IE 11, we clone the <noscript> text content into a <pre> (note: this preserves formatting because it's not text extraction), then extract text from the temp <pre> element.

image

Will open a PR

oscarmorrison commented 4 years ago

nice work. yeah that sounds good. i think its very important to be able to retain:

<script type="text/javascript" src="https://rawcdn.githack.com/oscarmorrison/md-page/abe58a8f057636e8d865324b5f5821c760f3f6e9/md-page.js"></script><noscript>
p1ho commented 4 years ago

As long as people have been using the following

<script src="https://rawcdn.githack.com/oscarmorrison/md-page/master/md-page.js"></script><noscript>

as instructed in the README.md, this shouldn't break anything for existing users.

oscarmorrison commented 4 years ago

can do it for ie only doing some like:

if (window.navigator.userAgent.indexOf("MSIE ")){
}
p1ho commented 4 years ago

@ji-ryoo You should be able to use it in IE 11 no problem now, feel free to open issues if you find something else not working. Thanks for letting us know.

Note: the rawcdn link might take time to refresh, give it a bit of time.

Edit: https://oscarmorrison.com/md-page/ works on my machine now

oscarmorrison commented 4 years ago

Nice work @p1ho

Closed in #47