mdbook_plotly/preprocessor/handlers/
code_handler.rs1pub mod plot_obj_parser;
2pub mod until;
3
4use crate::preprocessor::config::PlotlyInputType;
5use anyhow::Result;
6use log::{debug, warn};
7use plotly::Plot;
8use serde_json::Value;
9
10pub fn handle(raw_code: String, input_type: &PlotlyInputType) -> Result<Plot> {
11 let result = match input_type {
12 PlotlyInputType::SandBoxScript => {
13 warn!("The entry has been discarded. This config shouldn't be used.");
14 debug!("This function returns an empty string.");
15 Plot::new()
17 }
18 PlotlyInputType::JSONInput => handle_json_input(raw_code)?,
19 };
20 Ok(result)
21}
22
23pub fn handle_json_input(raw_code: String) -> Result<Plot> {
31 let mut value: Value = json5::from_str(&raw_code)?;
33 plot_obj_parser::parse(&mut value)
34}