This commit is contained in:
		@@ -36,11 +36,12 @@ pub type Element {
 | 
			
		||||
  EmptyElem(name: String, attrs: List(Attribute))
 | 
			
		||||
  Element(name: String, attrs: List(Attribute), elements: List(Element))
 | 
			
		||||
  Text(content: String)
 | 
			
		||||
  Comment(content: String)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn main() {
 | 
			
		||||
  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
 | 
			
		||||
}
 | 
			
		||||
@@ -147,7 +148,20 @@ fn parse_content(
 | 
			
		||||
 | 
			
		||||
  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])
 | 
			
		||||
        Error(_) -> Ok(#(list.reverse(new_content), doc))
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user