This commit is contained in:
		@@ -37,11 +37,12 @@ pub type Element {
 | 
			
		||||
  Element(name: String, attrs: List(Attribute), elements: List(Element))
 | 
			
		||||
  Text(content: String)
 | 
			
		||||
  Comment(content: String)
 | 
			
		||||
  CData(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='&'/><!-- ma comment --></b>",
 | 
			
		||||
    "<?xml version=\"1.1\" encoding='UTF-8'?>\r\n   <!-- hello-world -->   \n<b><a attr='ha &#38;ha' battr='baba' ref='&'/><!-- ma comment --><![CDATA[Testing&&<haha>]]></b>",
 | 
			
		||||
  )
 | 
			
		||||
  |> echo
 | 
			
		||||
}
 | 
			
		||||
@@ -158,6 +159,7 @@ fn parse_content(
 | 
			
		||||
                Error(_) -> Error(Nil)
 | 
			
		||||
              }
 | 
			
		||||
            },
 | 
			
		||||
            parse_cdata,
 | 
			
		||||
          ],
 | 
			
		||||
          doc,
 | 
			
		||||
        )
 | 
			
		||||
@@ -170,6 +172,30 @@ fn parse_content(
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn parse_cdata(doc: String) -> Result(#(Element, String), Nil) {
 | 
			
		||||
  case doc {
 | 
			
		||||
    "<![CDATA[" <> tail -> {
 | 
			
		||||
      use #(cdata, doc) <- result.try(do_parse_cdata(tail, ""))
 | 
			
		||||
 | 
			
		||||
      Ok(#(CData(cdata), doc))
 | 
			
		||||
    }
 | 
			
		||||
    _ -> Error(Nil)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn do_parse_cdata(doc: String, cdata: String) -> Result(#(String, String), Nil) {
 | 
			
		||||
  case doc {
 | 
			
		||||
    "]]>" <> tail -> Ok(#(cdata, tail))
 | 
			
		||||
    "" -> Error(Nil)
 | 
			
		||||
    _ -> {
 | 
			
		||||
      case parse_char(doc) {
 | 
			
		||||
        Ok(#(char, doc)) -> do_parse_cdata(doc, cdata <> char)
 | 
			
		||||
        _ -> Error(Nil)
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn parse_chardata(
 | 
			
		||||
  doc: String,
 | 
			
		||||
  doctype: Option(DocType),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user