-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSSConverter.fs
More file actions
65 lines (63 loc) · 3.16 KB
/
CSSConverter.fs
File metadata and controls
65 lines (63 loc) · 3.16 KB
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
[<AutoOpen>]
module Failess.Convert
open System
open System.Text.RegularExpressions
let inline toFailess css =
match css with
| [] -> ""
| [ s ] -> s
| _ ->
let block = ref false
let blockStart = ref ""
let blockQueue = ref []
String.Join(System.Environment.NewLine,
[for s : string in css do
if !block then
if s.Contains("}") then
block := false
yield (!blockStart).Replace("{", "-| [")
.Replace(".", "-.")
.Replace(":", "%")
.Replace(":", "%")
.Replace(",", "$")
if (!blockQueue).Length > 0 then
yield String.Join
(System.Environment.NewLine, !blockQueue)
yield sprintf "%s]" tab
blockQueue := []
else
if s.Contains(":") then
let split = s.Split(':')
if split.Length > 1 then
let left = ref split.[0]
let right = ref split.[1]
for w in (!left).Split(' ','.',':') do
if not <| String.IsNullOrEmpty w then
if not ( CSSStrings
|> List.exists(fun cw -> cw = w) ) then
left := (!left).Replace(w, (sprintf "\"%s\"" w))
let value s v n =
let rspl = Regex.Split(s, v)
if rspl.Length > 0 then right := sprintf "%s%s" n rspl.[0]
match !right with
| r when r.Contains("em") -> value r "em" "em"
| r when r.Contains("px") -> value r "px" "px"
| r when r.Contains("pt") -> value r "pt" "pt"
| r when r.Contains("%") -> value r "%" "prc"
| _ -> ()
right := (!right).Replace(";","")
blockQueue :=
sprintf "%s%s --%s" tab !left !right
:: !blockQueue
else
blockQueue :=
sprintf "%s%s%s" tab tab s
:: !blockQueue
else if s.Contains("{") then
blockStart := s
for w in s.Split(' ','.',':','{') do
if not <| String.IsNullOrEmpty w then
if not ( CSSStrings |> List.exists(fun cw -> cw = w) ) then
blockStart := (!blockStart).Replace(w, (sprintf "\"%s\"" w))
block := true
])