Implemented from-html.
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:20:47 +0200
4 files changed,
21 insertions(+),
1 deletions(-)
M
minpkg/lib/min_xml.nim
→
minpkg/lib/min_xml.nim
@@ -3,6 +3,7 @@ import
std/[xmlparser, xmltree, parsexml, + htmlparser, strtabs, critbits] import@@ -87,6 +88,16 @@ let s = vals[0].getString()
try: let xml = parseXml(s, {reportComments, allowUnquotedAttribs, allowEmptyAttribs}) + i.push(i.newXDict(xml)) + except CatchableError: + let msg = getCurrentExceptionMsg() + raiseInvalid(msg) + + def.symbol("from-html") do (i: In): + let vals = i.expect("str") + let s = vals[0].getString() + try: + let xml = parseHtml(s) i.push(i.newXDict(xml)) except CatchableError: let msg = getCurrentExceptionMsg()
M
next-release.md
→
next-release.md
@@ -1,4 +1,5 @@
### New Features - Added a new `color` symbol to the `io` module to enable/disable terminal color output. +- Added a new `from-html` symbol to the `xml` module to parse HTML documents and fragments.
M
site/contents/reference-xml.md
→
site/contents/reference-xml.md
@@ -4,8 +4,11 @@ title: "xml Module"
----- {@ _defs_.md || 0 @} +{#op||from-html||{{sl}}||{{xnode}}|| +Returns an {{xnode}} representing an HTML string (wrapped in a `<document>` tag unless a valid HTML document is provided as input).#} + {#op||from-xml||{{sl}}||{{xnode}}|| -> Returns an {{xnode}} representing an XML string representing an element or fragment. +> Returns an {{xnode}} representing an XML string (element or fragment). > > > %sidebar% > > Example
M
tests/xml.min
→
tests/xml.min
@@ -35,5 +35,10 @@ xnode "li.test" xqueryall
size 2 == ) *test/assert + ( + "<b>this is a test</b><img src='test.jpg'><i>©</i>" from-html :xnode + xnode to-xml "<document>\n <b>this is a test</b>\n <img src=\"test.jpg\" />\n <i>&copy</i>\n</document>" == + ) *test/assert + *test/report clear-stack