Ai
3 Star 1 Fork 0

Gitee 极速下载/node-htmlparser

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/tautologistics/node-htmlparser
克隆/下载
parser.js 20.88 KB
一键复制 编辑 原始数据 按行查看 历史
Dean Mao 提交于 2012-05-02 11:33 +08:00 . make test a little better
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
/***********************************************
Copyright 2010 - 2012, Chris Winberry <chris@winberry.net>. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
***********************************************/
(function () {
var exports;
if (typeof(module) !== 'undefined' && typeof(module.exports) !== 'undefined') {
exports = module.exports;
} else {
exports = {};
if (!this.Tautologistics) {
this.Tautologistics = {};
}
if (!this.Tautologistics.NodeHtmlParser) {
this.Tautologistics.NodeHtmlParser = {};
}
if (!this.Tautologistics.NodeHtmlParser.Tests) {
this.Tautologistics.NodeHtmlParser.Tests = [];
}
this.Tautologistics.NodeHtmlParser.Tests.Parser = exports;
}
exports['plain text'] = {
data: ['This is the text']
, expected: [{ type: 'text', data: 'This is the text' }]
};
exports['simple tag'] = {
data: ['<div>']
, expected: [{ type: 'tag', name: 'div', raw: 'div' }]
};
exports['simple comment'] = {
data: ['<!-- content -->']
, expected: [{ type: 'comment', data: ' content ' }]
};
exports['simple cdata'] = {
data: ['<![CDATA[ content ]]>']
, expected: [{ type: 'cdata', data: ' content ' }]
};
exports['text before tag'] = {
data: ['xxx<div>']
, expected: [
{ type: 'text', data: 'xxx'},
{ type: 'tag', name: 'div', raw: 'div' }
]
};
exports['text after tag'] = {
data: ['<div>xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div' },
{ type: 'text', data: 'xxx'}
]
};
exports['text inside tag'] = {
data: ['<div>xxx</div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div' },
{ type: 'text', data: 'xxx'},
{ type: 'tag', name: '/div', raw: '/div' }
]
};
exports['attribute with single quotes'] = {
data: ['<div a=\'1\'>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=\'1\'' },
{ type: 'attr', name:'a', data: '1'}
]
};
exports['attribute with double quotes'] = {
data: ['<div a="1">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1"' },
{ type: 'attr', name:'a', data: '1'}
]
};
exports['attribute with no quotes'] = {
data: ['<div a=1>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=1' },
{ type: 'attr', name:'a', data: '1'}
]
};
exports['attribute with no value'] = {
data: ['<div wierd>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div wierd' },
{ type: 'attr', name:'wierd', data: null}
]
};
exports['attribute with no value, trailing text'] = {
data: ['<div wierd>xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div wierd' },
{ type: 'attr', name:'wierd', data: null},
{ type: 'text', data: 'xxx' }
]
};
exports['tag with multiple attributes'] = {
data: ['<div a="1" b="2">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1" b="2"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'}
]
};
exports['tag with multiple attributes, trailing text'] = {
data: ['<div a="1" b="2">xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1" b="2"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'text', data: 'xxx' }
]
};
exports['tag with mixed attributes #1'] = {
data: ['<div a=1 b=\'2\' c="3">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=1 b=\'2\' c="3"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes #2'] = {
data: ['<div a=1 b="2" c=\'3\'>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=1 b="2" c=\'3\'' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes #3'] = {
data: ['<div a=\'1\' b=2 c="3">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=\'1\' b=2 c="3"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes #4'] = {
data: ['<div a=\'1\' b="2" c=3>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=\'1\' b="2" c=3' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes #5'] = {
data: ['<div a="1" b=2 c=\'3\'>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1" b=2 c=\'3\'' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes #6'] = {
data: ['<div a="1" b=\'2\' c="3">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1" b=\'2\' c="3"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'}
]
};
exports['tag with mixed attributes, trailing text'] = {
data: ['<div a=1 b=\'2\' c="3">xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=1 b=\'2\' c="3"' },
{ type: 'attr', name:'a', data: '1'},
{ type: 'attr', name:'b', data: '2'},
{ type: 'attr', name:'c', data: '3'},
{ type: 'text', data: 'xxx' }
]
};
exports['self closing tag'] = {
data: ['<div/>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div/' },
{ type: 'tag', name: '/div', raw: null }
]
};
exports['self closing tag, trailing text'] = {
data: ['<div/>xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div/' },
{ type: 'tag', name: '/div', raw: null },
{ type: 'text', data: 'xxx' }
]
};
exports['self closing tag with spaces #1'] = {
data: ['<div />']
, expected: [
{ type: 'tag', name: 'div', raw: 'div /' },
{ type: 'tag', name: '/div', raw: null }
]
};
exports['self closing tag with spaces #2'] = {
data: ['<div/ >']
, expected: [
{ type: 'tag', name: 'div', raw: 'div/ ' },
{ type: 'tag', name: '/div', raw: null }
]
};
exports['self closing tag with spaces #3'] = {
data: ['<div / >']
, expected: [
{ type: 'tag', name: 'div', raw: 'div / ' },
{ type: 'tag', name: '/div', raw: null }
]
};
exports['self closing tag with spaces, trailing text'] = {
data: ['<div / >xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div / ' },
{ type: 'tag', name: '/div', raw: null },
{ type: 'text', data: 'xxx' }
]
};
exports['self closing tag with attribute'] = {
data: ['<div a=b />']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=b /' },
{ type: 'attr', name:'a', data: 'b'},
{ type: 'tag', name: '/div', raw: null }
]
};
exports['self closing tag with attribute, trailing text'] = {
data: ['<div a=b />xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a=b /' },
{ type: 'attr', name:'a', data: 'b'},
{ type: 'tag', name: '/div', raw: null },
{ type: 'text', data: 'xxx' }
]
};
exports['attribute missing close quote'] = {
data: ['<div a="1><span id="foo">xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div a="1><span id="foo' },
{ type: 'attr', name:'a', data: '1><span id='},
{ type: 'attr', name:'foo', data: null},
{ type: 'text', data: 'xxx'}
]
};
exports['text before complex tag'] = {
data: ['xxx<div yyy="123">']
, expected: [
{ type: 'text', data: 'xxx' },
{ type: 'tag', name: 'div', raw: 'div yyy="123"'},
{ type: 'attr', name: 'yyy', data: '123' }
]
};
exports['text after complex tag'] = {
data: ['<div yyy="123">xxx']
, expected: [
{ type: 'tag', name: 'div', raw: 'div yyy="123"'},
{ type: 'attr', name: 'yyy', data: '123' },
{ type: 'text', data: 'xxx' }
]
};
exports['text inside complex tag'] = {
data: ['<div yyy="123">xxx</div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div yyy="123"'},
{ type: 'attr', name: 'yyy', data: '123' },
{ type: 'text', data: 'xxx' },
{ type: 'tag', name: '/div', raw: '/div'}
]
};
exports['nested tags'] = {
data: ['<div><span></span></div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div'},
{ type: 'tag', name: 'span', raw: 'span'},
{ type: 'tag', name: '/span', raw: '/span'},
{ type: 'tag', name: '/div', raw: '/div'}
]
};
exports['nested tags with attributes'] = {
data: ['<div aaa="bbb"><span 123=\'456\'>xxx</span></div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div aaa="bbb"'},
{ type: 'attr', name: 'aaa', data: 'bbb' },
{ type: 'tag', name: 'span', raw: 'span 123=\'456\''},
{ type: 'attr', name: '123', data: '456' },
{ type: 'text', data: 'xxx' },
{ type: 'tag', name: '/span', raw: '/span'},
{ type: 'tag', name: '/div', raw: '/div'}
]
};
exports['comment inside tag'] = {
data: ['<div><!-- comment text --></div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div'},
{ type: 'comment', data: ' comment text '},
{ type: 'tag', name: '/div', raw: '/div'}
]
};
exports['cdata inside tag'] = {
data: ['<div><![CDATA[ CData content ]]></div>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div'},
{ type: 'cdata', data: ' CData content '},
{ type: 'tag', name: '/div', raw: '/div'}
]
};
exports['html inside comment'] = {
data: ['<!-- <div>foo</div> -->']
, expected: [{ type: 'comment', data: ' <div>foo</div> '}]
};
exports['transitional doctype'] = {
data: ['<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html></html>']
, expected: [
{ type: 'doctype', data: ' HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"'},
{ type: 'tag', name: 'html', raw: 'html' },
{ type: 'tag', name: '/html', raw: '/html' }
]
};
exports['html inside cdata'] = {
data: ['<![CDATA[ <div>foo</div> ]]>']
, expected: [{ type: 'cdata', data: ' <div>foo</div> '}]
};
exports['quotes in attribute #1'] = {
data: ['<div xxx=\'a"b\'>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div xxx=\'a"b\''},
{ type: 'attr', name: 'xxx', data: 'a"b' }
]
};
exports['quotes in attribute #2'] = {
data: ['<div xxx="a\'b">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div xxx="a\'b"'},
{ type: 'attr', name: 'xxx', data: 'a\'b' }
]
};
exports['brackets in attribute'] = {
data: ['<div xxx="</div>">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div xxx="</div>"'},
{ type: 'attr', name: 'xxx', data: '</div>' }
]
};
exports['unfinished simple tag #1'] = {
data: ['<div']
, expected: [{ type: 'tag', name: 'div', raw: 'div'}]
};
exports['unfinished simple tag #2'] = {
data: ['<div ']
, expected: [{ type: 'tag', name: 'div', raw: 'div '}]
};
exports['unfinished complex tag #1'] = {
data: ['<div foo="bar"']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo="bar"'},
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['unfinished complex tag #2'] = {
data: ['<div foo="bar" ']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo="bar" '},
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['unfinished comment #1'] = {
data: ['<!-- comment text']
, expected: [{ type: 'comment', data: ' comment text'}]
};
exports['unfinished comment #2'] = {
data: ['<!-- comment text ']
, expected: [{ type: 'comment', data: ' comment text '}]
};
exports['unfinished comment #3'] = {
data: ['<!-- comment text -']
, expected: [{ type: 'comment', data: ' comment text -'}]
};
exports['unfinished comment #4'] = {
data: ['<!-- comment text --']
, expected: [{ type: 'comment', data: ' comment text --'}]
};
exports['unfinished cdata #1'] = {
data: ['<![CDATA[ content']
, expected: [{ type: 'cdata', data: ' content'}]
};
exports['unfinished cdata #2'] = {
data: ['<![CDATA[ content ']
, expected: [{ type: 'cdata', data: ' content '}]
};
exports['unfinished cdata #3'] = {
data: ['<![CDATA[ content ]']
, expected: [{ type: 'cdata', data: ' content ]'}]
};
exports['unfinished cdata #4'] = {
data: ['<![CDATA[ content ]]']
, expected: [{ type: 'cdata', data: ' content ]]'}]
};
exports['unfinished attribute #1'] = {
data: ['<div foo="bar']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo="bar' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['unfinished attribute #2'] = {
data: ['<div foo="']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo="' },
{ type: 'attr', name: 'foo', data: null }
]
};
exports['spaces in tag #1'] = {
data: ['< div>']
, expected: [{ type: 'tag', name: 'div', raw: ' div' }]
};
exports['spaces in tag #2'] = {
data: ['<div >']
, expected: [{ type: 'tag', name: 'div', raw: 'div ' }]
};
exports['spaces in tag #3'] = {
data: ['< div >']
, expected: [{ type: 'tag', name: 'div', raw: ' div ' }]
};
exports['spaces in closing tag #1'] = {
data: ['< /div>']
, expected: [{ type: 'tag', name: '/div', raw: ' /div' }]
};
exports['spaces in closing tag #2'] = {
data: ['</ div>']
, expected: [{ type: 'tag', name: '/div', raw: '/ div' }]
};
exports['spaces in closing tag #3'] = {
data: ['</div >']
, expected: [{ type: 'tag', name: '/div', raw: '/div ' }]
};
exports['spaces in closing tag #4'] = {
data: ['< / div >']
, expected: [{ type: 'tag', name: '/div', raw: ' / div ' }]
};
exports['spaces in tag, trailing text'] = {
data: ['< div >xxx']
, expected: [
{ type: 'tag', name: 'div', raw: ' div ' },
{ type: 'text', data: 'xxx' }
]
};
exports['spaces in attributes #1'] = {
data: ['<div foo ="bar">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo ="bar"' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['spaces in attributes #2'] = {
data: ['<div foo= "bar">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo= "bar"' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['spaces in attributes #3'] = {
data: ['<div foo = "bar">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo = "bar"' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['spaces in attributes #4'] = {
data: ['<div foo =bar>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo =bar' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['spaces in attributes #5'] = {
data: ['<div foo= bar>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo= bar' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['spaces in attributes #6'] = {
data: ['<div foo = bar>']
, expected: [
{ type: 'tag', name: 'div', raw: 'div foo = bar' },
{ type: 'attr', name: 'foo', data: 'bar' }
]
};
exports['mixed case tag'] = {
data: ['<diV>']
, expected: [{ type: 'tag', name: 'diV', raw: 'diV' }]
};
exports['upper case tag'] = {
data: ['<DIV>']
, expected: [{ type: 'tag', name: 'DIV', raw: 'DIV' }]
};
exports['mixed case attribute'] = {
data: ['<div xXx="yyy">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div xXx="yyy"' },
{ type: 'attr', name: 'xXx', data: 'yyy' }
]
};
exports['upper case case attribute'] = {
data: ['<div XXX="yyy">']
, expected: [
{ type: 'tag', name: 'div', raw: 'div XXX="yyy"' },
{ type: 'attr', name: 'XXX', data: 'yyy' }
]
};
exports['multiline simple tag'] = {
data: ["<\ndiv\n>"]
, expected: [
{ type: 'tag', name: 'div', raw: "\ndiv\n" }
]
};
exports['multiline complex tag'] = {
data: ["<\ndiv\nid='foo'\n>"]
, expected: [
{ type: 'tag', name: 'div', raw: "\ndiv\nid='foo'\n" },
{ type: 'attr', name: 'id', data: 'foo' }
]
};
exports['multiline comment'] = {
data: ["<!--\ncomment text\n-->"]
, expected: [
{ type: 'comment', data: "\ncomment text\n" }
]
};
exports['cdata comment'] = {
data: ["<![CDATA[\nCData content\n]]>"]
, expected: [
{ type: 'cdata', data: "\nCData content\n" }
]
};
exports['multiline attribute #1'] = {
data: ["<div id='\nxxx\nyyy\n'>"]
, expected: [
{ type: 'tag', name: 'div', raw: "div id='\nxxx\nyyy\n'" },
{ type: 'attr', name: 'id', data: "\nxxx\nyyy\n" }
]
};
exports['multiline attribute #2'] = {
data: ["<div id=\"\nxxx\nyyy\n\">"]
, expected: [
{ type: 'tag', name: 'div', raw: "div id=\"\nxxx\nyyy\n\"" },
{ type: 'attr', name: 'id', data: "\nxxx\nyyy\n" }
]
};
exports['tags in script tag code'] = {
data: ["<script language='javascript'>\nvar foo = '<bar>xxx</bar>';\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\nvar foo = '<bar>xxx</bar>';\n" },
{ type: 'tag', name: '/script', raw: "/script" },
]
};
exports['closing script tag in script tag code'] = {
data: ["<script language='javascript'>\nvar foo = '</script>';\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\nvar foo = '" },
{ type: 'tag', name: '/script', raw: "/script" },
{ type: 'text', data: "';\n" },
{ type: 'tag', name: '/script', raw: "/script" }
]
};
exports['comment in script tag code'] = {
data: ["<script language='javascript'>\nvar foo = '<!-- xxx -->';\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\nvar foo = '<!-- xxx -->';\n" },
{ type: 'tag', name: '/script', raw: "/script" },
]
};
exports['cdata in script tag code'] = {
data: ["<script language='javascript'>\nvar foo = '<![CDATA[ xxx ]]>';\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\nvar foo = '<![CDATA[ xxx ]]>';\n" },
{ type: 'tag', name: '/script', raw: "/script" },
]
};
exports['commented script tag code'] = {
data: ["<script language='javascript'>\n<!--\nvar foo = '<bar>xxx</bar>';\n//-->\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\n<!--\nvar foo = '<bar>xxx</bar>';\n//-->\n" },
{ type: 'tag', name: '/script', raw: "/script" },
]
};
exports['cdata in script tag'] = {
data: ["<script language='javascript'>\n<![CDATA[\nvar foo = '<bar>xxx</bar>';\n]]>\n</script>"]
, expected: [
{ type: 'tag', name: 'script', raw: "script language='javascript'" },
{ type: 'attr', name: 'language', data: 'javascript' },
{ type: 'text', data: "\n<![CDATA[\nvar foo = '<bar>xxx</bar>';\n]]>\n" },
{ type: 'tag', name: '/script', raw: "/script" },
]
};
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/node-htmlparser.git
git@gitee.com:mirrors/node-htmlparser.git
mirrors
node-htmlparser
node-htmlparser
master

搜索帮助