@@ -52,21 +52,32 @@ formatTypstBlock :: FormatOptions -> [SourceLine] -> Text
52
52
formatTypstBlock opts ls =
53
53
" #Skylighting(" <>
54
54
(if numberLines opts
55
- then " number: true, start: " <> Text. pack (show (startNumber opts)) <> " )"
56
- else " )" ) <>
57
- " [" <> formatTypstInline opts ls <> " ];"
55
+ then " number: true, start: " <> Text. pack (show (startNumber opts)) <> " , "
56
+ else " " ) <>
57
+ " (" <> -- an array
58
+ Text. intercalate " \n " (map (\ ln -> " [" <> formatTypstInline opts [ln] <> " ]," ) ls)
59
+ <> " ));"
58
60
59
61
-- | Converts a 'Style' to a set of Typst macro definitions,
60
62
-- which should be placed in the document's preamble.
61
63
styleToTypst :: Style -> Text
62
64
styleToTypst f =
63
65
Text. unlines $
64
- [ " #let Skylighting(body, number: false, start: 1) = block(" <>
65
- (case backgroundColor f of
66
- Nothing -> " "
67
- Just c -> " fill: rgb(" <> Text. pack (show (fromColor c :: String )) <> " ), " )
68
- <> " body)"
69
- , " #let EndLine() = raw(\"\\ n\" )"
66
+ [ " #let EndLine() = raw(\"\\ n\" )"
67
+ , " #let Skylighting(fill: none, number: false, start: 1, sourcelines) = {"
68
+ , " let blocks = []"
69
+ , " let lnum = start - 1"
70
+ , " for ln in sourcelines {"
71
+ , " if number { lnum = lnum + 1; blocks = blocks + box(width: 2em, [ #lnum ]) }"
72
+ , " blocks = blocks + ln + EndLine()"
73
+ , " }"
74
+ , " let bgcolor = " <> case backgroundColor f of
75
+ Nothing -> " none"
76
+ Just c -> " rgb(" <>
77
+ Text. pack (show (fromColor c :: String )) <>
78
+ " )"
79
+ , " block(fill: bgcolor, blocks)"
80
+ , " }"
70
81
] <>
71
82
sort (map (macrodef (defaultColor f) (Map. toList (tokenStyles f)))
72
83
(enumFromTo KeywordTok NormalTok ))
0 commit comments