added XML parser
This commit is contained in:
parent
44fd298edb
commit
8d93e6473e
@ -23,7 +23,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#let load(path-or-schema, config: auto) = {
|
#let parse-raw(schema) = {
|
||||||
|
let lang = schema.lang
|
||||||
|
let content = schema.text
|
||||||
|
if not lang in valid-extensions {
|
||||||
|
let fmts = valid-extensions.map(fmt => "." + fmt).join(", ")
|
||||||
|
fmts = "(" + fmts + ")"
|
||||||
|
panic("Unsupported format '" + lang + "'. Valid formats: " + fmts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if lang == "yaml" {
|
||||||
|
return yaml.decode(content)
|
||||||
|
} else if lang == "json" {
|
||||||
|
return json.decode(content)
|
||||||
|
} else if lang == "xml" {
|
||||||
|
return xml-loader.parse(xml.decode(content).first())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#let load(path-or-schema) = {
|
||||||
let schema = if type(path-or-schema) == str {
|
let schema = if type(path-or-schema) == str {
|
||||||
parse-file(path-or-schema)
|
parse-file(path-or-schema)
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,8 +81,7 @@
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#let load(path) = {
|
#let parse(content) = {
|
||||||
let content = xml(path).first()
|
|
||||||
let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure")
|
let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure")
|
||||||
|
|
||||||
let structures = (:)
|
let structures = (:)
|
||||||
@ -98,3 +97,8 @@
|
|||||||
structures: structures
|
structures: structures
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#let load(path) = {
|
||||||
|
let content = xml(path).first()
|
||||||
|
return parse(content)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user