This commit is contained in:
@@ -36,11 +36,12 @@ pub type Element {
|
|||||||
EmptyElem(name: String, attrs: List(Attribute))
|
EmptyElem(name: String, attrs: List(Attribute))
|
||||||
Element(name: String, attrs: List(Attribute), elements: List(Element))
|
Element(name: String, attrs: List(Attribute), elements: List(Element))
|
||||||
Text(content: String)
|
Text(content: String)
|
||||||
|
Comment(content: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
parse_document(
|
parse_document(
|
||||||
"<?xml version=\"1.1\" encoding='UTF-8'?>\r\n <!-- hello-world --> \n<b><a attr='ha &#38;ha' battr='baba' ref='&'/></b>",
|
"<?xml version=\"1.1\" encoding='UTF-8'?>\r\n <!-- hello-world --> \n<b><a attr='ha &#38;ha' battr='baba' ref='&'/><!-- ma comment --></b>",
|
||||||
)
|
)
|
||||||
|> echo
|
|> echo
|
||||||
}
|
}
|
||||||
@@ -147,7 +148,20 @@ fn parse_content(
|
|||||||
|
|
||||||
case doc {
|
case doc {
|
||||||
"<" <> _ -> {
|
"<" <> _ -> {
|
||||||
case try_parsers([parse_element(_, doctype)], doc) {
|
case
|
||||||
|
try_parsers(
|
||||||
|
[
|
||||||
|
parse_element(_, doctype),
|
||||||
|
fn(doc) {
|
||||||
|
case parse_comment(doc) {
|
||||||
|
Ok(#(comment, doc)) -> Ok(#(Comment(comment), doc))
|
||||||
|
Error(_) -> Error(Nil)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
doc,
|
||||||
|
)
|
||||||
|
{
|
||||||
Ok(#(element, doc)) -> parse_content(doc, doctype, [element, ..content])
|
Ok(#(element, doc)) -> parse_content(doc, doctype, [element, ..content])
|
||||||
Error(_) -> Ok(#(list.reverse(new_content), doc))
|
Error(_) -> Ok(#(list.reverse(new_content), doc))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user