From 5bac8cd8558048292bdc071fe09aa80191677719 Mon Sep 17 00:00:00 2001 From: Stephane Fontaine Date: Wed, 27 Jul 2016 15:14:34 +0400 Subject: [PATCH 1/3] htmlparser: Allow

as children of

and
  • --- lib/pure/htmlparser.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index fd58bed25d..1fe0b297ba 100644 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -464,12 +464,18 @@ proc untilElementEnd(x: var XmlParser, result: XmlNode, case x.kind of xmlElementStart, xmlElementOpen: case result.htmlTag - of tagLi, tagP, tagDt, tagDd, tagInput, tagOption: - # some tags are common to have no ````, like ``
  • ``: + of tagP, tagInput, tagOption: + # some tags are common to have no ````, like ``
  • `` but + # allow ``

    `` in `

    `, `
    ` and ``
  • `` in next case if htmlTag(x.elemName) in {tagLi, tagP, tagDt, tagDd, tagInput, tagOption}: errors.add(expected(x, result)) break + of tagDd, tagDt, tagLi: + if htmlTag(x.elemName) in {tagLi, tagDt, tagDd, tagInput, + tagOption}: + errors.add(expected(x, result)) + break of tagTd, tagTh: if htmlTag(x.elemName) in {tagTr, tagTd, tagTh, tagTfoot, tagThead}: errors.add(expected(x, result)) From fa537ee3a480823a251ca4fdf5442d2afe7a5afe Mon Sep 17 00:00:00 2001 From: Stephane Fontaine Date: Wed, 27 Jul 2016 21:24:51 +0400 Subject: [PATCH 2/3] htmlparser: Add test for paragraph inside --- tests/stdlib/thtmlparser2814.nim | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/stdlib/thtmlparser2814.nim diff --git a/tests/stdlib/thtmlparser2814.nim b/tests/stdlib/thtmlparser2814.nim new file mode 100644 index 0000000000..74c1a95563 --- /dev/null +++ b/tests/stdlib/thtmlparser2814.nim @@ -0,0 +1,38 @@ +discard """ + output: "@[]" +""" +import htmlparser +import xmltree +import strutils +from streams import newStringStream + + +## builds the two cases below and test that +## ``//[dd,li]`` has "

    that

    " as children +## +##
    +##
    this
    +##
    +##

    that

    +##
    +##
    + +## +##
      +##
    • +##

      that

      +##
    • +##
    + +for ltype in [["dl","dd"], ["ul","li"]]: + let desc_item = if ltype[0]=="dl": "
    this
    " else: "" + let item = "$1<$2>

    that

    " % [desc_item, ltype[1]] + let list = """ <$1> + $2 + """ % [ltype[0], item] + + var errors : seq[string] = @[] + + let parseH = parseHtml(newStringStream(list),"statichtml", errors =errors) + + echo $parseH.findAll(ltype[1])[0].child("p") == "

    that

    " From 48867b2541d561a85daf54f2e62f6b765b22ea5d Mon Sep 17 00:00:00 2001 From: Stephane Fontaine Date: Thu, 28 Jul 2016 20:25:12 +0400 Subject: [PATCH 3/3] Update htmlparser test ``output`` variable --- tests/stdlib/thtmlparser2814.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/stdlib/thtmlparser2814.nim b/tests/stdlib/thtmlparser2814.nim index 74c1a95563..968d390f13 100644 --- a/tests/stdlib/thtmlparser2814.nim +++ b/tests/stdlib/thtmlparser2814.nim @@ -1,5 +1,5 @@ discard """ - output: "@[]" + output: true """ import htmlparser import xmltree @@ -24,6 +24,7 @@ from streams import newStringStream ##
  • ## + for ltype in [["dl","dd"], ["ul","li"]]: let desc_item = if ltype[0]=="dl": "
    this
    " else: "" let item = "$1<$2>

    that

    " % [desc_item, ltype[1]] @@ -35,4 +36,9 @@ for ltype in [["dl","dd"], ["ul","li"]]: let parseH = parseHtml(newStringStream(list),"statichtml", errors =errors) - echo $parseH.findAll(ltype[1])[0].child("p") == "

    that

    " + if $parseH.findAll(ltype[1])[0].child("p") != "

    that

    ": + echo "case " & ltype[0] & " failed !" + quit(2) + + +echo "true"