Skip to content

Commit

Permalink
rehype-parse: fix support for <noscript> elements
Browse files Browse the repository at this point in the history
Apparently, they never really worked.
  • Loading branch information
wooorm committed Jun 10, 2018
1 parent 15a702b commit 0efaa14
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rehype-parse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ function parse(options) {
function parser(doc, file) {
var fn = settings.fragment ? 'parseFragment' : 'parse';
var onParseError = settings.emitParseErrors ? onerror : null;
var parse5 = new Parser5({sourceCodeLocationInfo: position, onParseError: onParseError});
var parse5 = new Parser5({
sourceCodeLocationInfo: position,
onParseError: onParseError,
scriptingEnabled: false
});

return fromParse5(parse5[fn](doc), {
file: file,
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/noscript/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!doctype html>
<h1>noscript!</h1>
<noscript><p>JavaScript isn’t enabled 😢</p></noscript>
<script>alert('JavaScript isn’t enabled 😢')</script>
230 changes: 230 additions & 0 deletions test/fixtures/noscript/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
{
"type": "root",
"children": [
{
"type": "doctype",
"name": "html",
"public": null,
"system": null,
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 16,
"offset": 15
}
}
},
{
"type": "element",
"tagName": "html",
"properties": {},
"children": [
{
"type": "element",
"tagName": "head",
"properties": {},
"children": []
},
{
"type": "element",
"tagName": "body",
"properties": {},
"children": [
{
"type": "element",
"tagName": "h1",
"properties": {},
"children": [
{
"type": "text",
"value": "noscript!",
"position": {
"start": {
"line": 2,
"column": 5,
"offset": 20
},
"end": {
"line": 2,
"column": 14,
"offset": 29
}
}
}
],
"position": {
"start": {
"line": 2,
"column": 1,
"offset": 16
},
"end": {
"line": 2,
"column": 19,
"offset": 34
}
}
},
{
"type": "text",
"value": "\n",
"position": {
"start": {
"line": 2,
"column": 19,
"offset": 34
},
"end": {
"line": 3,
"column": 1,
"offset": 35
}
}
},
{
"type": "element",
"tagName": "noscript",
"properties": {},
"children": [
{
"type": "element",
"tagName": "p",
"properties": {},
"children": [
{
"type": "text",
"value": "JavaScript isn’t enabled 😢",
"position": {
"start": {
"line": 3,
"column": 14,
"offset": 48
},
"end": {
"line": 3,
"column": 41,
"offset": 75
}
}
}
],
"position": {
"start": {
"line": 3,
"column": 11,
"offset": 45
},
"end": {
"line": 3,
"column": 45,
"offset": 79
}
}
}
],
"position": {
"start": {
"line": 3,
"column": 1,
"offset": 35
},
"end": {
"line": 3,
"column": 56,
"offset": 90
}
}
},
{
"type": "text",
"value": "\n",
"position": {
"start": {
"line": 3,
"column": 56,
"offset": 90
},
"end": {
"line": 4,
"column": 1,
"offset": 91
}
}
},
{
"type": "element",
"tagName": "script",
"properties": {},
"children": [
{
"type": "text",
"value": "alert('JavaScript isn’t enabled 😢')",
"position": {
"start": {
"line": 4,
"column": 9,
"offset": 99
},
"end": {
"line": 4,
"column": 45,
"offset": 135
}
}
}
],
"position": {
"start": {
"line": 4,
"column": 1,
"offset": 91
},
"end": {
"line": 4,
"column": 54,
"offset": 144
}
}
},
{
"type": "text",
"value": "\n",
"position": {
"start": {
"line": 4,
"column": 54,
"offset": 144
},
"end": {
"line": 5,
"column": 1,
"offset": 145
}
}
}
]
}
]
}
],
"data": {
"quirksMode": false
},
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 5,
"column": 1,
"offset": 145
}
}
}
4 changes: 4 additions & 0 deletions test/fixtures/noscript/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html><html><head></head><body><h1>noscript!</h1>
<noscript><p>JavaScript isn’t enabled 😢</p></noscript>
<script>alert('JavaScript isn’t enabled 😢')</script>
</body></html>

0 comments on commit 0efaa14

Please sign in to comment.