Implemented xentity2utf8
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:36:51 +0200
4 files changed,
23 insertions(+),
0 deletions(-)
M
minpkg/lib/min_xml.nim
→
minpkg/lib/min_xml.nim
@@ -119,6 +119,13 @@ def.symbol("xentity") do (i: In):
let vals = i.expect("'sym") i.push i.newXDict(newEntity(vals[0].getString)) + def.symbol("xentity2utf8") do (i: In): + let vals = i.expect("dict:xml-entity") + var entity = i.dget(vals[0], "text").getString + # Strip & and ; + entity = entity[1..entity.len-2] + i.push entity.entityToUtf8.newVal + def.symbol("xelement") do (i: In): let vals = i.expect("'sym") i.push i.newXDict(newElement(vals[0].getString))
M
next-release.md
→
next-release.md
@@ -2,4 +2,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. +- Added a new `xentity2utf8` symbol to the `xml` module to convert an XML entity to its corresponding UTF-8 string.
M
site/contents/reference-xml.md
→
site/contents/reference-xml.md
@@ -41,6 +41,17 @@
{#op||xentity||{{sl}}||{{xentity}}|| Returns a {{xentity}} representing an XML entity. #} +{#op||xentity2utf8||{{dict:xentity}}||{{s}}|| +> Returns the UTF-8 symbol corresponding to the specified XML entity. +> +> > %sidebar% +> > Example +> > +> > The following program prints `p` to the screen: +> > +> > ">" xentity xentity2utf8 puts + #} + {#op||xquery||{{xelement}} {{sl}}||{{xelement}}|| > Returns an {{xelement}} representing the first element matching CSS the selector {{sl}}. >
M
tests/xml.min
→
tests/xml.min
@@ -40,5 +40,9 @@ "<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 + ( + ">" xentity xentity2utf8 ">" == + ) *test/assert + *test/report clear-stack