@gmb/bitmark-parser-generator 1.35.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/dist/browser/bitmark-parser-generator.min.js +1 -1
  2. package/dist/browser/bundle-report.html +2 -2
  3. package/dist/cjs/BitmarkParserGenerator.js +8 -3
  4. package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
  5. package/dist/cjs/ast/Ast.js +1 -0
  6. package/dist/cjs/ast/Ast.js.map +1 -1
  7. package/dist/cjs/ast/BaseBuilder.js +91 -54
  8. package/dist/cjs/ast/BaseBuilder.js.map +1 -1
  9. package/dist/cjs/ast/Builder.js +813 -389
  10. package/dist/cjs/ast/Builder.js.map +1 -1
  11. package/dist/cjs/ast/ResourceBuilder.js +516 -252
  12. package/dist/cjs/ast/ResourceBuilder.js.map +1 -1
  13. package/dist/cjs/ast/rules/NodeValidator.js +61 -22
  14. package/dist/cjs/ast/rules/NodeValidator.js.map +1 -1
  15. package/dist/cjs/breakscaping/Breakscape.js +96 -71
  16. package/dist/cjs/breakscaping/Breakscape.js.map +1 -1
  17. package/dist/cjs/config/raw/bits.js +44 -5
  18. package/dist/cjs/config/raw/bits.js.map +1 -1
  19. package/dist/cjs/config/raw/properties.js +7 -2
  20. package/dist/cjs/config/raw/properties.js.map +1 -1
  21. package/dist/cjs/generated/build-info.js +1 -1
  22. package/dist/cjs/generated/build-info.js.map +1 -1
  23. package/dist/cjs/generated/parser/bitmark/bitmark-peggy-parser.js +1 -0
  24. package/dist/cjs/generated/parser/bitmark/bitmark-peggy-parser.js.map +1 -1
  25. package/dist/cjs/generator/AstWalkerGenerator.js +4 -1
  26. package/dist/cjs/generator/AstWalkerGenerator.js.map +1 -1
  27. package/dist/cjs/generator/bitmark/BitmarkGenerator.js +992 -339
  28. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  29. package/dist/cjs/generator/json/JsonGenerator.js +312 -1985
  30. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  31. package/dist/cjs/generator/text/TextGenerator.js +26 -8
  32. package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
  33. package/dist/cjs/index.js.map +1 -1
  34. package/dist/cjs/model/ast/NodeType.js +28 -8
  35. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  36. package/dist/cjs/model/config/enum/PropertyConfigKey.js +1 -0
  37. package/dist/cjs/model/config/enum/PropertyConfigKey.js.map +1 -1
  38. package/dist/cjs/model/enum/BitType.js +2 -2
  39. package/dist/cjs/model/enum/BitType.js.map +1 -1
  40. package/dist/cjs/model/enum/PropertyFormat.js +3 -1
  41. package/dist/cjs/model/enum/PropertyFormat.js.map +1 -1
  42. package/dist/cjs/model/enum/TextFormat.js +1 -1
  43. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js +9 -3
  44. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  45. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +49 -131
  46. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  47. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  48. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserValidator.js +7 -31
  49. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
  50. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +255 -0
  51. package/dist/cjs/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -0
  52. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +25 -12
  53. package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  54. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +175 -129
  55. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  56. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +8 -2
  57. package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  58. package/dist/cjs/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.js +61 -0
  59. package/dist/cjs/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.js.map +1 -0
  60. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +11 -5
  61. package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  62. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +21 -17
  63. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  64. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +50 -0
  65. package/dist/cjs/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -0
  66. package/dist/cjs/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.js +2 -15
  67. package/dist/cjs/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.js.map +1 -1
  68. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -4
  69. package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  70. package/dist/cjs/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js +4 -1
  71. package/dist/cjs/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
  72. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js +2 -4
  73. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js.map +1 -1
  74. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +5 -5
  75. package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  76. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +5 -6
  77. package/dist/cjs/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  78. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +23 -7
  79. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  80. package/dist/cjs/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js +5 -5
  81. package/dist/cjs/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js.map +1 -1
  82. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +3 -2
  83. package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  84. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +19 -8
  85. package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  86. package/dist/cjs/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.js +4 -6
  87. package/dist/cjs/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.js.map +1 -1
  88. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +4 -5
  89. package/dist/cjs/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  90. package/dist/cjs/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js +14 -5
  91. package/dist/cjs/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
  92. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js +37 -21
  93. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js.map +1 -1
  94. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -2
  95. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  96. package/dist/cjs/parser/json/JsonParser.js +73 -765
  97. package/dist/cjs/parser/json/JsonParser.js.map +1 -1
  98. package/dist/cjs/parser/text/TextParser.js +61 -2
  99. package/dist/cjs/parser/text/TextParser.js.map +1 -1
  100. package/dist/cjs/utils/BitUtils.js +15 -13
  101. package/dist/cjs/utils/BitUtils.js.map +1 -1
  102. package/dist/esm/BitmarkParserGenerator.js +8 -3
  103. package/dist/esm/BitmarkParserGenerator.js.map +1 -1
  104. package/dist/esm/ast/Ast.js +1 -0
  105. package/dist/esm/ast/Ast.js.map +1 -1
  106. package/dist/esm/ast/BaseBuilder.js +91 -54
  107. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  108. package/dist/esm/ast/Builder.js +813 -389
  109. package/dist/esm/ast/Builder.js.map +1 -1
  110. package/dist/esm/ast/ResourceBuilder.js +516 -252
  111. package/dist/esm/ast/ResourceBuilder.js.map +1 -1
  112. package/dist/esm/ast/rules/NodeValidator.js +61 -22
  113. package/dist/esm/ast/rules/NodeValidator.js.map +1 -1
  114. package/dist/esm/breakscaping/Breakscape.js +96 -71
  115. package/dist/esm/breakscaping/Breakscape.js.map +1 -1
  116. package/dist/esm/config/raw/bits.js +44 -5
  117. package/dist/esm/config/raw/bits.js.map +1 -1
  118. package/dist/esm/config/raw/properties.js +7 -2
  119. package/dist/esm/config/raw/properties.js.map +1 -1
  120. package/dist/esm/generated/build-info.js +1 -1
  121. package/dist/esm/generated/build-info.js.map +1 -1
  122. package/dist/esm/generated/parser/bitmark/bitmark-peggy-parser.js +1 -0
  123. package/dist/esm/generated/parser/bitmark/bitmark-peggy-parser.js.map +1 -1
  124. package/dist/esm/generator/AstWalkerGenerator.js +4 -1
  125. package/dist/esm/generator/AstWalkerGenerator.js.map +1 -1
  126. package/dist/esm/generator/bitmark/BitmarkGenerator.js +992 -339
  127. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  128. package/dist/esm/generator/json/JsonGenerator.js +312 -1985
  129. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  130. package/dist/esm/generator/text/TextGenerator.js +26 -8
  131. package/dist/esm/generator/text/TextGenerator.js.map +1 -1
  132. package/dist/esm/index.js.map +1 -1
  133. package/dist/esm/model/ast/NodeType.js +28 -8
  134. package/dist/esm/model/ast/NodeType.js.map +1 -1
  135. package/dist/esm/model/config/enum/PropertyConfigKey.js +1 -0
  136. package/dist/esm/model/config/enum/PropertyConfigKey.js.map +1 -1
  137. package/dist/esm/model/enum/BitType.js +2 -2
  138. package/dist/esm/model/enum/BitType.js.map +1 -1
  139. package/dist/esm/model/enum/PropertyFormat.js +3 -1
  140. package/dist/esm/model/enum/PropertyFormat.js.map +1 -1
  141. package/dist/esm/model/enum/TextFormat.js +1 -1
  142. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js +9 -3
  143. package/dist/esm/parser/bitmark/peg/BitmarkPegParserHelper.js.map +1 -1
  144. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +49 -131
  145. package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
  146. package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  147. package/dist/esm/parser/bitmark/peg/BitmarkPegParserValidator.js +7 -31
  148. package/dist/esm/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
  149. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js +252 -0
  150. package/dist/esm/parser/bitmark/peg/contentProcessors/BodyContentProcessor.js.map +1 -0
  151. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js +25 -12
  152. package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
  153. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +175 -129
  154. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  155. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js +8 -2
  156. package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
  157. package/dist/esm/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.js +58 -0
  158. package/dist/esm/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.js.map +1 -0
  159. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js +11 -5
  160. package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
  161. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +21 -17
  162. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
  163. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js +47 -0
  164. package/dist/esm/parser/bitmark/peg/contentProcessors/FooterContentProcessor.js.map +1 -0
  165. package/dist/esm/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.js +2 -15
  166. package/dist/esm/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.js.map +1 -1
  167. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -4
  168. package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
  169. package/dist/esm/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js +4 -1
  170. package/dist/esm/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
  171. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js +2 -4
  172. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js.map +1 -1
  173. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +5 -5
  174. package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
  175. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js +5 -6
  176. package/dist/esm/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.js.map +1 -1
  177. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +23 -7
  178. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  179. package/dist/esm/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js +5 -5
  180. package/dist/esm/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.js.map +1 -1
  181. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js +3 -2
  182. package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
  183. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js +19 -8
  184. package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
  185. package/dist/esm/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.js +4 -6
  186. package/dist/esm/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.js.map +1 -1
  187. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js +4 -5
  188. package/dist/esm/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.js.map +1 -1
  189. package/dist/esm/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js +14 -5
  190. package/dist/esm/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
  191. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js +37 -21
  192. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.js.map +1 -1
  193. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +3 -2
  194. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  195. package/dist/esm/parser/json/JsonParser.js +73 -765
  196. package/dist/esm/parser/json/JsonParser.js.map +1 -1
  197. package/dist/esm/parser/text/TextParser.js +61 -2
  198. package/dist/esm/parser/text/TextParser.js.map +1 -1
  199. package/dist/esm/utils/BitUtils.js +15 -13
  200. package/dist/esm/utils/BitUtils.js.map +1 -1
  201. package/dist/types/BitmarkParserGenerator.d.ts +8 -0
  202. package/dist/types/BitmarkParserGenerator.d.ts.map +1 -1
  203. package/dist/types/ast/Ast.d.ts.map +1 -1
  204. package/dist/types/ast/BaseBuilder.d.ts +31 -21
  205. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  206. package/dist/types/ast/Builder.d.ts +293 -441
  207. package/dist/types/ast/Builder.d.ts.map +1 -1
  208. package/dist/types/ast/ResourceBuilder.d.ts +177 -164
  209. package/dist/types/ast/ResourceBuilder.d.ts.map +1 -1
  210. package/dist/types/ast/rules/NodeValidator.d.ts +3 -2
  211. package/dist/types/ast/rules/NodeValidator.d.ts.map +1 -1
  212. package/dist/types/breakscaping/Breakscape.d.ts +6 -5
  213. package/dist/types/breakscaping/Breakscape.d.ts.map +1 -1
  214. package/dist/types/config/raw/bits.d.ts.map +1 -1
  215. package/dist/types/config/raw/properties.d.ts.map +1 -1
  216. package/dist/types/generated/parser/bitmark/bitmark-peggy-parser.d.ts.map +1 -1
  217. package/dist/types/generator/AstWalkerGenerator.d.ts.map +1 -1
  218. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +92 -55
  219. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  220. package/dist/types/generator/json/JsonGenerator.d.ts +89 -108
  221. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  222. package/dist/types/generator/text/TextGenerator.d.ts +14 -2
  223. package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
  224. package/dist/types/index.d.ts +2 -2
  225. package/dist/types/index.d.ts.map +1 -1
  226. package/dist/types/model/ast/NodeType.d.ts +50 -16
  227. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  228. package/dist/types/model/ast/Nodes.d.ts +64 -440
  229. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  230. package/dist/types/model/config/enum/ConfigKey.d.ts +2 -0
  231. package/dist/types/model/config/enum/ConfigKey.d.ts.map +1 -1
  232. package/dist/types/model/config/enum/PropertyConfigKey.d.ts +3 -0
  233. package/dist/types/model/config/enum/PropertyConfigKey.d.ts.map +1 -1
  234. package/dist/types/model/enum/BitType.d.ts +4 -4
  235. package/dist/types/model/enum/PropertyFormat.d.ts +4 -2
  236. package/dist/types/model/enum/PropertyFormat.d.ts.map +1 -1
  237. package/dist/types/model/enum/PropertyTag.d.ts +2 -0
  238. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  239. package/dist/types/model/json/BitJson.d.ts +38 -21
  240. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  241. package/dist/types/model/json/BodyBitJson.d.ts +16 -12
  242. package/dist/types/model/json/BodyBitJson.d.ts.map +1 -1
  243. package/dist/types/model/json/ResourceJson.d.ts +2 -22
  244. package/dist/types/model/json/ResourceJson.d.ts.map +1 -1
  245. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts +3 -2
  246. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts.map +1 -1
  247. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts +2 -15
  248. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
  249. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +83 -71
  250. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  251. package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts +2 -2
  252. package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts.map +1 -1
  253. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts +37 -0
  254. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts.map +1 -0
  255. package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
  256. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts +2 -2
  257. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  258. package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.d.ts.map +1 -1
  259. package/dist/types/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.d.ts +15 -0
  260. package/dist/types/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.d.ts.map +1 -0
  261. package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
  262. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
  263. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts +16 -0
  264. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts.map +1 -0
  265. package/dist/types/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.d.ts.map +1 -1
  266. package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
  267. package/dist/types/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.d.ts.map +1 -1
  268. package/dist/types/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.d.ts.map +1 -1
  269. package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
  270. package/dist/types/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.d.ts.map +1 -1
  271. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  272. package/dist/types/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.d.ts.map +1 -1
  273. package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
  274. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts +2 -2
  275. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
  276. package/dist/types/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.d.ts.map +1 -1
  277. package/dist/types/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.d.ts.map +1 -1
  278. package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts +5 -2
  279. package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts.map +1 -1
  280. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.d.ts +1 -1
  281. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.d.ts.map +1 -1
  282. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
  283. package/dist/types/parser/json/JsonParser.d.ts +9 -72
  284. package/dist/types/parser/json/JsonParser.d.ts.map +1 -1
  285. package/dist/types/parser/text/TextParser.d.ts +16 -1
  286. package/dist/types/parser/text/TextParser.d.ts.map +1 -1
  287. package/dist/types/utils/BitUtils.d.ts +8 -8
  288. package/dist/types/utils/BitUtils.d.ts.map +1 -1
  289. package/package.json +1 -1
@@ -8,19 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Ast } from '../../ast/Ast';
11
+ import { Breakscape } from '../../breakscaping/Breakscape';
11
12
  import { Config } from '../../config/Config';
12
13
  import { NodeType } from '../../model/ast/NodeType';
13
14
  import { BitType } from '../../model/enum/BitType';
14
15
  import { BitmarkVersion, DEFAULT_BITMARK_VERSION } from '../../model/enum/BitmarkVersion';
15
16
  import { BodyBitType } from '../../model/enum/BodyBitType';
16
17
  import { CardSetVersion } from '../../model/enum/CardSetVersion';
17
- import { PropertyAstKey } from '../../model/enum/PropertyAstKey';
18
+ import { PropertyFormat } from '../../model/enum/PropertyFormat';
18
19
  import { PropertyTag } from '../../model/enum/PropertyTag';
19
20
  import { ResourceTag } from '../../model/enum/ResourceTag';
20
21
  import { TextFormat } from '../../model/enum/TextFormat';
21
22
  import { BooleanUtils } from '../../utils/BooleanUtils';
22
23
  import { ObjectUtils } from '../../utils/ObjectUtils';
24
+ import { StringUtils } from '../../utils/StringUtils';
23
25
  import { AstWalkerGenerator } from '../AstWalkerGenerator';
26
+ import { TextGenerator } from '../text/TextGenerator';
24
27
  const DEFAULT_OPTIONS = {
25
28
  debugGenerationInline: false,
26
29
  };
@@ -50,6 +53,17 @@ class BitmarkGenerator extends AstWalkerGenerator {
50
53
  // State
51
54
  this.skipNLBetweenBitsValue = false;
52
55
  this.wroteSomething = false;
56
+ this.inTag = true;
57
+ // Keep TS happy
58
+ this.inTag;
59
+ // Bind callbacks
60
+ this.enter = this.enter.bind(this);
61
+ this.between = this.between.bind(this);
62
+ this.exit = this.exit.bind(this);
63
+ this.leaf = this.leaf.bind(this);
64
+ this.write = this.write.bind(this);
65
+ this.bodyBitCallback = this.bodyBitCallback.bind(this);
66
+ // Set options
53
67
  this.bitmarkVersion = (_a = BitmarkVersion.fromValue(options === null || options === void 0 ? void 0 : options.bitmarkVersion)) !== null && _a !== void 0 ? _a : DEFAULT_BITMARK_VERSION;
54
68
  this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options === null || options === void 0 ? void 0 : options.bitmarkOptions);
55
69
  this.debugGenerationInline = (_b = this.options.debugGenerationInline) !== null && _b !== void 0 ? _b : false;
@@ -66,11 +80,14 @@ class BitmarkGenerator extends AstWalkerGenerator {
66
80
  }
67
81
  // Calculate the prettify space
68
82
  this.prettifySpace = this.options.prettifyJson === true ? 2 : this.options.prettifyJson || undefined;
83
+ // Create the text generator
84
+ this.textGenerator = new TextGenerator(this.bitmarkVersion, {
85
+ writeCallback: this.write,
86
+ bodyBitCallback: this.bodyBitCallback,
87
+ debugGenerationInline: this.debugGenerationInline,
88
+ });
69
89
  this.writer = writer;
70
- this.enter = this.enter.bind(this);
71
- this.between = this.between.bind(this);
72
- this.exit = this.exit.bind(this);
73
- this.leaf = this.leaf.bind(this);
90
+ this.generateResourceHandlers();
74
91
  this.generatePropertyHandlers();
75
92
  }
76
93
  /**
@@ -110,6 +127,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
110
127
  resetState() {
111
128
  this.skipNLBetweenBitsValue = false;
112
129
  this.wroteSomething = false;
130
+ this.inTag = true;
113
131
  this.printed = false;
114
132
  }
115
133
  walkAndWrite(ast) {
@@ -140,12 +158,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
140
158
  this.writeOPD(bit.bitLevel);
141
159
  if (bit.isCommented)
142
160
  this.writeString('|');
143
- this.writeString(bit.bitType);
161
+ this.writeBreakscapedTagString(bit.bitType);
144
162
  if (bit.textFormat) {
145
163
  const write = this.isWriteTextFormat(bit.textFormat, bitConfig.textFormatDefault);
146
164
  if (write) {
147
165
  this.writeColon();
148
- this.writeString(bit.textFormat);
166
+ this.writeBreakscapedTagString(bit.textFormat);
149
167
  }
150
168
  }
151
169
  // Use the bitConfig to see if we need to write the resourceType attachment
@@ -168,10 +186,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
168
186
  }
169
187
  if (resourceType) {
170
188
  this.writeAmpersand();
171
- this.writeString(resourceType);
189
+ this.writeBreakscapedTagString(resourceType);
172
190
  }
173
191
  this.writeCL();
174
192
  this.writeNL();
193
+ // Continue traversal
194
+ return true;
175
195
  }
176
196
  between_bitsValue(node, left, right, route) {
177
197
  // The following keys are combined with other keys so don't need newlines
@@ -192,14 +212,20 @@ class BitmarkGenerator extends AstWalkerGenerator {
192
212
  // Ignore values that are not at the bit level as they might be handled elsewhere
193
213
  const parent = this.getParentNode(route);
194
214
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
195
- return;
215
+ return true;
196
216
  for (let i = 0; i < internalComment.length; i++) {
197
217
  const comment = internalComment[i];
198
218
  const last = i === internalComment.length - 1;
199
- this.writeProperty('internalComment', comment);
219
+ this.writeProperty('internalComment', comment, {
220
+ format: PropertyFormat.trimmedString,
221
+ single: false,
222
+ ignoreEmpty: true,
223
+ });
200
224
  if (!last)
201
225
  this.writeNL();
202
226
  }
227
+ // Stop traversal of this branch
228
+ return false;
203
229
  }
204
230
  // bitmarkAst -> bits -> bitsValue -> labelTrue / labelFalse
205
231
  enter_labelTrue(node, route) {
@@ -207,14 +233,24 @@ class BitmarkGenerator extends AstWalkerGenerator {
207
233
  // Ignore example that is not at the bit level as it are handled elsewhere
208
234
  const parent = this.getParentNode(route);
209
235
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
210
- return;
236
+ return true;
211
237
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
212
238
  if (bit) {
213
239
  if (value != '')
214
- this.writeProperty(PropertyTag.labelTrue, value, true);
240
+ this.writeProperty(PropertyTag.labelTrue, value, {
241
+ format: PropertyFormat.trimmedString,
242
+ single: true,
243
+ ignoreEmpty: true,
244
+ });
215
245
  if (bit.labelFalse && bit.labelFalse[0] != '')
216
- this.writeProperty(PropertyTag.labelFalse, bit.labelFalse, true);
246
+ this.writeProperty(PropertyTag.labelFalse, bit.labelFalse, {
247
+ format: PropertyFormat.trimmedString,
248
+ single: true,
249
+ ignoreEmpty: true,
250
+ });
217
251
  }
252
+ // Stop traversal of this branch
253
+ return false;
218
254
  }
219
255
  // bitmarkAst -> bits -> bitsValue -> imageSource
220
256
  enter_imageSource(node, route) {
@@ -222,19 +258,41 @@ class BitmarkGenerator extends AstWalkerGenerator {
222
258
  // Ignore values that are not at the bit level as they might be handled elsewhere
223
259
  const parent = this.getParentNode(route);
224
260
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
225
- return;
261
+ return true;
226
262
  const { url, mockupId, size, format, trim } = imageSource;
227
- this.writeProperty('imageSource', url, true);
263
+ this.writeProperty('imageSource', url, {
264
+ format: PropertyFormat.trimmedString,
265
+ single: true,
266
+ ignoreEmpty: true,
267
+ });
228
268
  if (url) {
229
269
  if (mockupId)
230
- this.writeProperty('mockupId', mockupId, true);
270
+ this.writeProperty('mockupId', mockupId, {
271
+ format: PropertyFormat.trimmedString,
272
+ single: true,
273
+ ignoreEmpty: true,
274
+ });
231
275
  if (size)
232
- this.writeProperty('size', size, true);
276
+ this.writeProperty('size', size, {
277
+ format: PropertyFormat.trimmedString,
278
+ single: true,
279
+ ignoreEmpty: true,
280
+ });
233
281
  if (format)
234
- this.writeProperty('format', format, true);
282
+ this.writeProperty('format', format, {
283
+ format: PropertyFormat.trimmedString,
284
+ single: true,
285
+ ignoreEmpty: true,
286
+ });
235
287
  if (BooleanUtils.isBoolean(trim))
236
- this.writeProperty('trim', trim, true);
288
+ this.writeProperty('trim', trim, {
289
+ format: PropertyFormat.trimmedString,
290
+ single: true,
291
+ ignoreEmpty: true,
292
+ });
237
293
  }
294
+ // Stop traversal of this branch
295
+ return false;
238
296
  }
239
297
  // bitmarkAst -> bits -> bitsValue -> technicalTerm
240
298
  enter_technicalTerm(node, route) {
@@ -242,11 +300,22 @@ class BitmarkGenerator extends AstWalkerGenerator {
242
300
  // Ignore values that are not at the bit level as they might be handled elsewhere
243
301
  const parent = this.getParentNode(route);
244
302
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
245
- return;
303
+ return true;
246
304
  const { technicalTerm, lang } = nodeValue;
247
- this.writeProperty('technicalTerm', technicalTerm, true);
248
- if (lang != null)
249
- this.writeProperty('lang', lang);
305
+ this.writeProperty('technicalTerm', technicalTerm, {
306
+ format: PropertyFormat.trimmedString,
307
+ single: true,
308
+ ignoreEmpty: true,
309
+ });
310
+ if (lang != null) {
311
+ this.writeProperty('lang', lang, {
312
+ format: PropertyFormat.trimmedString,
313
+ single: true,
314
+ ignoreEmpty: true,
315
+ });
316
+ }
317
+ // Stop traversal of this branch
318
+ return false;
250
319
  }
251
320
  // bitmarkAst -> bits -> bitsValue -> servings
252
321
  enter_servings(node, route) {
@@ -254,17 +323,52 @@ class BitmarkGenerator extends AstWalkerGenerator {
254
323
  // Ignore values that are not at the bit level as they might be handled elsewhere
255
324
  const parent = this.getParentNode(route);
256
325
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
257
- return;
258
- const { servings, unit, unitAbbr, decimalPlaces, disableCalculation } = nodeValue;
259
- this.writeProperty('servings', servings, true);
260
- if (unit != null)
261
- this.writeProperty('unit', unit);
262
- if (unitAbbr != null)
263
- this.writeProperty('unitAbbr', unitAbbr);
264
- if (decimalPlaces != null)
265
- this.writeProperty('decimalPlaces', decimalPlaces);
266
- if (disableCalculation != null)
267
- this.writeProperty('disableCalculation', disableCalculation);
326
+ return true;
327
+ const { servings, unit, unitAbbr, decimalPlaces, disableCalculation, hint } = nodeValue;
328
+ this.writeProperty('servings', servings, {
329
+ format: PropertyFormat.trimmedString,
330
+ single: true,
331
+ ignoreEmpty: true,
332
+ });
333
+ if (unit != null) {
334
+ this.writeProperty('unit', unit, {
335
+ format: PropertyFormat.trimmedString,
336
+ single: true,
337
+ ignoreEmpty: true,
338
+ });
339
+ }
340
+ if (unitAbbr != null) {
341
+ this.writeProperty('unitAbbr', unitAbbr, {
342
+ format: PropertyFormat.trimmedString,
343
+ single: true,
344
+ ignoreEmpty: true,
345
+ });
346
+ }
347
+ if (decimalPlaces != null) {
348
+ this.writeProperty('decimalPlaces', decimalPlaces, {
349
+ format: PropertyFormat.trimmedString,
350
+ single: true,
351
+ ignoreEmpty: true,
352
+ });
353
+ }
354
+ if (disableCalculation != null) {
355
+ this.writeProperty('disableCalculation', disableCalculation, {
356
+ format: PropertyFormat.trimmedString,
357
+ single: true,
358
+ ignoreEmpty: true,
359
+ });
360
+ }
361
+ if (hint != null) {
362
+ this.writeOPQ();
363
+ this.writeBreakscapedTagString(hint);
364
+ this.writeCL();
365
+ // this.writeProperty('hint', hint, {
366
+ // format: PropertyFormat.trimmedString,
367
+ // single: true,
368
+ // ignoreEmpty: true,
369
+ // });
370
+ }
371
+ return false;
268
372
  }
269
373
  // bitmarkAst -> bits -> bitsValue -> person
270
374
  enter_person(node, route) {
@@ -272,15 +376,25 @@ class BitmarkGenerator extends AstWalkerGenerator {
272
376
  // Ignore values that are not at the bit level as they might be handled elsewhere
273
377
  const parent = this.getParentNode(route);
274
378
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
275
- return;
379
+ return true;
276
380
  const { name, title, avatarImage } = person;
277
- this.writeProperty('person', name, true);
381
+ this.writeProperty('person', name, {
382
+ format: PropertyFormat.trimmedString,
383
+ single: true,
384
+ ignoreEmpty: true,
385
+ });
278
386
  if (title) {
279
- this.writeProperty('title', title, true);
387
+ this.writeProperty('title', title, {
388
+ format: PropertyFormat.trimmedString,
389
+ single: true,
390
+ ignoreEmpty: true,
391
+ });
280
392
  }
281
393
  if (avatarImage) {
282
- this.writeResource(avatarImage);
394
+ this.writeResource(ResourceTag.image, avatarImage.src);
283
395
  }
396
+ // Stop traversal of this branch
397
+ return false;
284
398
  }
285
399
  // bitmarkAst -> bits -> bitsValue -> ratingLevelStart
286
400
  enter_ratingLevelStart(node, route) {
@@ -300,45 +414,110 @@ class BitmarkGenerator extends AstWalkerGenerator {
300
414
  // Ignore values that are not at the bit level as they might be handled elsewhere
301
415
  const parent = this.getParentNode(route);
302
416
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
303
- return;
417
+ return true;
304
418
  const { level, label } = n;
305
419
  const levelKey = node.key === NodeType.ratingLevelStart ? PropertyTag.ratingLevelStart : PropertyTag.ratingLevelEnd;
306
- this.writeProperty(levelKey, level, true);
420
+ this.writeProperty(levelKey, level, {
421
+ format: PropertyFormat.trimmedString,
422
+ single: true,
423
+ ignoreEmpty: true,
424
+ });
307
425
  if (label) {
308
- this.writeProperty('label', label, true);
426
+ this.writeProperty('label', label, {
427
+ format: PropertyFormat.bitmarkMinusMinus,
428
+ single: true,
429
+ ignoreEmpty: true,
430
+ });
309
431
  }
432
+ return false;
433
+ }
434
+ // bitmarkAst -> bits -> bitsValue -> markConfig
435
+ enter_markConfig(_node, _route) {
436
+ // Handler so markConfig is not processed by the default property handler
437
+ // Continue traversal
438
+ return true;
310
439
  }
311
- // bitmarkAst -> bits -> bitsValue -> markConfigValue
440
+ // bitmarkAst -> bits -> bitsValue -> markConfig -> markConfigValue
312
441
  enter_markConfigValue(node, route) {
313
442
  const markConfig = node.value;
314
443
  // Ignore values that are not at the correct level as they might be handled elsewhere
315
444
  const parent = this.getParentNode(route);
316
445
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.markConfig)
317
- return;
446
+ return true;
318
447
  const { mark, color, emphasis } = markConfig;
319
448
  if (mark) {
320
- this.writeProperty('mark', mark, true);
321
- if (color)
322
- this.writeProperty('color', color, true);
323
- if (emphasis)
324
- this.writeProperty('emphasis', emphasis, true);
449
+ this.writeProperty('mark', mark, {
450
+ format: PropertyFormat.trimmedString,
451
+ single: true,
452
+ ignoreEmpty: true,
453
+ });
454
+ if (color) {
455
+ this.writeProperty('color', color, {
456
+ format: PropertyFormat.trimmedString,
457
+ single: true,
458
+ ignoreEmpty: true,
459
+ });
460
+ }
461
+ if (emphasis) {
462
+ this.writeProperty('emphasis', emphasis, {
463
+ format: PropertyFormat.trimmedString,
464
+ single: true,
465
+ ignoreEmpty: true,
466
+ });
467
+ }
325
468
  this.writeNL();
326
469
  }
470
+ // Stop traversal of this branch
471
+ return false;
327
472
  }
328
473
  // bitmarkAst -> bits -> bitsValue -> partialAnswer
474
+ enter_partialAnswer(node, _route) {
475
+ this.writeProperty('partialAnswer', node.value, {
476
+ format: PropertyFormat.trimmedString,
477
+ single: true,
478
+ ignoreEmpty: true,
479
+ });
480
+ // Stop traversal of this branch
481
+ return false;
482
+ }
329
483
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> partialAnswer
330
484
  leaf_partialAnswer(node, _route) {
331
- this.writeProperty('partialAnswer', node.value);
485
+ this.writeProperty('partialAnswer', node.value, {
486
+ format: PropertyFormat.trimmedString,
487
+ single: true,
488
+ ignoreEmpty: true,
489
+ });
490
+ // Stop traversal of this branch
491
+ return false;
332
492
  }
333
493
  // bitmarkAst -> bits -> bitsValue -> sampleSolution
334
494
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> sampleSolution
495
+ enter_sampleSolution(node, _route) {
496
+ this.writeProperty('sampleSolution', node.value, {
497
+ format: PropertyFormat.trimmedString,
498
+ single: true,
499
+ ignoreEmpty: true,
500
+ });
501
+ // Stop traversal of this branch
502
+ return false;
503
+ }
335
504
  leaf_sampleSolution(node, _route) {
336
- this.writeProperty('sampleSolution', node.value);
505
+ this.writeProperty('sampleSolution', node.value, {
506
+ format: PropertyFormat.trimmedString,
507
+ single: true,
508
+ ignoreEmpty: true,
509
+ });
510
+ // Stop traversal of this branch
511
+ return false;
337
512
  }
338
513
  // bitmarkAst -> bits -> bitsValue -> reasonableNumOfChars
339
514
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> reasonableNumOfChars
340
515
  leaf_reasonableNumOfChars(node, _route) {
341
- this.writeProperty('reasonableNumOfChars', node.value);
516
+ this.writeProperty('reasonableNumOfChars', node.value, {
517
+ format: PropertyFormat.trimmedString,
518
+ single: true,
519
+ ignoreEmpty: true,
520
+ });
342
521
  }
343
522
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> additionalSolutions
344
523
  between_additionalSolutions(_node, _left, _right, route) {
@@ -354,60 +533,244 @@ class BitmarkGenerator extends AstWalkerGenerator {
354
533
  const parent = this.getParentNode(route, 2);
355
534
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue)
356
535
  return;
357
- this.writeProperty('additionalSolutions', node.value);
358
- }
359
- // bitmarkAst -> bits -> bitsValue -> itemLead
360
- enter_itemLead(node, _route) {
361
- const itemLead = node.value;
362
- if (itemLead && (itemLead.item || itemLead.lead || itemLead.pageNumber || itemLead.marginNumber)) {
363
- // Always write item if item or lead is set
364
- this.writeOPC();
365
- this.writeString(itemLead.item || '');
366
- this.writeCL();
367
- if (itemLead.lead || itemLead.pageNumber || itemLead.marginNumber) {
368
- this.writeOPC();
369
- this.writeString(itemLead.lead || '');
370
- this.writeCL();
371
- }
372
- if (itemLead.pageNumber || itemLead.marginNumber) {
373
- this.writeOPC();
374
- this.writeString(itemLead.pageNumber || '');
375
- this.writeCL();
376
- }
377
- if (itemLead.marginNumber) {
378
- this.writeOPC();
379
- this.writeString(itemLead.marginNumber || '');
380
- this.writeCL();
381
- }
382
- }
536
+ this.writeProperty('additionalSolutions', node.value, {
537
+ format: PropertyFormat.trimmedString,
538
+ single: false,
539
+ });
540
+ }
541
+ // bitmarkAst -> bits -> bitsValue -> item
542
+ enter_item(node, route) {
543
+ var _a, _b, _c;
544
+ const item = node.value;
545
+ const parent = this.getParentNode(route);
546
+ if (this.isEmptyText(item))
547
+ return false; // Ignore empty
548
+ if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.lead))
549
+ return true; // Will be handled by lead
550
+ if (!this.isEmptyText((_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.pageNumber))
551
+ return true; // Will be handled by pageNumber
552
+ if (!this.isEmptyText((_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.marginNumber))
553
+ return true; // Will be handled by marginNumber
554
+ this.writeOPC();
555
+ this.textGenerator.generateSync(item, TextFormat.bitmarkMinusMinus);
556
+ this.writeCL();
557
+ return true;
558
+ }
559
+ // bitmarkAst -> bits -> bitsValue -> lead
560
+ enter_lead(node, route) {
561
+ var _a, _b, _c, _d;
562
+ const lead = node.value;
563
+ const parent = this.getParentNode(route);
564
+ if (this.isEmptyText(lead))
565
+ return false; // Ignore empty
566
+ if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.pageNumber))
567
+ return true; // Will be handled by pageNumber
568
+ if (!this.isEmptyText((_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.marginNumber))
569
+ return true; // Will be handled by marginNumber
570
+ this.writeOPC();
571
+ this.textGenerator.generateSync((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.item) !== null && _d !== void 0 ? _d : '', TextFormat.bitmarkMinusMinus);
572
+ this.writeCL();
573
+ this.writeOPC();
574
+ this.textGenerator.generateSync(lead, TextFormat.bitmarkMinusMinus);
575
+ this.writeCL();
576
+ return true;
577
+ }
578
+ // bitmarkAst -> bits -> bitsValue -> pageNumber
579
+ enter_pageNumber(node, route) {
580
+ var _a, _b, _c, _d, _e;
581
+ const pageNumber = node.value;
582
+ const parent = this.getParentNode(route);
583
+ if (this.isEmptyText(pageNumber))
584
+ return false; // Ignore empty
585
+ if (!this.isEmptyText((_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.marginNumber))
586
+ return true; // Will be handled by marginNumber
587
+ this.writeOPC();
588
+ this.textGenerator.generateSync((_c = (_b = parent === null || parent === void 0 ? void 0 : parent.value) === null || _b === void 0 ? void 0 : _b.item) !== null && _c !== void 0 ? _c : '', TextFormat.bitmarkMinusMinus);
589
+ this.writeCL();
590
+ this.writeOPC();
591
+ this.textGenerator.generateSync((_e = (_d = parent === null || parent === void 0 ? void 0 : parent.value) === null || _d === void 0 ? void 0 : _d.lead) !== null && _e !== void 0 ? _e : '', TextFormat.bitmarkMinusMinus);
592
+ this.writeCL();
593
+ this.writeOPC();
594
+ this.textGenerator.generateSync(pageNumber !== null && pageNumber !== void 0 ? pageNumber : '', TextFormat.bitmarkMinusMinus);
595
+ this.writeCL();
596
+ return true;
597
+ }
598
+ // bitmarkAst -> bits -> bitsValue -> marginNumber
599
+ enter_marginNumber(node, route) {
600
+ var _a, _b, _c, _d, _e, _f;
601
+ const marginNumber = node.value;
602
+ const parent = this.getParentNode(route);
603
+ if (this.isEmptyText(marginNumber))
604
+ return false; // Ignore empty
605
+ this.writeOPC();
606
+ this.textGenerator.generateSync((_b = (_a = parent === null || parent === void 0 ? void 0 : parent.value) === null || _a === void 0 ? void 0 : _a.item) !== null && _b !== void 0 ? _b : '', TextFormat.bitmarkMinusMinus);
607
+ this.writeCL();
608
+ this.writeOPC();
609
+ this.textGenerator.generateSync((_d = (_c = parent === null || parent === void 0 ? void 0 : parent.value) === null || _c === void 0 ? void 0 : _c.lead) !== null && _d !== void 0 ? _d : '', TextFormat.bitmarkMinusMinus);
610
+ this.writeCL();
611
+ this.writeOPC();
612
+ this.textGenerator.generateSync((_f = (_e = parent === null || parent === void 0 ? void 0 : parent.value) === null || _e === void 0 ? void 0 : _e.pageNumber) !== null && _f !== void 0 ? _f : '', TextFormat.bitmarkMinusMinus);
613
+ this.writeCL();
614
+ this.writeOPC();
615
+ this.textGenerator.generateSync(marginNumber, TextFormat.bitmarkMinusMinus);
616
+ this.writeCL();
617
+ return true;
383
618
  }
384
619
  // bitmarkAst -> bits -> bitsValue -> body
385
620
  enter_body(node, route) {
621
+ var _a;
622
+ // Ignore values that are not at the bit level as they might be handled elsewhere
623
+ const parent = this.getParentNode(route);
624
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardBitsValue)
625
+ return true;
626
+ this.inTag = false;
386
627
  // always write a NL before the body content if there is any?
387
628
  const body = node.value;
388
- if ((body.bodyParts && body.bodyParts.length > 0) || body.bodyJson) {
629
+ const textFormat = this.getTextFormat(route);
630
+ const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
631
+ // Handle body
632
+ if (textFormat === TextFormat.json) {
633
+ const json = (_a = body.body) !== null && _a !== void 0 ? _a : null;
634
+ if (Array.isArray(json) || ObjectUtils.isObject(json)) {
635
+ const text = JSON.stringify(json, null, this.prettifySpace);
636
+ if (text) {
637
+ this.writeNL();
638
+ this.writePlainTextDivider();
639
+ this.writeNL();
640
+ this.write(Breakscape.breakscape(text, {
641
+ textFormat: TextFormat.text,
642
+ }));
643
+ }
644
+ }
645
+ }
646
+ else if (isBitmarkText) {
647
+ // handle bitmark text
389
648
  this.writeNL();
390
- // Write the plain text divider if not bitmark++/-- format
391
- const textFormat = this.getTextFormat(route);
649
+ // The text generator will write to the writer
650
+ const b = (Array.isArray(body.body) ? body.body : []);
651
+ this.textGenerator.generateSync(b, textFormat);
652
+ }
653
+ else {
654
+ // handle plain text
655
+ this.writeNL();
656
+ this.writePlainTextDivider();
657
+ this.writeNL();
658
+ const s = (StringUtils.isString(body.body) ? body.body : '');
659
+ this.write(Breakscape.breakscape(`${s}`, {
660
+ textFormat: TextFormat.text,
661
+ }));
662
+ this.writeNL();
663
+ }
664
+ // Stop traversal of this branch
665
+ return false;
666
+ // if ((body.body && body.body.length > 0) || body.bodyJson) {
667
+ // this.writeNL();
668
+ // // Write the plain text divider if not bitmark++/-- format
669
+ // const textFormat = this.getTextFormat(route);
670
+ // const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
671
+ // if (!isBitmarkText) {
672
+ // this.writePlainTextDivider();
673
+ // this.writeNL();
674
+ // }
675
+ // }
676
+ }
677
+ exit_body(_node, _route) {
678
+ this.inTag = true;
679
+ }
680
+ bodyBitCallback(bodyBit, _index, _route) {
681
+ // console.log('bodyBitCallback', bodyBit, index, route);
682
+ var _a;
683
+ // Walk the body bit AST
684
+ const nodeType = (_a = NodeType.fromValue(bodyBit.type)) !== null && _a !== void 0 ? _a : NodeType.bodyBit;
685
+ this.ast.walk(bodyBit, nodeType, this, undefined);
686
+ return ''; // Return empty string as we are writing to the writer
687
+ }
688
+ // bodyBit -> gap
689
+ enter_gap(node, _route) {
690
+ const gap = node.value;
691
+ if (gap.solutions && gap.solutions.length === 0) {
692
+ // If there are no solutions, we need to write the special cloze gap [_] to indicate this
693
+ this.writeOPU();
694
+ this.writeCL();
695
+ }
696
+ else {
697
+ for (const solution of gap.solutions) {
698
+ this.writeOPU();
699
+ this.writeBreakscapedTagString(solution);
700
+ this.writeCL();
701
+ }
702
+ }
703
+ // Continue traversal
704
+ return true;
705
+ }
706
+ // bodyBit -> mark
707
+ enter_mark(node, _route) {
708
+ const mark = node.value;
709
+ this.writeOPE();
710
+ this.writeBreakscapedTagString(mark.solution);
711
+ this.writeCL();
712
+ // Continue traversal
713
+ return true;
714
+ }
715
+ // bodyBit -> select
716
+ enter_select(_node, _route) {
717
+ // Continue traversal
718
+ return true;
719
+ }
720
+ // bodyBit -> highlight
721
+ enter_highlight(_node, _route) {
722
+ // Continue traversal
723
+ return true;
724
+ }
725
+ // bitmarkAst -> bits -> footer
726
+ enter_footer(node, route) {
727
+ const parent = this.getParentNode(route);
728
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
729
+ return true;
730
+ const footer = node.value;
731
+ const textFormat = this.getTextFormat(route);
732
+ // Handle footer
733
+ if (textFormat === TextFormat.json) {
734
+ // Json footer?!
735
+ // Not valid, ignore
736
+ }
737
+ else if (footer.footer && footer.footer.length > 0) {
392
738
  const isBitmarkText = textFormat === TextFormat.bitmarkPlusPlus || textFormat === TextFormat.bitmarkMinusMinus;
393
- if (!isBitmarkText) {
394
- this.writePlainTextDivider();
739
+ if (isBitmarkText) {
740
+ // handle bitmark text
741
+ this.write('~~~~');
395
742
  this.writeNL();
743
+ // The text generator will write to the writer
744
+ this.textGenerator.generateSync(footer.footer, TextFormat.text);
745
+ }
746
+ else {
747
+ // Plain text footer?!
748
+ // Not valid, ignore (plain text cannot have a card set / footer marker, so cannot have a footer!
396
749
  }
397
750
  }
751
+ // Stop traversal of this branch
752
+ return false;
398
753
  }
399
754
  // bitmarkAst -> bits -> bitsValue -> body -> bodyParts -> bodyPartsValue -> data -> solutions
400
- enter_solutions(node, _route) {
755
+ enter_solutions(node, route) {
756
+ const parent = this.getParentNode(route);
757
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
758
+ return true;
401
759
  const solutions = node.value;
402
760
  if (solutions && solutions.length === 0) {
403
761
  // If there are no solutions, we need to write the special cloze gap [_] to indicate this
404
762
  this.writeOPU();
405
763
  this.writeCL();
406
764
  }
765
+ // Continue traversal
766
+ return true;
407
767
  }
408
768
  // bitmarkAst -> bits -> bitsValue -> body -> bodyParts -> bodyPartsValue -> data -> solution
409
769
  leaf_solution(node, route) {
410
770
  var _a;
771
+ const parent = this.getParentNode(route);
772
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
773
+ return;
411
774
  const solution = node.value;
412
775
  // Ignore values that are not at the correct level as they might be handled elsewhere
413
776
  const bodyPartsValue = (_a = this.getParentNode(route, 2)) === null || _a === void 0 ? void 0 : _a.value;
@@ -415,20 +778,22 @@ class BitmarkGenerator extends AstWalkerGenerator {
415
778
  return;
416
779
  if (solution) {
417
780
  this.writeOPE();
418
- this.writeString(solution);
781
+ this.writeBreakscapedTagString(solution);
419
782
  this.writeCL();
420
783
  }
421
784
  }
422
- // bitmarkAst -> bits -> bitsValue -> body -> bodyParts -> bodyPartsValue -> data -> mark
785
+ // bitmarkAst -> bits -> bitsValue -> body -> bodyBit -> mark -> mark
423
786
  leaf_mark(node, route) {
424
- var _a;
425
- const mark = node.value;
426
- // Ignore values that are not at the correct level as they might be handled elsewhere
427
- const bodyPartsValue = (_a = this.getParentNode(route, 2)) === null || _a === void 0 ? void 0 : _a.value;
428
- if ((bodyPartsValue === null || bodyPartsValue === void 0 ? void 0 : bodyPartsValue.type) !== BodyBitType.mark)
787
+ const root = route[0];
788
+ if ((root === null || root === void 0 ? void 0 : root.key) !== NodeType.mark)
429
789
  return;
790
+ const mark = node.value;
430
791
  if (mark) {
431
- this.writeProperty('mark', mark, true);
792
+ this.writeProperty('mark', mark, {
793
+ format: PropertyFormat.trimmedString,
794
+ single: true,
795
+ ignoreEmpty: true,
796
+ });
432
797
  }
433
798
  }
434
799
  // bitmarkAst -> bits -> bitsValue -> body -> bodyParts -> bodyPartsValue -> data -> options -> optionsValue
@@ -442,6 +807,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
442
807
  }
443
808
  this.write(selectOption.text);
444
809
  this.writeCL();
810
+ // Continue traversal
811
+ return true;
445
812
  }
446
813
  // bitmarkAst -> bits -> bitsValue -> body -> bodyParts -> bodyPartsValue -> data -> texts -> textsValue
447
814
  enter_textsValue(node, _route) {
@@ -454,15 +821,19 @@ class BitmarkGenerator extends AstWalkerGenerator {
454
821
  }
455
822
  this.write(highlightText.text);
456
823
  this.writeCL();
824
+ // Continue traversal
825
+ return true;
457
826
  }
458
827
  // bitmarkAst -> bits -> bitsValue -> cardNode
459
828
  enter_cardNode(_node, route) {
460
829
  // Ignore cards for xxx-1
461
830
  const isBitType1 = this.isOfBitType1(route);
462
831
  if (isBitType1)
463
- return;
832
+ return true;
464
833
  this.writeCardSetStart();
465
834
  this.writeNL();
835
+ // Continue traversal
836
+ return true;
466
837
  }
467
838
  between_cardNode(_node, _left, _right, route) {
468
839
  // Ignore cards for xxx-1
@@ -504,26 +875,29 @@ class BitmarkGenerator extends AstWalkerGenerator {
504
875
  }
505
876
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue
506
877
  between_flashcardsValue(_node, _left, right, _route) {
878
+ var _a;
507
879
  if (right.key === NodeType.answer) {
508
880
  this.writeNL();
509
881
  this.writeCardSetSideDivider();
510
882
  this.writeNL();
511
883
  }
512
- else if (right.key === NodeType.alternativeAnswers) {
884
+ else if (right.key === NodeType.alternativeAnswers && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
513
885
  this.writeNL();
514
886
  this.writeCardSetVariantDivider();
515
887
  this.writeNL();
516
888
  }
517
889
  }
518
890
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> answer
519
- leaf_answer(node, route) {
891
+ enter_answer(node, route) {
520
892
  // Ignore responses that are not at the flashcardsValue level as they are handled elsewhere
521
893
  const parent = this.getParentNode(route);
522
894
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
523
- return;
895
+ return true;
524
896
  if (node.value) {
525
- this.writeString(node.value);
897
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
526
898
  }
899
+ // Stop traversal of this branch
900
+ return false;
527
901
  }
528
902
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers
529
903
  between_alternativeAnswers(_node, _route) {
@@ -532,30 +906,38 @@ class BitmarkGenerator extends AstWalkerGenerator {
532
906
  this.writeNL();
533
907
  }
534
908
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards -> flashcardsValue -> alternativeAnswers -> alternativeAnswersValue
535
- leaf_alternativeAnswersValue(node, route) {
909
+ enter_alternativeAnswersValue(node, route) {
536
910
  // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
537
911
  const parent = this.getParentNode(route);
538
912
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.alternativeAnswers)
539
- return;
913
+ return true;
540
914
  if (node.value) {
541
- this.writeString(node.value);
915
+ // this.writeBreakscapedTagString(node.value);
916
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
542
917
  }
918
+ // Stop traversal of this branch
919
+ return false;
543
920
  }
544
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions
921
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefintions
545
922
  between_alternativeDefinitions(_node, _route) {
546
923
  this.writeNL();
547
924
  this.writeCardSetVariantDivider();
548
925
  this.writeNL();
549
926
  }
550
927
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> alternativeDefinitions -> alternativeDefinitionsValue
551
- leaf_alternativeDefinitionsValue(node, route) {
552
- // Ignore responses that are not at the alternativeDefinitions level as they are handled elsewhere
928
+ enter_alternativeDefinitionsValue(node, route) {
929
+ // Ignore responses that are not at the alternativeAnswers level as they are handled elsewhere
553
930
  const parent = this.getParentNode(route);
554
931
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.alternativeDefinitions)
555
- return;
932
+ return true;
556
933
  if (node.value) {
557
- this.writeString(node.value);
934
+ // this.writeNL();
935
+ // this.writeCardSetVariantDivider();
936
+ // this.writeNL();
937
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
558
938
  }
939
+ // Stop traversal of this branch
940
+ return false;
559
941
  }
560
942
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements
561
943
  enter_statements(_node, _route) {
@@ -581,8 +963,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
581
963
  else {
582
964
  this.writeOPM();
583
965
  }
584
- this.write(statement.text);
966
+ this.write(statement.statement);
585
967
  this.writeCL();
968
+ // Continue traversal
969
+ return true;
586
970
  }
587
971
  // bitmarkAst -> bits -> bitsValue -> choices
588
972
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
@@ -602,8 +986,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
602
986
  else {
603
987
  this.writeOPM();
604
988
  }
605
- this.write(choice.text);
989
+ this.write(choice.choice);
606
990
  this.writeCL();
991
+ // Continue traversal
992
+ return true;
607
993
  }
608
994
  // bitmarkAst -> bits -> bitsValue -> responses
609
995
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
@@ -623,8 +1009,10 @@ class BitmarkGenerator extends AstWalkerGenerator {
623
1009
  else {
624
1010
  this.writeOPM();
625
1011
  }
626
- this.write(response.text);
1012
+ this.write(response.response);
627
1013
  this.writeCL();
1014
+ // Continue traversal
1015
+ return true;
628
1016
  }
629
1017
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
630
1018
  enter_quizzes(_node, _route) {
@@ -688,13 +1076,17 @@ class BitmarkGenerator extends AstWalkerGenerator {
688
1076
  enter_keyAudio(node, _route) {
689
1077
  const resource = node.value;
690
1078
  // This is a resource, so handle it with the common code
691
- this.writeResource(resource);
1079
+ this.writeResource(ResourceTag.audio, resource.src);
1080
+ // Stop traversal of this branch
1081
+ return false;
692
1082
  }
693
1083
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs -> pairsValue -> keyImage
694
1084
  enter_keyImage(node, _route) {
695
1085
  const resource = node.value;
696
1086
  // This is a resource, so handle it with the common code
697
- this.writeResource(resource);
1087
+ this.writeResource(ResourceTag.image, resource.src);
1088
+ // Stop traversal of this branch
1089
+ return false;
698
1090
  }
699
1091
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
700
1092
  enter_matrix(_node, _route) {
@@ -733,8 +1125,8 @@ class BitmarkGenerator extends AstWalkerGenerator {
733
1125
  this.writeCardSetCardDivider();
734
1126
  this.writeNL();
735
1127
  }
736
- // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> rows
737
- between_rows(_node, _left, _right, route) {
1128
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data
1129
+ between_data(_node, _left, _right, route) {
738
1130
  const parent = this.getParentNode(route);
739
1131
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table)
740
1132
  return;
@@ -758,20 +1150,23 @@ class BitmarkGenerator extends AstWalkerGenerator {
758
1150
  leaf_columnsValue(node, _route) {
759
1151
  this.writeOPHASH();
760
1152
  if (node.value)
761
- this.writeString(node.value);
1153
+ this.writeBreakscapedTagString(node.value);
762
1154
  this.writeCL();
763
1155
  }
764
- // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> rows -> rowsValue
765
- between_rowsValue(_node, _left, _right, route) {
766
- const parent = this.getParentNode(route);
767
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.rows)
1156
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue
1157
+ between_dataValue(_node, _left, _right, route) {
1158
+ const parent = this.getParentNode(route, 2);
1159
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table)
768
1160
  return;
769
1161
  this.writeNL();
770
1162
  this.writeCardSetSideDivider();
771
1163
  this.writeNL();
772
1164
  }
773
- // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> rows -> rowsValue -> rowsValueValue
774
- leaf_rowsValueValue(node, _route) {
1165
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> table -> data -> dataValue -> dataValueValue
1166
+ leaf_dataValueValue(node, route) {
1167
+ const parent = this.getParentNode(route, 3);
1168
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.table)
1169
+ return;
775
1170
  if (node.value)
776
1171
  this.write(node.value);
777
1172
  }
@@ -800,23 +1195,49 @@ class BitmarkGenerator extends AstWalkerGenerator {
800
1195
  // this.writeCardSetSideDivider();
801
1196
  // this.writeNL();
802
1197
  // }
803
- // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> term
804
1198
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> term
1199
+ enter_term(node, route) {
1200
+ const parent = this.getParentNode(route);
1201
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1202
+ return true;
1203
+ if (node.value) {
1204
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1205
+ }
1206
+ // Stop traversal of this branch
1207
+ return false;
1208
+ }
1209
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> term
805
1210
  leaf_term(node, route) {
806
1211
  const parent = this.getParentNode(route);
807
1212
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
808
- return;
809
- if (node.value)
1213
+ return true;
1214
+ if (node.value) {
810
1215
  this.write(node.value);
1216
+ }
1217
+ // Stop traversal of this branch
1218
+ return false;
811
1219
  }
812
- // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> description
813
- // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> description
814
- leaf_description(node, route) {
1220
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue -> definition
1221
+ enter_definition(node, route) {
815
1222
  const parent = this.getParentNode(route);
816
1223
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
817
- return;
818
- if (node.value)
1224
+ return true;
1225
+ if (node.value) {
1226
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1227
+ }
1228
+ // Stop traversal of this branch
1229
+ return false;
1230
+ }
1231
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue -> definition
1232
+ leaf_definition(node, route) {
1233
+ const parent = this.getParentNode(route);
1234
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitionsValue)
1235
+ return true;
1236
+ if (node.value) {
819
1237
  this.write(node.value);
1238
+ }
1239
+ // Stop traversal of this branch
1240
+ return false;
820
1241
  }
821
1242
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions
822
1243
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions
@@ -828,23 +1249,37 @@ class BitmarkGenerator extends AstWalkerGenerator {
828
1249
  this.writeCardSetCardDivider();
829
1250
  this.writeNL();
830
1251
  }
831
- // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
832
1252
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions -> definitionsValue
833
1253
  between_definitionsValue(_node, _left, right, route) {
1254
+ var _a;
834
1255
  const parent = this.getParentNode(route);
835
1256
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.definitions)
836
1257
  return;
837
- if (right.key === NodeType.description) {
1258
+ if (right.key === NodeType.definition) {
838
1259
  this.writeNL();
839
1260
  this.writeCardSetSideDivider();
840
1261
  this.writeNL();
841
1262
  }
842
- else if (right.key === NodeType.alternativeDefinitions) {
1263
+ else if (right.key === NodeType.alternativeDefinitions && ((_a = right.value) === null || _a === void 0 ? void 0 : _a.length) > 0) {
843
1264
  this.writeNL();
844
1265
  this.writeCardSetVariantDivider();
845
1266
  this.writeNL();
846
1267
  }
847
1268
  }
1269
+ // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList -> definitions -> definitionsValue
1270
+ // protected between_definitionsValue(_node: NodeInfo, _left: NodeInfo, right: NodeInfo, route: NodeInfo[]): void {
1271
+ // const parent = this.getParentNode(route);
1272
+ // if (parent?.key !== NodeType.definitions) return;
1273
+ // if (right.key === NodeType.definition) {
1274
+ // this.writeNL();
1275
+ // this.writeCardSetSideDivider();
1276
+ // this.writeNL();
1277
+ // } else if (right.key === NodeType.alternativeDefinitions && right.value?.length > 0) {
1278
+ // this.writeNL();
1279
+ // this.writeCardSetVariantDivider();
1280
+ // this.writeNL();
1281
+ // }
1282
+ // }
848
1283
  // bitmarkAst -> bits -> bitsValue -> cardNode -> questions
849
1284
  enter_questions(_node, _route) {
850
1285
  //
@@ -884,7 +1319,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
884
1319
  const ingredient = node.value;
885
1320
  if (ingredient.title != null) {
886
1321
  this.writeOPHASH();
887
- this.writeString(ingredient.title);
1322
+ this.writeBreakscapedTagString(ingredient.title);
888
1323
  this.writeCL();
889
1324
  this.writeNL();
890
1325
  }
@@ -899,24 +1334,42 @@ class BitmarkGenerator extends AstWalkerGenerator {
899
1334
  // [!43]
900
1335
  if (ingredient.quantity != null) {
901
1336
  this.writeOPB();
902
- this.writeString(`${ingredient.quantity}`);
1337
+ this.writeBreakscapedTagString(`${ingredient.quantity}`);
903
1338
  this.writeCL();
904
1339
  }
905
1340
  // [@unit:kilograms]
906
1341
  if (ingredient.unit != null)
907
- this.writeProperty('unit', ingredient.unit, true);
1342
+ this.writeProperty('unit', ingredient.unit, {
1343
+ format: PropertyFormat.trimmedString,
1344
+ single: true,
1345
+ ignoreEmpty: true,
1346
+ });
908
1347
  // [@unitAbbr:kg]
909
1348
  if (ingredient.unitAbbr != null)
910
- this.writeProperty('unitAbbr', ingredient.unitAbbr, true);
1349
+ this.writeProperty('unitAbbr', ingredient.unitAbbr, {
1350
+ format: PropertyFormat.trimmedString,
1351
+ single: true,
1352
+ ignoreEmpty: true,
1353
+ });
911
1354
  // [@decimalPlaces:1]
912
1355
  if (ingredient.decimalPlaces != null)
913
- this.writeProperty('decimalPlaces', ingredient.decimalPlaces, true);
1356
+ this.writeProperty('decimalPlaces', ingredient.decimalPlaces, {
1357
+ format: PropertyFormat.trimmedString,
1358
+ single: true,
1359
+ ignoreEmpty: true,
1360
+ });
914
1361
  // [@disableCalculation]
915
1362
  if (ingredient.disableCalculation)
916
- this.writeProperty('disableCalculation', true, true);
1363
+ this.writeProperty('disableCalculation', true, {
1364
+ format: PropertyFormat.trimmedString,
1365
+ single: true,
1366
+ ignoreEmpty: true,
1367
+ });
917
1368
  // item
918
1369
  if (ingredient.item != null)
919
1370
  this.write(ingredient.item);
1371
+ // Stop traversal of this branch
1372
+ return false;
920
1373
  }
921
1374
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses
922
1375
  enter_botResponses(_node, _route) {
@@ -949,37 +1402,42 @@ class BitmarkGenerator extends AstWalkerGenerator {
949
1402
  //
950
1403
  }
951
1404
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> response
952
- leaf_response(node, _route) {
1405
+ leaf_response(node, route) {
1406
+ const parent = this.getParentNode(route);
1407
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
1408
+ return;
953
1409
  this.writeOPB();
954
- this.writeString(node.value);
1410
+ this.writeBreakscapedTagString(node.value);
955
1411
  this.writeCL();
956
1412
  }
957
1413
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> reaction
958
- leaf_reaction(node, _route) {
959
- this.writeProperty('reaction', node.value, true);
1414
+ leaf_reaction(node, route) {
1415
+ const parent = this.getParentNode(route);
1416
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
1417
+ return;
1418
+ this.writeProperty('reaction', node.value, {
1419
+ format: PropertyFormat.trimmedString,
1420
+ single: true,
1421
+ ignoreEmpty: true,
1422
+ });
960
1423
  }
961
1424
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses -> botResponsesValue -> feedback
962
- leaf_feedback(node, _route) {
1425
+ leaf_feedback(node, route) {
1426
+ const parent = this.getParentNode(route);
1427
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.botResponsesValue)
1428
+ return;
963
1429
  const feeback = node.value;
964
1430
  if (feeback) {
965
1431
  this.write(feeback);
966
1432
  }
967
1433
  }
968
- // bitmarkAst -> bits -> bitsValue -> resources
969
- between_resources(_node, _left, _right, _route) {
970
- this.writeNL();
971
- }
972
- // bitmarkAst -> bits -> bitsValue -> resourcesValue
973
- enter_resourcesValue(node, _route) {
974
- const resource = node.value;
975
- // This is a resource, so handle it with the common code
976
- this.writeResource(resource);
977
- }
978
1434
  // bitmarkAst -> bits -> bitsValue -> imagePlaceholder
979
1435
  enter_imagePlaceholder(node, _route) {
980
1436
  const resource = node.value;
981
1437
  // This is a resource, so handle it with the common code
982
1438
  this.writePropertyStyleResource(node.key, resource);
1439
+ // Continue traversal
1440
+ return true;
983
1441
  }
984
1442
  exit_imagePlaceholder(_node, _route) {
985
1443
  this.writeNL();
@@ -992,16 +1450,26 @@ class BitmarkGenerator extends AstWalkerGenerator {
992
1450
  // Bit poster image
993
1451
  const posterImage = node.value;
994
1452
  if (posterImage) {
995
- this.writeProperty('posterImage', posterImage);
1453
+ this.writeProperty('posterImage', posterImage, {
1454
+ format: PropertyFormat.trimmedString,
1455
+ single: true,
1456
+ ignoreEmpty: true,
1457
+ });
996
1458
  }
997
1459
  }
998
1460
  else {
999
1461
  // Resource poster image
1000
1462
  const posterImage = node.value;
1001
- if (posterImage && posterImage.value) {
1002
- this.writeProperty('posterImage', posterImage.value);
1463
+ if (posterImage && posterImage.src) {
1464
+ this.writeProperty('posterImage', posterImage.src, {
1465
+ format: PropertyFormat.trimmedString,
1466
+ single: true,
1467
+ ignoreEmpty: true,
1468
+ });
1003
1469
  }
1004
1470
  }
1471
+ // Continue traversal
1472
+ return true;
1005
1473
  }
1006
1474
  // bitmarkAst -> bits -> bitsValue -> resource -> thumbnails
1007
1475
  // [src1x,src2x,src3x,src4x,width,height,alt,zoomDisabled,caption]
@@ -1015,21 +1483,24 @@ class BitmarkGenerator extends AstWalkerGenerator {
1015
1483
  break;
1016
1484
  const thumbnail = thumbnails[i];
1017
1485
  const key = thumbnailKeys[i];
1018
- this.writeProperty(key, thumbnail.value, true);
1486
+ this.writeProperty(key, thumbnail.src, {
1487
+ format: PropertyFormat.trimmedString,
1488
+ single: true,
1489
+ ignoreEmpty: true,
1490
+ });
1019
1491
  }
1020
1492
  }
1493
+ // Stop traversal of this branch
1494
+ return false;
1021
1495
  }
1022
- //
1023
- // Terminal nodes (leaves)
1024
- //
1025
1496
  // bitmarkAst -> bits -> bitsValue -> bitType
1026
1497
  // bitmarkAst -> bits -> bitsValue -> textFormat
1027
1498
  // bitmarkAst -> bits -> title
1028
- leaf_title(node, route) {
1029
- const parent = this.getParentNode(route);
1499
+ enter_title(node, route) {
1030
1500
  // Ensure this is at the bit level
1501
+ const parent = this.getParentNode(route);
1031
1502
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
1032
- return;
1503
+ return true;
1033
1504
  const value = node.value;
1034
1505
  const title = value;
1035
1506
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
@@ -1038,12 +1509,18 @@ class BitmarkGenerator extends AstWalkerGenerator {
1038
1509
  this.writeOP();
1039
1510
  for (let i = 0; i < +level; i++)
1040
1511
  this.writeHash();
1041
- this.writeString(title);
1512
+ this.textGenerator.generateSync(title, TextFormat.bitmarkMinusMinus);
1042
1513
  this.writeCL();
1043
1514
  }
1515
+ // Stop traversal of this branch
1516
+ return false;
1044
1517
  }
1045
1518
  // bitmarkAst -> bits -> subtitle
1046
- leaf_subtitle(node, _route) {
1519
+ enter_subtitle(node, route) {
1520
+ // Ensure this is at the bit level
1521
+ const parent = this.getParentNode(route);
1522
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
1523
+ return true;
1047
1524
  const value = node.value;
1048
1525
  const subtitle = value;
1049
1526
  const level = 2;
@@ -1051,23 +1528,61 @@ class BitmarkGenerator extends AstWalkerGenerator {
1051
1528
  this.writeOP();
1052
1529
  for (let i = 0; i < level; i++)
1053
1530
  this.writeHash();
1054
- this.writeString(subtitle);
1531
+ this.textGenerator.generateSync(subtitle, TextFormat.bitmarkMinusMinus);
1055
1532
  this.writeCL();
1056
1533
  }
1534
+ // Stop traversal of this branch
1535
+ return false;
1536
+ }
1537
+ // bitmarkAst -> bits -> bitsValue -> book (array)
1538
+ // bitmarkAst -> bits -> bitsValue -> book (array) -> bookValue
1539
+ enter_book(_node, _route) {
1540
+ // Block standard property handling
1541
+ }
1542
+ between_book(_node, _route) {
1543
+ this.writeNL();
1544
+ }
1545
+ enter_bookValue(node, _route) {
1546
+ const book = node.value;
1547
+ // const parent = this.getParentNode(route);
1548
+ // const bit = parent?.value as Bit;
1549
+ if (book) {
1550
+ this.writeProperty('book', book.book, {
1551
+ format: PropertyFormat.trimmedString,
1552
+ single: true,
1553
+ ignoreEmpty: false,
1554
+ });
1555
+ if (book.reference) {
1556
+ this.writeOPRANGLE();
1557
+ this.writeBreakscapedTagString(book.reference);
1558
+ this.writeCL();
1559
+ if (book.referenceEnd) {
1560
+ this.writeOPRANGLE();
1561
+ this.writeBreakscapedTagString(book.referenceEnd);
1562
+ this.writeCL();
1563
+ }
1564
+ }
1565
+ }
1566
+ // Stop traversal of this branch
1567
+ return false;
1057
1568
  }
1058
- // bitmarkAst -> bits -> bitsValue -> book
1569
+ // bitmarkAst -> bits -> bitsValue -> book (single)
1059
1570
  leaf_book(node, route) {
1060
1571
  const parent = this.getParentNode(route);
1061
1572
  const bit = parent === null || parent === void 0 ? void 0 : parent.value;
1062
1573
  if (bit && node.value) {
1063
- this.writeProperty('book', node.value);
1574
+ this.writeProperty('book', node.value, {
1575
+ format: PropertyFormat.trimmedString,
1576
+ single: true,
1577
+ ignoreEmpty: false,
1578
+ });
1064
1579
  if (bit.reference) {
1065
1580
  this.writeOPRANGLE();
1066
- this.writeString(bit.reference);
1581
+ this.writeBreakscapedTagString(bit.reference);
1067
1582
  this.writeCL();
1068
1583
  if (bit.referenceEnd) {
1069
1584
  this.writeOPRANGLE();
1070
- this.writeString(bit.referenceEnd);
1585
+ this.writeBreakscapedTagString(bit.referenceEnd);
1071
1586
  this.writeCL();
1072
1587
  }
1073
1588
  }
@@ -1077,7 +1592,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1077
1592
  leaf_anchor(node, _route) {
1078
1593
  if (node.value) {
1079
1594
  this.writeOPDANGLE();
1080
- this.writeString(node.value);
1595
+ this.writeBreakscapedTagString(node.value);
1081
1596
  this.writeCL();
1082
1597
  }
1083
1598
  }
@@ -1089,7 +1604,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1089
1604
  // Only write reference if it is not chained to 'book'
1090
1605
  if (!bit.book) {
1091
1606
  this.writeOPRANGLE();
1092
- this.writeString(node.value);
1607
+ this.writeBreakscapedTagString(node.value);
1093
1608
  this.writeCL();
1094
1609
  }
1095
1610
  }
@@ -1097,101 +1612,80 @@ class BitmarkGenerator extends AstWalkerGenerator {
1097
1612
  // * -> itemLead --> item
1098
1613
  // * -> itemLead --> lead
1099
1614
  // * -> hint
1100
- leaf_hint(node, _route) {
1615
+ enter_hint(node, _route) {
1101
1616
  const value = node.value;
1102
1617
  const text = value;
1103
- if (text) {
1618
+ if (!this.isEmptyText(text)) {
1104
1619
  this.writeOPQ();
1105
- this.writeString(text);
1620
+ this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1106
1621
  this.writeCL();
1107
1622
  }
1623
+ // Stop traversal of this branch
1624
+ return false;
1108
1625
  }
1109
1626
  // bitmarkAst -> bits -> bitsValue -> * -> instruction
1110
- leaf_instruction(node, _route) {
1627
+ enter_instruction(node, _route) {
1111
1628
  const value = node.value;
1112
1629
  const text = value;
1113
- if (text) {
1630
+ if (!this.isEmptyText(text)) {
1114
1631
  this.writeOPB();
1115
- this.writeString(text);
1632
+ this.textGenerator.generateSync(text, TextFormat.bitmarkMinusMinus);
1116
1633
  this.writeCL();
1117
1634
  }
1635
+ // Stop traversal of this branch
1636
+ return false;
1118
1637
  }
1119
- // bitmarkAst -> bits -> bitsValue -> * -> example
1120
- leaf_example(node, route) {
1121
- var _a, _b;
1122
- const value = node.value;
1123
- const parent = this.getParentNode(route);
1124
- const isExample = (_a = parent === null || parent === void 0 ? void 0 : parent.value.isExample) !== null && _a !== void 0 ? _a : false;
1125
- const isDefaultExample = (_b = parent === null || parent === void 0 ? void 0 : parent.value.isDefaultExample) !== null && _b !== void 0 ? _b : false;
1638
+ // bitmarkAst -> bits -> bitsValue -> * -> isExample / example
1639
+ leaf_isExample(node, route) {
1640
+ var _a;
1641
+ const isExample = node.value;
1126
1642
  if (!isExample)
1127
1643
  return;
1128
- if (isDefaultExample) {
1129
- this.writeOPA();
1130
- this.writeString('example');
1131
- this.writeCL();
1132
- }
1133
- else if (value != null) {
1644
+ const parent = this.getParentNode(route);
1645
+ const example = (_a = parent === null || parent === void 0 ? void 0 : parent.value.example) !== null && _a !== void 0 ? _a : null;
1646
+ // const __isDefaultExample = parent?.value.__isDefaultExample ?? false;
1647
+ if (example != null && example !== '') {
1134
1648
  this.writeOPA();
1135
1649
  this.writeString('example');
1136
1650
  this.writeColon();
1137
- if (value === true) {
1651
+ if (example === true) {
1138
1652
  this.writeString('true');
1139
1653
  }
1140
- else if (value === false) {
1654
+ else if (example === false) {
1141
1655
  this.writeString('false');
1142
1656
  }
1657
+ else if (Array.isArray(example)) {
1658
+ // TextAst
1659
+ this.textGenerator.generateSync(example, TextFormat.bitmarkMinusMinus);
1660
+ }
1143
1661
  else {
1144
1662
  // String
1145
- this.writeString(value);
1663
+ this.writeBreakscapedTagString(example);
1146
1664
  }
1147
1665
  this.writeCL();
1148
1666
  }
1149
- }
1150
- // bitmarkAst -> bits -> body -> bodyValue -> bodyText
1151
- leaf_bodyText(node, _route) {
1152
- const value = node.value;
1153
- const text = value;
1154
- if (text) {
1155
- this.writeString(text);
1156
- }
1157
- }
1158
- // bitmarkAst -> bits -> body -> bodyValue -> bodyJson
1159
- enter_bodyJson(node, _route) {
1160
- const value = node.value;
1161
- if (Array.isArray(value) || ObjectUtils.isObject(value)) {
1162
- const text = JSON.stringify(value, null, this.prettifySpace);
1163
- if (text) {
1164
- this.writeString(text);
1165
- }
1166
- }
1167
- // Stop traversal of this branch to avoid processing the bodyJson
1168
- return false;
1169
- }
1170
- // bitmarkAst -> bits -> footer
1171
- enter_footer(_node, _route) {
1172
- this.write('~~~~');
1173
- this.writeNL();
1174
- }
1175
- // bitmarkAst -> bits -> footer -> footerText
1176
- leaf_footerText(node, _route) {
1177
- const value = node.value;
1178
- const text = value;
1179
- if (text) {
1180
- this.writeString(text);
1667
+ else {
1668
+ // Don't write example if it is null.
1669
+ // this.writeOPA();
1670
+ // this.writeString('example');
1671
+ // this.writeCL();
1181
1672
  }
1182
1673
  }
1183
1674
  // bitmarkAst -> bits -> bitsValue -> elements -> elementsValue
1184
1675
  leaf_elementsValue(node, _route) {
1185
1676
  if (node.value) {
1186
- this.writeString(node.value);
1677
+ this.writeBreakscapedTagString(node.value);
1187
1678
  }
1188
1679
  }
1189
1680
  // bitmarkAst -> bits -> bitsValue -> body -> bodyValue -> gap -> solutions -> solution
1190
1681
  // ? -> solutions -> solution
1191
- leaf_solutionsValue(node, _route) {
1682
+ leaf_solutionsValue(node, route) {
1683
+ const parent = this.getParentNode(route, 2);
1684
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
1685
+ return;
1192
1686
  if (node.value != null) {
1193
1687
  this.writeOPU();
1194
- this.writeString(node.value);
1688
+ this.writeBreakscapedTagString(node.value);
1195
1689
  this.writeCL();
1196
1690
  }
1197
1691
  }
@@ -1200,7 +1694,7 @@ class BitmarkGenerator extends AstWalkerGenerator {
1200
1694
  leaf_prefix(node, _route) {
1201
1695
  if (node.value) {
1202
1696
  this.writeOPPRE();
1203
- this.writeString(node.value);
1697
+ this.writeBreakscapedTagString(node.value);
1204
1698
  this.writeCL();
1205
1699
  }
1206
1700
  }
@@ -1209,39 +1703,50 @@ class BitmarkGenerator extends AstWalkerGenerator {
1209
1703
  leaf_postfix(node, _route) {
1210
1704
  if (node.value) {
1211
1705
  this.writeOPPOST();
1212
- this.writeString(node.value);
1706
+ this.writeBreakscapedTagString(node.value);
1213
1707
  this.writeCL();
1214
1708
  }
1215
1709
  }
1216
1710
  // bitmarkAst -> bits -> bitsValue -> * -> isCaseSensitive
1217
1711
  leaf_isCaseSensitive(node, _route) {
1218
- this.writeProperty('isCaseSensitive', node.value, true, false, true);
1712
+ this.writeProperty('isCaseSensitive', node.value, {
1713
+ format: PropertyFormat.boolean,
1714
+ single: true,
1715
+ ignoreFalse: false,
1716
+ ignoreTrue: true,
1717
+ });
1219
1718
  }
1220
1719
  // bitmarkAst -> bits -> bitsValue -> * -> isCorrect
1221
1720
  // bitmarkAst -> bits -> bitsValue -> heading -> forKeys
1222
1721
  leaf_forKeys(node, _route) {
1223
1722
  this.writeOPHASH();
1224
- this.writeString(node.value);
1723
+ this.writeBreakscapedTagString(node.value);
1724
+ this.writeCL();
1725
+ }
1726
+ // bitmarkAst -> bits -> bitsValue -> heading -> forValues
1727
+ leaf_forValues(node, _route) {
1728
+ this.writeOPHASH();
1729
+ this.writeBreakscapedTagString(node.value);
1225
1730
  this.writeCL();
1226
1731
  }
1227
1732
  // bitmarkAst -> bits -> bitsValue -> heading -> forValuesValue
1228
1733
  leaf_forValuesValue(node, _route) {
1229
1734
  this.writeOPHASH();
1230
- this.writeString(node.value);
1735
+ this.writeBreakscapedTagString(node.value);
1231
1736
  this.writeCL();
1232
1737
  }
1233
1738
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> key
1234
1739
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> key
1235
1740
  leaf_key(node, _route) {
1236
1741
  if (node.value) {
1237
- this.writeString(node.value);
1742
+ this.writeBreakscapedTagString(node.value);
1238
1743
  }
1239
1744
  }
1240
1745
  // bitmarkAst -> bits -> bitsValue -> pairs -> pairsValue -> values -> valuesValue
1241
1746
  // bitmarkAst -> bits -> bitsValue -> matrix -> matrixValue -> cells -> cellsValue -> values -> valuesValue
1242
1747
  leaf_valuesValue(node, _route) {
1243
1748
  if (node.value) {
1244
- this.writeString(node.value);
1749
+ this.writeBreakscapedTagString(node.value);
1245
1750
  }
1246
1751
  }
1247
1752
  // bitmarkAst -> bits -> bitsValue -> questions -> questionsValue -> question
@@ -1252,35 +1757,76 @@ class BitmarkGenerator extends AstWalkerGenerator {
1252
1757
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
1253
1758
  return;
1254
1759
  if (node.value) {
1255
- this.writeString(node.value);
1760
+ this.writeBreakscapedTagString(node.value);
1256
1761
  // this.writeNL();
1257
1762
  }
1258
1763
  }
1764
+ enter_question(node, route) {
1765
+ // Ignore responses that are not at the questionsValue level as they are handled elsewhere
1766
+ const parent = this.getParentNode(route);
1767
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.questionsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.flashcardsValue)
1768
+ return true;
1769
+ if (node.value) {
1770
+ this.textGenerator.generateSync(node.value, TextFormat.bitmarkMinusMinus);
1771
+ // this.writeString(node.value);
1772
+ // this.writeNL();
1773
+ }
1774
+ // Stop traversal of this branch
1775
+ return false;
1776
+ }
1259
1777
  // bitmarkAst -> bits -> bitsValue -> statements -> text
1260
1778
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
1261
1779
  // bitmarkAst -> bits -> bitsValue -> resource -> posterImage -> ...
1262
1780
  // bitmarkAst -> bits -> bitsValue -> resource -> thumbnails -> thumbnailsValue -> ...
1263
1781
  // [src1x,src2x,src3x,src4x,width,height,alt,zoomDisabled,caption]
1264
1782
  leaf_src1x(node, _route) {
1265
- this.writeProperty('src1x', node.value);
1783
+ this.writeProperty('src1x', node.value, {
1784
+ format: PropertyFormat.trimmedString,
1785
+ single: true,
1786
+ ignoreEmpty: true,
1787
+ });
1266
1788
  }
1267
1789
  leaf_src2x(node, _route) {
1268
- this.writeProperty('src2x', node.value);
1790
+ this.writeProperty('src2x', node.value, {
1791
+ format: PropertyFormat.trimmedString,
1792
+ single: true,
1793
+ ignoreEmpty: true,
1794
+ });
1269
1795
  }
1270
1796
  leaf_src3x(node, _route) {
1271
- this.writeProperty('src3x', node.value);
1797
+ this.writeProperty('src3x', node.value, {
1798
+ format: PropertyFormat.trimmedString,
1799
+ single: true,
1800
+ ignoreEmpty: true,
1801
+ });
1272
1802
  }
1273
1803
  leaf_src4x(node, _route) {
1274
- this.writeProperty('src4x', node.value);
1804
+ this.writeProperty('src4x', node.value, {
1805
+ format: PropertyFormat.trimmedString,
1806
+ single: true,
1807
+ ignoreEmpty: true,
1808
+ });
1275
1809
  }
1276
1810
  leaf_width(node, _route) {
1277
- this.writeProperty('width', node.value);
1811
+ this.writeProperty('width', node.value, {
1812
+ format: PropertyFormat.trimmedString,
1813
+ single: true,
1814
+ ignoreEmpty: true,
1815
+ });
1278
1816
  }
1279
1817
  leaf_height(node, _route) {
1280
- this.writeProperty('height', node.value);
1818
+ this.writeProperty('height', node.value, {
1819
+ format: PropertyFormat.trimmedString,
1820
+ single: true,
1821
+ ignoreEmpty: true,
1822
+ });
1281
1823
  }
1282
1824
  leaf_alt(node, _route) {
1283
- this.writeProperty('alt', node.value);
1825
+ this.writeProperty('alt', node.value, {
1826
+ format: PropertyFormat.trimmedString,
1827
+ single: true,
1828
+ ignoreEmpty: true,
1829
+ });
1284
1830
  }
1285
1831
  leaf_zoomDisabled(node, route) {
1286
1832
  const bitType = this.getBitType(route);
@@ -1290,32 +1836,65 @@ class BitmarkGenerator extends AstWalkerGenerator {
1290
1836
  BitType.imagesLogoGrave,
1291
1837
  BitType.prototypeImages,
1292
1838
  ])) {
1293
- this.writeProperty('zoomDisabled', node.value, undefined, false, true);
1839
+ this.writeProperty('zoomDisabled', node.value, {
1840
+ format: PropertyFormat.boolean,
1841
+ single: true,
1842
+ ignoreFalse: false,
1843
+ ignoreTrue: true,
1844
+ });
1294
1845
  }
1295
1846
  else {
1296
- this.writeProperty('zoomDisabled', node.value, undefined, true, false);
1847
+ this.writeProperty('zoomDisabled', node.value, {
1848
+ format: PropertyFormat.boolean,
1849
+ single: true,
1850
+ ignoreFalse: true,
1851
+ ignoreTrue: false,
1852
+ });
1297
1853
  }
1298
1854
  }
1299
1855
  leaf_license(node, _route) {
1300
- this.writeProperty('license', node.value);
1856
+ this.writeProperty('license', node.value, {
1857
+ format: PropertyFormat.trimmedString,
1858
+ single: true,
1859
+ ignoreEmpty: true,
1860
+ });
1301
1861
  }
1302
1862
  leaf_copyright(node, _route) {
1303
- this.writeProperty('copyright', node.value);
1863
+ this.writeProperty('copyright', node.value, {
1864
+ format: PropertyFormat.trimmedString,
1865
+ single: true,
1866
+ ignoreEmpty: true,
1867
+ });
1304
1868
  }
1305
1869
  leaf_provider(_node, _route) {
1306
1870
  // provider is included in the url (it is the domain) and should not be written as a property
1307
1871
  // this.writeProperty('provider', node.value);
1308
1872
  }
1309
1873
  leaf_showInIndex(node, _route) {
1310
- this.writeProperty('showInIndex', node.value);
1874
+ this.writeProperty('showInIndex', node.value, {
1875
+ format: PropertyFormat.boolean,
1876
+ single: true,
1877
+ ignoreEmpty: true,
1878
+ ignoreFalse: true,
1879
+ });
1311
1880
  }
1312
- leaf_caption(node, _route) {
1881
+ enter_caption(node, _route) {
1313
1882
  const value = node.value;
1314
- this.writeProperty('caption', value);
1883
+ this.writeProperty('caption', value, {
1884
+ format: PropertyFormat.bitmarkMinusMinus,
1885
+ single: true, // ??
1886
+ ignoreEmpty: true,
1887
+ });
1888
+ // Stop traversal of this branch
1889
+ return false;
1315
1890
  }
1316
1891
  leaf_search(node, _route) {
1317
1892
  const value = node.value;
1318
- this.writeProperty('search', value);
1893
+ this.writeProperty('search', value, {
1894
+ format: PropertyFormat.trimmedString,
1895
+ single: true,
1896
+ ignoreEmpty: true,
1897
+ });
1319
1898
  }
1320
1899
  // bitmarkAst -> bits -> bitsValue -> resource -> ...
1321
1900
  // bitmarkAst -> bits -> bitsValue -> resource -> posterImage -> ...
@@ -1326,23 +1905,97 @@ class BitmarkGenerator extends AstWalkerGenerator {
1326
1905
  const parent = this.getParentNode(route);
1327
1906
  if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType.bitsValue)
1328
1907
  return;
1329
- this.writeProperty('duration', node.value);
1908
+ this.writeProperty('duration', node.value, {
1909
+ format: PropertyFormat.trimmedString,
1910
+ single: true,
1911
+ ignoreEmpty: true,
1912
+ });
1330
1913
  }
1331
1914
  leaf_mute(node, _route) {
1332
- this.writeProperty('mute', node.value);
1915
+ this.writeProperty('mute', node.value, {
1916
+ format: PropertyFormat.boolean,
1917
+ single: true,
1918
+ ignoreEmpty: true,
1919
+ });
1333
1920
  }
1334
1921
  leaf_autoplay(node, _route) {
1335
- this.writeProperty('autoplay', node.value);
1922
+ this.writeProperty('autoplay', node.value, {
1923
+ format: PropertyFormat.boolean,
1924
+ single: true,
1925
+ ignoreEmpty: true,
1926
+ });
1336
1927
  }
1337
1928
  leaf_allowSubtitles(node, _route) {
1338
- this.writeProperty('allowSubtitles', node.value);
1929
+ this.writeProperty('allowSubtitles', node.value, {
1930
+ format: PropertyFormat.boolean,
1931
+ single: true,
1932
+ ignoreEmpty: true,
1933
+ });
1339
1934
  }
1340
1935
  leaf_showSubtitles(node, _route) {
1341
- this.writeProperty('showSubtitles', node.value);
1936
+ this.writeProperty('showSubtitles', node.value, {
1937
+ format: PropertyFormat.boolean,
1938
+ single: true,
1939
+ ignoreEmpty: true,
1940
+ });
1941
+ }
1942
+ //
1943
+ // Resources
1944
+ //
1945
+ // bitmarkAst -> bits -> bitsValue -> resources
1946
+ between_resources(_node, _left, _right, _route) {
1947
+ this.writeNL();
1948
+ }
1949
+ exit_resources(_node, _left, _right, _route) {
1950
+ this.writeNL();
1951
+ }
1952
+ // bitmarkAst -> bits -> bitsValue -> resourcesValue
1953
+ between_resourcesValue(_node, _left, _right, _route) {
1954
+ this.writeNL();
1342
1955
  }
1343
1956
  //
1344
1957
  // Generated Node Handlers
1345
1958
  //
1959
+ /**
1960
+ * Generate the handlers for resources, as they are mostly the same, but not quite
1961
+ */
1962
+ generateResourceHandlers() {
1963
+ for (const tag of ResourceTag.keys()) {
1964
+ // skip unknown
1965
+ if (tag === ResourceTag.keyFromValue(ResourceTag.unknown))
1966
+ continue;
1967
+ const enterFuncName = `enter_${tag}`;
1968
+ // Skip if the function already exists, allows for custom handlers
1969
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1970
+ if (typeof this[enterFuncName] === 'function') {
1971
+ continue;
1972
+ }
1973
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1974
+ this[enterFuncName] = (node, route) => {
1975
+ const resource = node.value;
1976
+ if (resource == null)
1977
+ return false;
1978
+ // Ignore any property that is not at the bit level as that will be handled by a different handler
1979
+ const parent = this.getParentNode(route);
1980
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.resourcesValue)
1981
+ return true;
1982
+ // Get the resource alias
1983
+ const alias = ResourceTag.fromValue(parent.value.__typeAlias);
1984
+ const type = alias !== null && alias !== void 0 ? alias : ResourceTag.fromValue(parent.value.type);
1985
+ if (!type)
1986
+ return false;
1987
+ // url / src / href / app
1988
+ const url = resource.url || resource.src || resource.body || '';
1989
+ // Write the resource
1990
+ this.writeResource(type, url);
1991
+ // Continue traversal
1992
+ return true;
1993
+ };
1994
+ // Bind this
1995
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1996
+ this[enterFuncName] = this[enterFuncName].bind(this);
1997
+ }
1998
+ }
1346
1999
  /**
1347
2000
  * Generate the handlers for properties, as they are mostly the same, but not quite
1348
2001
  */
@@ -1359,36 +2012,15 @@ class BitmarkGenerator extends AstWalkerGenerator {
1359
2012
  const propertiesConfig = Config.getRawPropertiesConfig();
1360
2013
  for (const propertyConfig of Object.values(propertiesConfig)) {
1361
2014
  const astKey = (_a = propertyConfig.astKey) !== null && _a !== void 0 ? _a : propertyConfig.tag;
1362
- // Special cases (handled outside of the automatically generated handlers)
1363
- if (astKey === PropertyTag.internalComment)
1364
- continue;
1365
- if (astKey === PropertyTag.example)
1366
- continue;
1367
- if (astKey === PropertyTag.labelTrue)
1368
- continue;
1369
- if (astKey === PropertyTag.labelFalse)
1370
- continue;
1371
- if (astKey === PropertyTag.posterImage)
1372
- continue;
1373
- if (astKey === PropertyTag.imageSource)
1374
- continue;
1375
- if (astKey === PropertyTag.imagePlaceholder)
1376
- continue;
1377
- if (astKey === PropertyTag.technicalTerm)
1378
- continue;
1379
- if (astKey === PropertyTag.servings)
1380
- continue;
1381
- if (astKey === PropertyTag.person)
1382
- continue;
1383
- if (astKey === PropertyAstKey.ast_markConfig)
1384
- continue;
1385
- if (astKey === PropertyTag.ratingLevelStart)
1386
- continue;
1387
- if (astKey === PropertyTag.ratingLevelEnd)
1388
- continue;
1389
2015
  const enterFuncName = `enter_${astKey}`;
2016
+ // Skip if the function already exists, allows for custom handlers
2017
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2018
+ if (typeof this[enterFuncName] === 'function') {
2019
+ continue;
2020
+ }
1390
2021
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1391
2022
  this[enterFuncName] = (node, route) => {
2023
+ var _a, _b;
1392
2024
  const value = node.value;
1393
2025
  if (value == null)
1394
2026
  return;
@@ -1398,7 +2030,12 @@ class BitmarkGenerator extends AstWalkerGenerator {
1398
2030
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
1399
2031
  return;
1400
2032
  // Write the property
1401
- this.writeProperty(propertyConfig.tag, node.value, propertyConfig.single, propertyConfig.defaultValue === 'false', propertyConfig.defaultValue === 'true');
2033
+ this.writeProperty(propertyConfig.tag, node.value, {
2034
+ format: (_a = propertyConfig.format) !== null && _a !== void 0 ? _a : PropertyFormat.trimmedString,
2035
+ single: (_b = propertyConfig.single) !== null && _b !== void 0 ? _b : false,
2036
+ ignoreFalse: propertyConfig.defaultValue === 'false',
2037
+ ignoreTrue: propertyConfig.defaultValue === 'true',
2038
+ });
1402
2039
  };
1403
2040
  // Bind this
1404
2041
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1434,6 +2071,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
1434
2071
  //
1435
2072
  // WRITE FUNCTIONS
1436
2073
  //
2074
+ writeBreakscapedTagString(s) {
2075
+ if (s != null) {
2076
+ this.write(Breakscape.breakscape(`${s}`, {
2077
+ textFormat: TextFormat.bitmarkMinusMinus,
2078
+ }));
2079
+ }
2080
+ }
1437
2081
  writeString(s) {
1438
2082
  if (s != null)
1439
2083
  this.write(`${s}`);
@@ -1568,84 +2212,86 @@ class BitmarkGenerator extends AstWalkerGenerator {
1568
2212
  this.write('\n');
1569
2213
  }
1570
2214
  writePropertyStyleResource(key, resource) {
1571
- const resourceAsArticle = resource;
2215
+ var _a;
1572
2216
  if (key && resource) {
2217
+ const resourceTag = (_a = ResourceTag.keyFromValue(resource.type)) !== null && _a !== void 0 ? _a : '';
2218
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2219
+ const resourceData = resource[resourceTag];
2220
+ const src = resourceData ? resourceData.src || resourceData.url || resourceData.body || '' : '';
1573
2221
  this.writeOPA();
1574
- this.writeString(key);
1575
- if (resource.type === ResourceTag.article && resourceAsArticle.value) {
1576
- this.writeColon();
1577
- // this.writeNL();
1578
- this.writeString(resourceAsArticle.value);
2222
+ this.writeBreakscapedTagString(key);
2223
+ this.writeColon();
2224
+ this.writeBreakscapedTagString(src);
2225
+ if (resource.type === ResourceTag.article) {
1579
2226
  this.writeNL();
1580
2227
  }
1581
- else if (resource.value) {
1582
- this.writeColon();
1583
- this.writeString(resource.value);
1584
- }
1585
2228
  this.writeCL();
1586
2229
  }
1587
2230
  }
1588
- writeResource(resource) {
1589
- var _a;
1590
- const resourceAsArticle = resource;
1591
- if (resource) {
1592
- // All resources should now be valid as they are validated in the AST
1593
- // TODO: remove code below
1594
- // // Check if a resource has a value, if not, we should not write it (or any of its chained properties)
1595
- // let valid = false;
1596
- // if (resource.value) {
1597
- // valid = true;
1598
- // }
1599
- // // Resource is not valid, cancel walking it's tree.
1600
- // if (!valid) return false;
2231
+ writeResource(type, value) {
2232
+ // const resourceAsArticle = resource as ArticleResource;
2233
+ if (type) {
1601
2234
  // Standard case
1602
2235
  this.writeOPAMP();
1603
- this.writeString((_a = resource.typeAlias) !== null && _a !== void 0 ? _a : resource.type);
1604
- if (resource.type === ResourceTag.article && resourceAsArticle.value) {
1605
- this.writeColon();
1606
- // this.writeNL();
1607
- this.writeString(resourceAsArticle.value);
2236
+ this.writeBreakscapedTagString(type);
2237
+ this.writeColon();
2238
+ this.writeBreakscapedTagString(value);
2239
+ if (type === ResourceTag.article) {
1608
2240
  this.writeNL();
1609
2241
  }
1610
- else if (resource.value) {
1611
- this.writeColon();
1612
- this.writeString(resource.value);
1613
- }
1614
2242
  this.writeCL();
1615
2243
  }
1616
2244
  }
1617
- writeProperty(name, values, singleOnly, ignoreFalse, ignoreTrue) {
2245
+ writeProperty(name, values, options) {
2246
+ var _a;
1618
2247
  let valuesArray;
1619
2248
  let wroteSomething = false;
1620
2249
  if (values !== undefined) {
1621
- if (!Array.isArray(values)) {
1622
- valuesArray = [values];
2250
+ const isBitmarkText = options.format === PropertyFormat.bitmarkMinusMinus || options.format === PropertyFormat.bitmarkPlusPlus;
2251
+ if (isBitmarkText) {
2252
+ // Write bitmark text
2253
+ if (options.ignoreEmpty && isBitmarkText && this.isEmptyText(values))
2254
+ return;
2255
+ this.writeOPA();
2256
+ this.writeBreakscapedTagString(name);
2257
+ this.writeColon();
2258
+ this.textGenerator.generateSync(values, (_a = TextFormat.fromValue(options.format)) !== null && _a !== void 0 ? _a : TextFormat.bitmarkMinusMinus);
2259
+ this.writeCL();
2260
+ wroteSomething = true;
1623
2261
  }
1624
2262
  else {
1625
- valuesArray = values;
1626
- }
1627
- if (valuesArray.length > 0) {
1628
- if (singleOnly)
1629
- valuesArray = valuesArray.slice(valuesArray.length - 1);
1630
- let propertyIndex = 0;
1631
- for (const val of valuesArray) {
1632
- if (val !== undefined) {
1633
- if (ignoreFalse && val === false)
1634
- continue;
1635
- if (ignoreTrue && val === true)
1636
- continue;
1637
- if (propertyIndex > 0)
1638
- this.writeNL();
1639
- this.writeOPA();
1640
- this.writeString(name);
1641
- this.writeColon();
1642
- this.writeString(`${val}`);
1643
- this.writeCL();
1644
- wroteSomething = true;
1645
- propertyIndex++;
2263
+ // Write any other property type
2264
+ if (!Array.isArray(values)) {
2265
+ valuesArray = [values];
2266
+ }
2267
+ else {
2268
+ valuesArray = values;
2269
+ }
2270
+ if (valuesArray.length > 0) {
2271
+ if (options.single)
2272
+ valuesArray = valuesArray.slice(valuesArray.length - 1);
2273
+ let propertyIndex = 0;
2274
+ for (const val of valuesArray) {
2275
+ if (val !== undefined) {
2276
+ if (options.ignoreFalse && val === false)
2277
+ continue;
2278
+ if (options.ignoreTrue && val === true)
2279
+ continue;
2280
+ if (options.ignoreEmpty && val === '')
2281
+ continue;
2282
+ if (propertyIndex > 0)
2283
+ this.writeNL();
2284
+ this.writeOPA();
2285
+ this.writeBreakscapedTagString(name);
2286
+ this.writeColon();
2287
+ this.writeBreakscapedTagString(`${val}`);
2288
+ this.writeCL();
2289
+ wroteSomething = true;
2290
+ propertyIndex++;
2291
+ }
1646
2292
  }
1647
2293
  }
1648
- }
2294
+ } // isBitmarkText
1649
2295
  }
1650
2296
  if (!wroteSomething) {
1651
2297
  this.skipNLBetweenBitsValue = true;
@@ -1667,6 +2313,13 @@ class BitmarkGenerator extends AstWalkerGenerator {
1667
2313
  //
1668
2314
  // Helper functions
1669
2315
  //
2316
+ isEmptyText(text) {
2317
+ if (!text)
2318
+ return true;
2319
+ if (Array.isArray(text))
2320
+ return text.length === 0;
2321
+ return true; // true as not valid TextAst?
2322
+ }
1670
2323
  isWriteTextFormat(bitsValue, textFormatDefault) {
1671
2324
  const isDefault = TextFormat.fromValue(bitsValue) === textFormatDefault;
1672
2325
  const writeFormat = !isDefault || this.options.explicitTextFormat;