CMParserTestObject.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // CMParserTestObject.m
  3. // CocoaMarkdown
  4. //
  5. // Created by Indragie on 1/14/15.
  6. // Copyright (c) 2015 Indragie Karunaratne. All rights reserved.
  7. //
  8. #import "CMParserTestObject.h"
  9. #import <CocoaMarkdown/CocoaMarkdown.h>
  10. @interface CMParserTestObject () <CMParserDelegate>
  11. @end
  12. @implementation CMParserTestObject {
  13. CMParser *_parser;
  14. NSMutableArray *_foundText;
  15. NSMutableArray *_didStartHeader;
  16. NSMutableArray *_didEndHeader;
  17. NSMutableArray *_didStartLink;
  18. NSMutableArray *_didEndLink;
  19. NSMutableArray *_didStartImage;
  20. NSMutableArray *_didEndImage;
  21. NSMutableArray *_foundHTML;
  22. NSMutableArray *_foundInlineHTML;
  23. NSMutableArray *_foundCodeBlock;
  24. NSMutableArray *_foundInlineCode;
  25. NSMutableArray *_didStartUnorderedList;
  26. NSMutableArray *_didEndUnorderedList;
  27. NSMutableArray *_didStartOrderedList;
  28. NSMutableArray *_didEndOrderedList;
  29. }
  30. - (instancetype)initWithDocument:(CMDocument *)document
  31. {
  32. NSParameterAssert(document);
  33. if ((self = [super init])) {
  34. _parser = [[CMParser alloc] initWithDocument:document delegate:self];
  35. _foundText = [[NSMutableArray alloc] init];
  36. _didStartHeader = [[NSMutableArray alloc] init];
  37. _didEndHeader = [[NSMutableArray alloc] init];
  38. _didStartLink = [[NSMutableArray alloc] init];
  39. _didEndLink = [[NSMutableArray alloc] init];
  40. _didStartImage = [[NSMutableArray alloc] init];
  41. _didEndImage = [[NSMutableArray alloc] init];
  42. _foundHTML = [[NSMutableArray alloc] init];
  43. _foundInlineHTML = [[NSMutableArray alloc] init];
  44. _foundCodeBlock = [[NSMutableArray alloc] init];
  45. _foundInlineCode = [[NSMutableArray alloc] init];
  46. _didStartUnorderedList = [[NSMutableArray alloc] init];
  47. _didEndUnorderedList = [[NSMutableArray alloc] init];
  48. _didStartOrderedList = [[NSMutableArray alloc] init];
  49. _didEndOrderedList = [[NSMutableArray alloc] init];
  50. }
  51. return self;
  52. }
  53. - (void)parse
  54. {
  55. [_parser parse];
  56. }
  57. #pragma mark - CMParserDelegate
  58. - (void)parserDidStartDocument:(CMParser *)parser
  59. {
  60. _didStartDocument++;
  61. if (_abortOnStart) {
  62. [parser abortParsing];
  63. }
  64. }
  65. - (void)parserDidEndDocument:(CMParser *)parser
  66. {
  67. _didEndDocument++;
  68. }
  69. - (void)parserDidAbort:(CMParser *)parser
  70. {
  71. _didAbort++;
  72. }
  73. - (void)parser:(CMParser *)parser foundText:(NSString *)text
  74. {
  75. [_foundText addObject:text];
  76. }
  77. - (void)parserFoundHRule:(CMParser *)parser
  78. {
  79. _foundHRule++;
  80. }
  81. - (void)parser:(CMParser *)parser didStartHeaderWithLevel:(NSInteger)level
  82. {
  83. [_didStartHeader addObject:@(level)];
  84. }
  85. - (void)parser:(CMParser *)parser didEndHeaderWithLevel:(NSInteger)level
  86. {
  87. [_didEndHeader addObject:@(level)];
  88. }
  89. - (void)parserDidStartParagraph:(CMParser *)parser
  90. {
  91. _didStartParagraph++;
  92. }
  93. - (void)parserDidEndParagraph:(CMParser *)parser
  94. {
  95. _didEndParagraph++;
  96. }
  97. - (void)parserDidStartEmphasis:(CMParser *)parser
  98. {
  99. _didStartEmphasis++;
  100. }
  101. - (void)parserDidEndEmphasis:(CMParser *)parser
  102. {
  103. _didEndEmphasis++;
  104. }
  105. - (void)parserDidStartStrong:(CMParser *)parser
  106. {
  107. _didStartStrong++;
  108. }
  109. - (void)parserDidEndStrong:(CMParser *)parser
  110. {
  111. _didEndStrong++;
  112. }
  113. - (void)parser:(CMParser *)parser didStartLinkWithURL:(NSURL *)URL title:(NSString *)title
  114. {
  115. NSParameterAssert(URL);
  116. [_didStartLink addObject:@[URL, title ?: NSNull.null]];
  117. }
  118. - (void)parser:(CMParser *)parser didEndLinkWithURL:(NSURL *)URL title:(NSString *)title
  119. {
  120. NSParameterAssert(URL);
  121. [_didEndLink addObject:@[URL, title ?: NSNull.null]];
  122. }
  123. - (void)parser:(CMParser *)parser didStartImageWithURL:(NSURL *)URL title:(NSString *)title
  124. {
  125. NSParameterAssert(URL);
  126. [_didStartImage addObject:@[URL, title ?: NSNull.null]];
  127. }
  128. - (void)parser:(CMParser *)parser didEndImageWithURL:(NSURL *)URL title:(NSString *)title
  129. {
  130. NSParameterAssert(URL);
  131. [_didEndImage addObject:@[URL, title ?: NSNull.null]];
  132. }
  133. - (void)parser:(CMParser *)parser foundHTML:(NSString *)HTML
  134. {
  135. NSParameterAssert(HTML);
  136. [_foundHTML addObject:HTML];
  137. }
  138. - (void)parser:(CMParser *)parser foundInlineHTML:(NSString *)HTML
  139. {
  140. NSParameterAssert(HTML);
  141. [_foundInlineHTML addObject:HTML];
  142. }
  143. - (void)parser:(CMParser *)parser foundCodeBlock:(NSString *)code info:(NSString *)info
  144. {
  145. NSParameterAssert(code);
  146. [_foundCodeBlock addObject:@[code, info ?: NSNull.null]];
  147. }
  148. - (void)parser:(CMParser *)parser foundInlineCode:(NSString *)code
  149. {
  150. [_foundInlineCode addObject:code];
  151. }
  152. - (void)parserFoundSoftBreak:(CMParser *)parser
  153. {
  154. _foundSoftBreak++;
  155. }
  156. - (void)parserFoundLineBreak:(CMParser *)parser
  157. {
  158. _foundLineBreak++;
  159. }
  160. - (void)parserDidStartBlockQuote:(CMParser *)parser
  161. {
  162. _didStartBlockQuote++;
  163. }
  164. - (void)parserDidEndBlockQuote:(CMParser *)parser
  165. {
  166. _didEndBlockQuote++;
  167. }
  168. - (void)parser:(CMParser *)parser didStartUnorderedListWithTightness:(BOOL)tight
  169. {
  170. [_didStartUnorderedList addObject:@(tight)];
  171. }
  172. - (void)parser:(CMParser *)parser didEndUnorderedListWithTightness:(BOOL)tight
  173. {
  174. [_didEndUnorderedList addObject:@(tight)];
  175. }
  176. - (void)parser:(CMParser *)parser didStartOrderedListWithStartingNumber:(NSInteger)num tight:(BOOL)tight
  177. {
  178. [_didStartOrderedList addObject:@[@(num), @(tight)]];
  179. }
  180. - (void)parser:(CMParser *)parser didEndOrderedListWithStartingNumber:(NSInteger)num tight:(BOOL)tight
  181. {
  182. [_didEndOrderedList addObject:@[@(num), @(tight)]];
  183. }
  184. - (void)parserDidStartListItem:(CMParser *)parser
  185. {
  186. _didStartListItem++;
  187. }
  188. - (void)parserDidEndListItem:(CMParser *)parser
  189. {
  190. _didEndListItem++;
  191. }
  192. @end