mdbook_plotly/preprocessor/config.rs
1use serde::{Deserialize, Serialize};
2
3pub const SUPPORTED_MDBOOK_VERSION: &str = "0.5.2";
4
5/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
6#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(default, rename_all = "kebab-case")]
8pub struct PreprocessorConfig {
9 /// About the output form of the chart.
10 /// This output format may affect the presentation of the chart.
11 ///
12 /// In addition, in most cases, the different output forms can significantly affect the time at which the book is compiled.
13 ///
14 /// Other: The inner is an enumeration.
15 pub output_type: PlotlyOutputType,
16
17 /// About the input form of the chart.
18 ///
19 /// Charts are usually in the form of code in a markdown document. At the time of input, we allow the code to be presented in different forms.
20 ///
21 /// The two forms we consider for adoption are: a general script and a configuration file organized in a specific form. In theory, you can read and operate files directly from the current path by turning on some of the functions that come with MDBook.
22 pub input_type: PlotlyInputType,
23
24 /// About the script source control.
25 /// If this is false(default), a JS script source from CDN will be injected;
26 /// otherwise, an HTML script tag containing an embedded JS source will be added for offline use.
27 pub offline_js_sources: bool,
28}
29
30/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
31#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
32#[serde(rename_all = "kebab-case")]
33pub enum PlotlyOutputType {
34 /// After the code is executed, it is compiled into an `<div>` for display.
35 #[default]
36 #[cfg(feature = "plotly-html-handler")]
37 PlotlyHtml,
38
39 /// After the code is executed, it is compiled into an SVG for display.
40 #[cfg(feature = "plotly-svg-handler")]
41 PlotlySvg,
42}
43
44/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
45#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
46#[serde(rename_all = "kebab-case")]
47pub enum PlotlyInputType {
48 /// Translates the Json format into an actual plotly object.
49 /// NOTE: In the `PlotlyOutputType = PlotlySvg` state, this method may cause some performance loss due to multiple packaging.
50 #[default]
51 JSONInput,
52
53 /// NOTE: This entry is deprecated because the use of `rquickjs` was abandoned.
54 /// Execute the script locally in a sandbox, either for preprocessing or to complete the compilation directly.
55 /// Once processed, follow the target output type.
56 SandBoxScript,
57}