use crate::core::environment::EscapeState;
use crate::core::exec::{outcome_from_run, ExecOutcome};
use crate::core::Element;
use crate::error::Result;
use std::rc::Rc;
pub struct EscapeBlock {
pub expr: crate::core::Expr,
pub body: Vec<Element>,
}
impl EscapeBlock {
pub fn new(expr: crate::core::Expr, body: Vec<Element>) -> Self {
EscapeBlock { expr, body }
}
pub(crate) fn exec(&self, env: &mut crate::core::Environment) -> Result<ExecOutcome> {
let state = match &self.expr.kind {
crate::core::ExprKind::Ident(n) if n == "html" => EscapeState::Html,
crate::core::ExprKind::Ident(n) if n == "xml" => EscapeState::Xml,
crate::core::ExprKind::Ident(n) if n == "xhtml" => EscapeState::Html, _ => EscapeState::Custom(Rc::new(self.expr.clone())),
};
env.push_escape(state);
let r = env.run(&self.body);
env.pop_escape();
outcome_from_run(r)
}
}