mdbook_plotly/preprocessor/config.rs
1use serde::{Deserialize, Serialize};
2
3pub const SUPPORTED_MDBOOK_VERSION: &str = "0.5.2";
4pub const PREPROCESSOR_CONFIG_KEY: &str = "preprocessor.plotly";
5
6/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
7#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
8#[serde(default, rename_all = "kebab-case")]
9pub struct PreprocessorConfig {
10 /// About the output form of the chart.
11 /// This output format may affect the presentation of the chart.
12 ///
13 /// In addition, in most cases, the different output forms can significantly affect the time at which the book is compiled.
14 ///
15 /// Other: The inner is an enumeration.
16 pub output_type: PlotlyOutputType,
17
18 /// About the input form of the chart.
19 ///
20 /// 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.
21 ///
22 /// 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.
23 pub input_type: PlotlyInputType,
24
25 /// Controls map expression evaluation behavior such as namespace visibility
26 /// and whether fasteval optimizations should be enabled.
27 pub map_eval: MapEvalConfig,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
31#[serde(default, rename_all = "kebab-case")]
32pub struct MapEvalConfig {
33 pub enabled: bool,
34 pub reuse_slab: bool,
35 pub compile_expressions: bool,
36 pub namespace_scope: MapNamespaceScope,
37}
38
39impl Default for MapEvalConfig {
40 fn default() -> Self {
41 Self {
42 enabled: true,
43 reuse_slab: true,
44 compile_expressions: true,
45 namespace_scope: MapNamespaceScope::FullMap,
46 }
47 }
48}
49
50#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
51#[serde(rename_all = "kebab-case")]
52pub enum MapNamespaceScope {
53 #[default]
54 FullMap,
55 ExportsOnly,
56}
57
58/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
59#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
60#[serde(rename_all = "kebab-case")]
61pub enum PlotlyOutputType {
62 /// After the code is executed, it is compiled into an `<div>` for display.
63 #[default]
64 #[cfg(feature = "plotly-html-handler")]
65 PlotlyHtml,
66
67 /// After the code is executed, it is compiled into an SVG for display.
68 #[cfg(feature = "plotly-svg-handler")]
69 PlotlySvg,
70}
71
72/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
73#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
74#[serde(rename_all = "kebab-case")]
75pub enum PlotlyInputType {
76 /// Translates the Json format into an actual plotly object.
77 /// NOTE: In the `PlotlyOutputType = PlotlySvg` state, this method may cause some performance loss due to multiple packaging.
78 #[default]
79 JSONInput,
80
81 /// Translates the TOML format into JSON value first, then reuses the existing plot parser.
82 TOMLInput,
83}