mdbook_plotly/preprocessor/handlers/
plotly_html_handler.rs1use plotly::Plot;
2use pulldown_cmark::Event;
3
4pub fn handle(code: Plot) -> Event<'static> {
5 Event::Html(code.to_inline_html(None).into())
6}
7
8fn trim_leading_spaces(text: &mut String) {
9 let mut out = String::with_capacity(text.len());
10 for (idx, line) in text.lines().enumerate() {
11 if idx > 0 {
12 out.push('\n');
13 }
14 out.push_str(line.trim_start());
15 }
16 *text = out;
17}
18
19pub fn inject_header() -> Event<'static> {
20 let mut html: String = Plot::online_cdn_js();
21 trim_leading_spaces(&mut html);
22 Event::Html(html.into())
23}