@@ -141,6 +141,42 @@ public enum Block: Equatable, CustomStringConvertible, CustomDebugStringConverti
141
141
return self . description
142
142
}
143
143
}
144
+
145
+ /// Returns raw text for this block, i.e. ignoring all markup.
146
+ public var string : String {
147
+ switch self {
148
+ case . document( let blocks) :
149
+ return blocks. string
150
+ case . blockquote( let blocks) :
151
+ return blocks. string
152
+ case . list( _, _, let blocks) :
153
+ return blocks. string
154
+ case . listItem( _, _, let blocks) :
155
+ return blocks. string
156
+ case . paragraph( let text) :
157
+ return text. string
158
+ case . heading( _, let text) :
159
+ return text. string
160
+ case . indentedCode( let lines) :
161
+ return lines. map { String ( $0) } . joined ( )
162
+ case . fencedCode( _, let lines) :
163
+ return lines. map { String ( $0) } . joined ( separator: " \n " )
164
+ case . htmlBlock( _) :
165
+ return " "
166
+ case . referenceDef( _, _, let lines) :
167
+ return lines. map { String ( $0) } . joined ( separator: " " )
168
+ case . thematicBreak:
169
+ return " \n \n "
170
+ case . table( let headers, _, let rows) :
171
+ return headers. map { $0. string } . joined ( separator: " | " ) + " \n " +
172
+ rows. map { $0. map { $0. string } . joined ( separator: " | " ) }
173
+ . joined ( separator: " \n " )
174
+ case . definitionList( let defs) :
175
+ return defs. map { $0. string } . joined ( separator: " \n \n " )
176
+ case . custom( let obj) :
177
+ return obj. string
178
+ }
179
+ }
144
180
145
181
fileprivate static func string( from blocks: Blocks ) -> String {
146
182
var res = " "
@@ -295,6 +331,10 @@ public struct Definition: Equatable, CustomStringConvertible, CustomDebugStringC
295
331
public var debugDescription : String {
296
332
return self . description
297
333
}
334
+
335
+ public var string : String {
336
+ return " \( self . item. rawDescription) : \( self . descriptions. string) "
337
+ }
298
338
}
299
339
300
340
public typealias Definitions = ContiguousArray < Definition >
0 commit comments