Merge branch 'Lompik-htmlparser' into devel
This commit is contained in:
commit
ccae58c5e2
2 changed files with 52 additions and 2 deletions
|
|
@ -464,12 +464,18 @@ proc untilElementEnd(x: var XmlParser, result: XmlNode,
|
||||||
case x.kind
|
case x.kind
|
||||||
of xmlElementStart, xmlElementOpen:
|
of xmlElementStart, xmlElementOpen:
|
||||||
case result.htmlTag
|
case result.htmlTag
|
||||||
of tagLi, tagP, tagDt, tagDd, tagInput, tagOption:
|
of tagP, tagInput, tagOption:
|
||||||
# some tags are common to have no ``</end>``, like ``<li>``:
|
# some tags are common to have no ``</end>``, like ``<li>`` but
|
||||||
|
# allow ``<p>`` in `<dd>`, `<dt>` and ``<li>`` in next case
|
||||||
if htmlTag(x.elemName) in {tagLi, tagP, tagDt, tagDd, tagInput,
|
if htmlTag(x.elemName) in {tagLi, tagP, tagDt, tagDd, tagInput,
|
||||||
tagOption}:
|
tagOption}:
|
||||||
errors.add(expected(x, result))
|
errors.add(expected(x, result))
|
||||||
break
|
break
|
||||||
|
of tagDd, tagDt, tagLi:
|
||||||
|
if htmlTag(x.elemName) in {tagLi, tagDt, tagDd, tagInput,
|
||||||
|
tagOption}:
|
||||||
|
errors.add(expected(x, result))
|
||||||
|
break
|
||||||
of tagTd, tagTh:
|
of tagTd, tagTh:
|
||||||
if htmlTag(x.elemName) in {tagTr, tagTd, tagTh, tagTfoot, tagThead}:
|
if htmlTag(x.elemName) in {tagTr, tagTd, tagTh, tagTfoot, tagThead}:
|
||||||
errors.add(expected(x, result))
|
errors.add(expected(x, result))
|
||||||
|
|
|
||||||
44
tests/stdlib/thtmlparser2814.nim
Normal file
44
tests/stdlib/thtmlparser2814.nim
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
discard """
|
||||||
|
output: true
|
||||||
|
"""
|
||||||
|
import htmlparser
|
||||||
|
import xmltree
|
||||||
|
import strutils
|
||||||
|
from streams import newStringStream
|
||||||
|
|
||||||
|
|
||||||
|
## builds the two cases below and test that
|
||||||
|
## ``//[dd,li]`` has "<p>that</p>" as children
|
||||||
|
##
|
||||||
|
## <dl>
|
||||||
|
## <dt>this</dt>
|
||||||
|
## <dd>
|
||||||
|
## <p>that</p>
|
||||||
|
## </dd>
|
||||||
|
## </dl>
|
||||||
|
|
||||||
|
##
|
||||||
|
## <ul>
|
||||||
|
## <li>
|
||||||
|
## <p>that</p>
|
||||||
|
## </li>
|
||||||
|
## </ul>
|
||||||
|
|
||||||
|
|
||||||
|
for ltype in [["dl","dd"], ["ul","li"]]:
|
||||||
|
let desc_item = if ltype[0]=="dl": "<dt>this</dt>" else: ""
|
||||||
|
let item = "$1<$2><p>that</p></$2>" % [desc_item, ltype[1]]
|
||||||
|
let list = """ <$1>
|
||||||
|
$2
|
||||||
|
</$1> """ % [ltype[0], item]
|
||||||
|
|
||||||
|
var errors : seq[string] = @[]
|
||||||
|
|
||||||
|
let parseH = parseHtml(newStringStream(list),"statichtml", errors =errors)
|
||||||
|
|
||||||
|
if $parseH.findAll(ltype[1])[0].child("p") != "<p>that</p>":
|
||||||
|
echo "case " & ltype[0] & " failed !"
|
||||||
|
quit(2)
|
||||||
|
|
||||||
|
|
||||||
|
echo "true"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue