@@ -51,17 +51,37 @@ newtype EscapedChar = EscapedChar
51
51
}
52
52
deriving stock (Show , Eq , Generic )
53
53
54
+ newtype Strong = Strong
55
+ { _strong :: Inlines
56
+ }
57
+ deriving stock (Show , Eq , Generic )
58
+
59
+ newtype Emph = Emph
60
+ { _emph :: Inlines
61
+ }
62
+ deriving stock (Show , Eq , Generic )
63
+
64
+ newtype Code = Code
65
+ { _code :: Text
66
+ }
67
+ deriving stock (Show , Eq , Generic )
68
+
69
+ newtype Entity = Entity
70
+ { _entity :: Text
71
+ }
72
+ deriving stock (Show , Eq , Generic )
73
+
54
74
data Inline
55
75
= InlineHardBreak (Meta HardBreak )
56
76
| InlineSoftBreak (Meta SoftBreak )
57
77
| InlineString (Meta Text )
58
- | InlineEntity (Meta Text )
78
+ | InlineEntity (Meta Entity )
59
79
| InlineEscapedChar (Meta EscapedChar )
60
- | InlineEmph Inlines
61
- | InlineStrong Inlines
80
+ | InlineEmph ( Meta Emph )
81
+ | InlineStrong ( Meta Strong )
62
82
| InlineLink (Meta Link )
63
83
| InlineImage (Meta Image )
64
- | InlineCode (Meta Text )
84
+ | InlineCode (Meta Code )
65
85
| InlineRaw (Meta RawInline )
66
86
deriving stock (Show , Eq , Generic )
67
87
@@ -155,9 +175,20 @@ instance Rangeable (Meta a) where
155
175
ranged = set (metaLoc . unIrrelevant)
156
176
157
177
instance HasAttributes Inline where
158
- addAttributes _attr = trace " todo"
178
+ addAttributes attr =
179
+ \ case
180
+ InlineHardBreak a -> InlineHardBreak (addAttributes attr a)
181
+ InlineSoftBreak a -> InlineSoftBreak (addAttributes attr a)
182
+ InlineString a -> InlineString (addAttributes attr a)
183
+ InlineEntity a -> InlineEntity (addAttributes attr a)
184
+ InlineEscapedChar a -> InlineEscapedChar (addAttributes attr a)
185
+ InlineEmph a -> InlineEmph (addAttributes attr a)
186
+ InlineStrong a -> InlineStrong (addAttributes attr a)
187
+ InlineLink a -> InlineLink (addAttributes attr a)
188
+ InlineImage a -> InlineImage (addAttributes attr a)
189
+ InlineCode a -> InlineCode (addAttributes attr a)
190
+ InlineRaw a -> InlineRaw (addAttributes attr a)
159
191
160
- -- TODO
161
192
instance Rangeable Inline where
162
193
ranged d =
163
194
\ case
@@ -180,10 +211,10 @@ instance HasAttributes Inlines where
180
211
addAttributes attr = over inlines (map (addAttributes attr))
181
212
182
213
instance Rangeable Blocks where
183
- ranged d bs = trace ( " rangeable blocks " <> show ( length (bs ^. blocks)) <> " " <> show d) ( over blocks (map (ranged d)) bs)
214
+ ranged d bs = over blocks (map (ranged d)) bs
184
215
185
216
instance Rangeable Inlines where
186
- ranged d = trace ( " rangeable inlines " <> show d) . over inlines (map (ranged d))
217
+ ranged d = over inlines (map (ranged d))
187
218
188
219
class IsInlines a where
189
220
toInlines :: a -> Inlines
@@ -208,35 +239,40 @@ iniRange :: SourceRange
208
239
iniRange = mempty
209
240
210
241
instance Rangeable Block where
211
- ranged r b =
212
- trace
213
- (" rangeable block: " <> show b)
214
- ( case b of
215
- BlockParagraph a -> BlockParagraph (ranged r a)
216
- BlockPlain a -> BlockPlain (ranged r a)
217
- BlockCodeBlock a -> BlockCodeBlock (ranged r a)
218
- BlockHeading a -> BlockHeading (ranged r a)
219
- BlockThematicBreak a -> BlockThematicBreak (ranged r a)
220
- BlockQuote a -> BlockQuote (ranged r a)
221
- BlockList a -> BlockList (ranged r a)
222
- BlockRawBlock a -> BlockRawBlock (ranged r a)
223
- BlockReferenceLinkDefinition a -> BlockReferenceLinkDefinition (ranged r a)
224
- )
242
+ ranged r = \ case
243
+ BlockParagraph a -> BlockParagraph (ranged r a)
244
+ BlockPlain a -> BlockPlain (ranged r a)
245
+ BlockCodeBlock a -> BlockCodeBlock (ranged r a)
246
+ BlockHeading a -> BlockHeading (ranged r a)
247
+ BlockThematicBreak a -> BlockThematicBreak (ranged r a)
248
+ BlockQuote a -> BlockQuote (ranged r a)
249
+ BlockList a -> BlockList (ranged r a)
250
+ BlockRawBlock a -> BlockRawBlock (ranged r a)
251
+ BlockReferenceLinkDefinition a -> BlockReferenceLinkDefinition (ranged r a)
225
252
226
253
instance HasAttributes Block where
227
- addAttributes _ = trace " attributes block"
254
+ addAttributes attr = \ case
255
+ BlockParagraph a -> BlockParagraph (addAttributes attr a)
256
+ BlockPlain a -> BlockPlain (addAttributes attr a)
257
+ BlockCodeBlock a -> BlockCodeBlock (addAttributes attr a)
258
+ BlockHeading a -> BlockHeading (addAttributes attr a)
259
+ BlockThematicBreak a -> BlockThematicBreak (addAttributes attr a)
260
+ BlockQuote a -> BlockQuote (addAttributes attr a)
261
+ BlockList a -> BlockList (addAttributes attr a)
262
+ BlockRawBlock a -> BlockRawBlock (addAttributes attr a)
263
+ BlockReferenceLinkDefinition a -> BlockReferenceLinkDefinition (addAttributes attr a)
228
264
229
265
instance IsInline Inlines where
230
266
lineBreak = toInlines (InlineHardBreak (mkMeta HardBreak ))
231
267
softBreak = toInlines (InlineSoftBreak (mkMeta SoftBreak ))
232
268
str a = toInlines (InlineString (mkMeta a))
233
- entity a = toInlines (InlineEntity (mkMeta a ))
269
+ entity a = toInlines (InlineEntity (mkMeta ( Entity a) ))
234
270
escapedChar _escapedChar = toInlines (InlineEscapedChar (mkMeta (EscapedChar {.. })))
235
- emph a = toInlines (InlineEmph a )
236
- strong a = toInlines (InlineStrong a )
271
+ emph a = toInlines (InlineEmph (mkMeta ( Emph a)) )
272
+ strong a = toInlines (InlineStrong (mkMeta ( Strong a)) )
237
273
link _linkDestination _linkTitle _linkDescription = toInlines (InlineLink (mkMeta Link {.. }))
238
274
image _imageSource _imageTitle _imageDescription = toInlines (InlineImage (mkMeta Image {.. }))
239
- code a = toInlines (InlineCode (mkMeta a ))
275
+ code a = toInlines (InlineCode (mkMeta ( Code a) ))
240
276
rawInline _rawInlineFormat _rawInlineText = toInlines (InlineRaw (mkMeta RawInline {.. }))
241
277
242
278
instance IsBlock Inlines Blocks where
@@ -246,7 +282,7 @@ instance IsBlock Inlines Blocks where
246
282
blockQuote _quoteBlock = mkBlocks (BlockQuote (mkMeta QuoteBlock {.. }))
247
283
codeBlock _codeBlockLanguage _codeBlock = mkBlocks (BlockCodeBlock (mkMeta (CodeBlock {.. })))
248
284
heading _headingLevel _headingText = mkBlocks (BlockHeading (mkMeta Heading {.. }))
249
- rawBlock = error " todo "
285
+ rawBlock _rawBlockFormat _rawBlockText = mkBlocks ( BlockRawBlock (mkMeta RawBlock { .. }))
250
286
referenceLinkDefinition _referenceLinkDefinitionLabel (_referenceLinkDefinitionDestination, _referenceLinkDefinitionTitle) = mkBlocks (BlockReferenceLinkDefinition (mkMeta ReferenceLinkDefinition {.. }))
251
287
list _listType _listSpacing lstBlocks = mkBlocks (BlockList (mkMeta List {_listBlocks = nonEmpty' lstBlocks, .. }))
252
288
0 commit comments