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 /// About the script source control.
26 /// If this is false(default), a JS script source from CDN will be injected;
27 /// otherwise, an HTML script tag containing an embedded JS source will be added for offline use.
28 pub offline_js_sources: bool,
29
30 /// Controls map expression evaluation behavior such as namespace visibility
31 /// and whether fasteval optimizations should be enabled.
32 pub map_eval: MapEvalConfig,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
36#[serde(default, rename_all = "kebab-case")]
37pub struct MapEvalConfig {
38 pub enabled: bool,
39 pub reuse_slab: bool,
40 pub compile_expressions: bool,
41 pub namespace_scope: MapNamespaceScope,
42}
43
44impl Default for MapEvalConfig {
45 fn default() -> Self {
46 Self {
47 enabled: true,
48 reuse_slab: true,
49 compile_expressions: true,
50 namespace_scope: MapNamespaceScope::FullMap,
51 }
52 }
53}
54
55#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
56#[serde(rename_all = "kebab-case")]
57pub enum MapNamespaceScope {
58 #[default]
59 FullMap,
60 ExportsOnly,
61}
62
63/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
64#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
65#[serde(rename_all = "kebab-case")]
66pub enum PlotlyOutputType {
67 /// After the code is executed, it is compiled into an `<div>` for display.
68 #[default]
69 #[cfg(feature = "plotly-html-handler")]
70 PlotlyHtml,
71
72 /// After the code is executed, it is compiled into an SVG for display.
73 #[cfg(feature = "plotly-svg-handler")]
74 PlotlySvg,
75}
76
77/// NOTE: These configurations are printed as kebab-case names. Please pay attention when using.
78#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
79#[serde(rename_all = "kebab-case")]
80pub enum PlotlyInputType {
81 /// Translates the Json format into an actual plotly object.
82 /// NOTE: In the `PlotlyOutputType = PlotlySvg` state, this method may cause some performance loss due to multiple packaging.
83 #[default]
84 JSONInput,
85}