fix #14064 xmltree should allow create text node with raw text(non-es… (#14070)

* fix #14064 xmltree should allow create text node with raw text(non-escaped) eg. html style element's text

* change xnRawText to VerbatimText,newRawText to newVerbatimText ,add since anotation

* change changelog_1_2_0.md latest date

* move change log

Co-authored-by: bung87 <crc32@qq.com>
This commit is contained in:
Bung
2020-04-23 01:46:55 +08:00
committed by GitHub
parent 6c0c882509
commit e1cc0219de
3 changed files with 12 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
## Standard library additions and changes
- Added `xmltree.newVerbatimText` support create `style`'s,`script`'s text.
- `uri` adds Data URI Base64, implements RFC-2397.
- Add [DOM Parser](https://developer.mozilla.org/en-US/docs/Web/API/DOMParser)
to the `dom` module for the JavaScript target.

View File

@@ -2,7 +2,6 @@
## Standard library additions and changes
- Added overloaded `strformat.fmt` macro that use specified characters as
delimiter instead of '{' and '}'.
- Added new procs in `tables.nim`: `OrderedTable.pop`, `CountTable.del`,

View File

@@ -35,6 +35,7 @@
## * `htmlgen module <htmlgen.html>`_ for html code generator
import macros, strtabs, strutils
include "system/inclrtl"
type
XmlNode* = ref XmlNodeObj ## An XML tree consisting of XML nodes.
@@ -44,6 +45,7 @@ type
XmlNodeKind* = enum ## Different kinds of XML nodes.
xnText, ## a text element
xnVerbatimText, ##
xnElement, ## an element with 0 or more children
xnCData, ## a CDATA node
xnEntity, ## an entity (like ``&thing;``)
@@ -56,7 +58,7 @@ type
XmlNodeObj {.acyclic.} = object
case k: XmlNodeKind # private, use the kind() proc to read this field.
of xnText, xnComment, xnCData, xnEntity:
of xnText, xnVerbatimText, xnComment, xnCData, xnEntity:
fText: string
of xnElement:
fTag: string
@@ -101,6 +103,12 @@ proc newText*(text: string): XmlNode =
result = newXmlNode(xnText)
result.fText = text
proc newVerbatimText*(text: string): XmlNode {.since:(1, 3).} =
## Creates a new ``XmlNode`` of kind ``xnVerbatimText`` with the text `text`.
## **Since**: Version 1.3.
result = newXmlNode(xnVerbatimText)
result.fText = text
proc newComment*(comment: string): XmlNode =
## Creates a new ``XmlNode`` of kind ``xnComment`` with the text `comment`.
runnableExamples:
@@ -646,6 +654,8 @@ proc add*(result: var string, n: XmlNode, indent = 0, indWidth = 2,
result.add(">")
of xnText:
result.addEscaped(n.fText)
of xnVerbatimText:
result.add(n.fText)
of xnComment:
result.add("<!-- ")
result.addEscaped(n.fText)