use markdoc::ast::Node;
use markdoc::markdown_it::Token;
use markdoc::next::index;
use markdoc::next::parser::ParserArgs;
use serde_json::{Map, Value};
pub fn parse(tokens: &[Token], src: &str, args: &Map<String, Value>) -> Result<Node, String> {
let args = ParserArgs {
file: args.get("file").and_then(Value::as_str).map(str::to_owned),
slots: args.get("slots").and_then(Value::as_bool).unwrap_or(false),
location: args.get("location").and_then(Value::as_bool) != Some(false),
conditional_tags: args
.get("conditionalTags")
.and_then(Value::as_array)
.map(|tags| {
tags.iter()
.filter_map(|t| t.as_str().map(str::to_owned))
.collect()
}),
..ParserArgs::default()
};
index::parse_tokens(tokens, src, &args).map_err(|e| index::thrown(&e).to_owned())
}