elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.55k stars 662 forks source link

elm reactor web page is corrupt if README includes <script> tag #1780

Open billstclair opened 6 years ago

billstclair commented 6 years ago

I was documenting how to set up ports for the soon-to-be-published billstclair/elm-websocket-client package, when I ran into this.

mkdir script-tag-bug
cd script-tag-bug
elm init
echo "    <script type='text/javascript' src='index.js'></script>" >README.md
elm reactor

Aim your browser at http://localhost:8000

My browser displays this:

\n", "project": { "type": "application", "source-directories": [ "src" ], "elm-version": "0.19.0", "dependencies": { "direct": { "elm/browser": "1.0.0", "elm/core": "1.0.0", "elm/html": "1.0.0" }, "indirect": { "elm/json": "1.0.0", "elm/time": "1.0.0", "elm/url": "1.0.0", "elm/virtual-dom": "1.0.0" } }, "test-dependencies": { "direct": {}, "indirect": {} } }, "exactDeps": { "elm/browser": "1.0.0", "elm/core": "1.0.0", "elm/html": "1.0.0", "elm/json": "1.0.0", "elm/time": "1.0.0", "elm/url": "1.0.0", "elm/virtual-dom": "1.0.0" } } });

Note that the <script> tag is indented by four spaces, meaning I expect it to be quoted code, rendered with a <pre> tag, or similar.

billstclair commented 6 years ago

The actual README that prompted me to create this issue is at https://github.com/billstclair/elm-websocket-client/tree/master/example

billstclair commented 6 years ago

I have discovered a workaround, If I change the closing </script> tag to <!/script>, it correctly displays the now-misspelled HTML (I swapped single and double quotes, since exclamation point is a special shell character inside double quotes):

mkdir script-tag-bug
cd script-tag-bug
elm init
 echo '    <script type="text/javascript" src="index.js"><!/script>' >README.md
elm reactor
badlydrawnrob commented 4 months ago

@billstclair I stumbled on this problem and it puzzled me for a good hour. Mine is wrapped in Markdown fenced code blocks. Such a weird little bug. Not so helpful if you need to write documentation in a README.

```html
<script>
// The name of the module
Elm.RefactorEnhance.Picshare04.init({
    node: document.getElementById('main') // the HTML element
});
</script>