1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
//! Types about configuration.
#[cfg(feature = "config_serde")]
use serde::{Deserialize, Serialize};
use std::num::NonZeroUsize;
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase", default))]
/// The whole configuration of markup_fmt.
///
/// For detail, please refer to [Configuration](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md) on GitHub.
pub struct FormatOptions {
#[cfg_attr(feature = "config_serde", serde(flatten))]
pub layout: LayoutOptions,
#[cfg_attr(feature = "config_serde", serde(flatten))]
pub language: LanguageOptions,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase", default))]
/// Configuration related to layout, such as indentation or print width.
pub struct LayoutOptions {
/// See [`printWidth`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#printwidth) on GitHub
pub print_width: usize,
/// See [`useTabs`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#usetabs) on GitHub
pub use_tabs: bool,
/// See [`indentWidth`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#indentwidth) on GitHub
pub indent_width: usize,
/// See [`lineBreak`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#linebreak) on GitHub
pub line_break: LineBreak,
}
impl Default for LayoutOptions {
fn default() -> Self {
Self {
print_width: 80,
use_tabs: false,
indent_width: 2,
line_break: LineBreak::Lf,
}
}
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum LineBreak {
#[default]
Lf,
Crlf,
}
impl From<LineBreak> for tiny_pretty::LineBreak {
fn from(value: LineBreak) -> Self {
match value {
LineBreak::Lf => tiny_pretty::LineBreak::Lf,
LineBreak::Crlf => tiny_pretty::LineBreak::Crlf,
}
}
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase", default))]
/// Configuration related to syntax.
pub struct LanguageOptions {
/// See [`quotes`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#quotes) on GitHub
pub quotes: Quotes,
/// See [`formatComments`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#formatcomments) on GitHub
pub format_comments: bool,
/// See [`scriptIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#scriptindent) on GitHub
pub script_indent: bool,
#[cfg_attr(feature = "config_serde", serde(rename = "html.scriptIndent"))]
/// See [`scriptIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#scriptindent) on GitHub
pub html_script_indent: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "vue.scriptIndent"))]
/// See [`scriptIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#scriptindent) on GitHub
pub vue_script_indent: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "svelte.scriptIndent"))]
/// See [`scriptIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#scriptindent) on GitHub
pub svelte_script_indent: Option<bool>,
/// See [`styleIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#styleindent) on GitHub
pub style_indent: bool,
#[cfg_attr(feature = "config_serde", serde(rename = "html.styleIndent"))]
/// See [`styleIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#styleindent) on GitHub
pub html_style_indent: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "vue.styleIndent"))]
/// See [`styleIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#styleindent) on GitHub
pub vue_style_indent: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "svelte.styleIndent"))]
/// See [`styleIndent`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#styleindent) on GitHub
pub svelte_style_indent: Option<bool>,
/// See [`closingBracketSameLine`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#closingbracketsameline) on GitHub
pub closing_bracket_same_line: bool,
/// See [`closingTagLineBreakForEmpty`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#closingtaglinebreakforempty) on GitHub
pub closing_tag_line_break_for_empty: ClosingTagLineBreakForEmpty,
/// See [`maxAttrsPerLine`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#maxattrsperline) on GitHub
pub max_attrs_per_line: Option<NonZeroUsize>,
#[cfg_attr(feature = "config_serde", serde(rename = "html.normal.selfClosing"))]
/// See [`*.selfClosing`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#selfclosing) on GitHub
pub html_normal_self_closing: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "html.void.selfClosing"))]
/// See [`*.selfClosing`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#selfclosing) on GitHub
pub html_void_self_closing: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "component.selfClosing"))]
/// See [`*.selfClosing`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#selfclosing) on GitHub
pub component_self_closing: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "svg.selfClosing"))]
/// See [`*.selfClosing`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#selfclosing) on GitHub
pub svg_self_closing: Option<bool>,
#[cfg_attr(feature = "config_serde", serde(rename = "mathml.selfClosing"))]
/// See [`*.selfClosing`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#selfclosing) on GitHub
pub mathml_self_closing: Option<bool>,
/// See [`whitespaceSensitivity`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#whitespacesensitivity) on GitHub
pub whitespace_sensitivity: WhitespaceSensitivity,
#[cfg_attr(
feature = "config_serde",
serde(rename = "component.whitespaceSensitivity")
)]
/// See [`whitespaceSensitivity`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#whitespacesensitivity) on GitHub
pub component_whitespace_sensitivity: Option<WhitespaceSensitivity>,
/// See [`vBindStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vbindstyle) on GitHub
pub v_bind_style: Option<VBindStyle>,
/// See [`vOnStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vonstyle) on GitHub
pub v_on_style: Option<VOnStyle>,
/// See [`vForDelimiterStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vfordelimiterstyle) on GitHub
pub v_for_delimiter_style: Option<VForDelimiterStyle>,
/// See [`vSlotStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vslotstyle) on GitHub
pub v_slot_style: Option<VSlotStyle>,
#[cfg_attr(feature = "config_serde", serde(rename = "component.vSlotStyle"))]
/// See [`vSlotStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vslotstyle) on GitHub
pub component_v_slot_style: Option<VSlotStyle>,
#[cfg_attr(feature = "config_serde", serde(rename = "default.vSlotStyle"))]
/// See [`vSlotStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vslotstyle) on GitHub
pub default_v_slot_style: Option<VSlotStyle>,
#[cfg_attr(feature = "config_serde", serde(rename = "named.vSlotStyle"))]
/// See [`vSlotStyle`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#vslotstyle) on GitHub
pub named_v_slot_style: Option<VSlotStyle>,
/// See [`strictSvelteAttr`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#strictsvelteattr) on GitHub
pub strict_svelte_attr: bool,
/// See [`svelteAttrShorthand`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#svelteattrshorthand) on GitHub
pub svelte_attr_shorthand: Option<bool>,
/// See [`svelteDirectiveShorthand`](https://github.com/g-plane/markup_fmt/blob/main/docs/config.md#sveltedirectiveshorthand) on GitHub
pub svelte_directive_shorthand: Option<bool>,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum Quotes {
#[default]
Double,
Single,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum ClosingTagLineBreakForEmpty {
Always,
#[default]
Fit,
Never,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum WhitespaceSensitivity {
#[default]
Css,
Strict,
Ignore,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum VBindStyle {
#[default]
Short,
Long,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum VOnStyle {
#[default]
Short,
Long,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum VForDelimiterStyle {
#[default]
In,
Of,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "config_serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "config_serde", serde(rename_all = "camelCase"))]
pub enum VSlotStyle {
#[default]
Short,
Long,
VSlot,
}