all repos — min @ 1dcfc447fd65cabb7a060c745a1642ff64d79c4a

A small but practical concatenative programming language.

Implemented xentity2utf8
h3rald h3rald@h3rald.com
Sat, 04 May 2024 15:36:51 +0200
commit

1dcfc447fd65cabb7a060c745a1642ff64d79c4a

parent

b5ffbb3c191c4d881ed540407773713ca9152ec7

4 files changed, 23 insertions(+), 0 deletions(-)

jump to
M minpkg/lib/min_xml.nimminpkg/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.mdnext-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.mdsite/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.mintests/xml.min

@@ -40,5 +40,9 @@ "<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 + ( + "&gt;" xentity xentity2utf8 ">" == + ) *test/assert + *test/report clear-stack