bugfixes: re; pegs module
This commit is contained in:
parent
230567588b
commit
ddb7185482
13 changed files with 97 additions and 72 deletions
|
|
@ -1044,10 +1044,20 @@ proc target*(PI: PProcessingInstruction): string =
|
|||
|
||||
# --Other stuff--
|
||||
# Writer
|
||||
proc addEscaped(s: string): string =
|
||||
result = ""
|
||||
for c in items(s):
|
||||
case c
|
||||
of '<': result.add("<")
|
||||
of '>': result.add(">")
|
||||
of '&': result.add("&")
|
||||
of '"': result.add(""")
|
||||
else: result.add(c)
|
||||
|
||||
proc nodeToXml(n: PNode, indent: int = 0): string =
|
||||
result = repeatChar(indent, ' ') & "<" & n.nodeName
|
||||
for i in items(n.Attributes):
|
||||
result.add(" " & i.name & "=\"" & i.value & "\"")
|
||||
result.add(" " & i.name & "=\"" & addEscaped(i.value) & "\"")
|
||||
|
||||
if n.childNodes.len() == 0:
|
||||
result.add("/>") # No idea why this doesn't need a \n :O
|
||||
|
|
@ -1060,7 +1070,7 @@ proc nodeToXml(n: PNode, indent: int = 0): string =
|
|||
result.add(nodeToXml(i, indent + 2))
|
||||
of TextNode:
|
||||
result.add(repeatChar(indent * 2, ' '))
|
||||
result.add(i.nodeValue)
|
||||
result.add(addEscaped(i.nodeValue))
|
||||
of CDataSectionNode:
|
||||
result.add(repeatChar(indent * 2, ' '))
|
||||
result.add("<![CDATA[" & i.nodeValue & "]]>")
|
||||
|
|
@ -1080,4 +1090,4 @@ proc nodeToXml(n: PNode, indent: int = 0): string =
|
|||
proc `$`*(doc: PDocument): string =
|
||||
## Converts a PDocument object into a string representation of it's XML
|
||||
result = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||
result.add(nodeToXml(doc.documentElement))
|
||||
result.add(nodeToXml(doc.documentElement))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue