Skip to content

Commit 5386680

Browse files
committed
feat: add the whitespace plugin
1 parent e420c5d commit 5386680

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

crates/tailwind-parse/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ mod plugin {
6666
Pointer,
6767
Ease,
6868
Order,
69+
Whitespace(Whitespace),
6970
From,
7071
To,
7172
Outline,
@@ -101,6 +102,15 @@ mod plugin {
101102
Sr,
102103
}
103104

105+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
106+
pub enum Whitespace {
107+
Normal,
108+
Nowrap,
109+
Pre,
110+
PreLine,
111+
PreWrap,
112+
}
113+
104114
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
105115
pub enum Gap {
106116
X,

src/parse/literal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn parse_literal<'a>(theme: &TailwindTheme, lit: Literal<'a>) -> Result<Obje
2929
Flex(f) => return plugin::flex(f, lit.value, theme).ok_or(lit.full),
3030
Grid(g) => return plugin::grid(g, lit.value, theme).ok_or(lit.full),
3131
Object(o) => return plugin::object(o, lit.value, theme).ok_or(lit.full),
32+
Whitespace(ws) => return plugin::white_space(ws, lit.value, theme).ok_or(lit.full),
3233

3334
// all other plugins
3435
Text => Required(plugin::text),

src/plugin.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use swc_core::{
1212
};
1313
use tailwind_parse::{
1414
Border, Display, Flex, Grid, Object, Position, Rounded, TextDecoration, TextTransform,
15-
Visibility,
15+
Visibility, Whitespace,
1616
};
1717

1818
macro_rules! lookup_plugin {
@@ -525,6 +525,21 @@ pub fn object(o: Object, _rest: Option<SubjectValue>, _theme: &TailwindTheme) ->
525525
Some(to_lit(&rule))
526526
}
527527

528+
pub fn white_space(
529+
o: Whitespace,
530+
_rest: Option<SubjectValue>,
531+
_theme: &TailwindTheme,
532+
) -> Option<ObjectLit> {
533+
let rule = match o {
534+
Whitespace::Normal => [("whiteSpace", "normal")],
535+
Whitespace::Nowrap => [("whiteSpace", "nowrap")],
536+
Whitespace::Pre => [("whiteSpace", "pre")],
537+
Whitespace::PreLine => [("whiteSpace", "pre-line")],
538+
Whitespace::PreWrap => [("whiteSpace", "pre-wrap")],
539+
};
540+
Some(to_lit(&rule))
541+
}
542+
528543
pub fn col(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
529544
simple_lookup(&theme.grid_column, rest, "gridColumn").or_else(|| match rest.split_once('-') {
530545
Some(("start", rest)) => simple_lookup(&theme.grid_column_start, rest, "gridColumnStart"),

0 commit comments

Comments
 (0)