all repos — min @ b5ffbb3c191c4d881ed540407773713ca9152ec7

A small but practical concatenative programming language.

Implemented from-html.
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:20:47 +0200
commit

b5ffbb3c191c4d881ed540407773713ca9152ec7

parent

1b234efce79339aa3afcf847a8b5db569aa3f735

4 files changed, 21 insertions(+), 1 deletions(-)

jump to
M minpkg/lib/min_xml.nimminpkg/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.mdnext-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.mdsite/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.mintests/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>&copy</i>" from-html :xnode + xnode to-xml "<document>\n <b>this is a test</b>\n <img src=\"test.jpg\" />\n <i>&amp;copy</i>\n</document>" == + ) *test/assert + *test/report clear-stack