@gmb/bitmark-parser-generator 1.35.0 → 2.0.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 (290) 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 +776 -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 +14 -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 +959 -338
  28. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  29. package/dist/cjs/generator/json/JsonGenerator.js +308 -1982
  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 +27 -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 +1 -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 +2 -1
  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 +776 -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 +14 -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 +959 -338
  127. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  128. package/dist/esm/generator/json/JsonGenerator.js +308 -1982
  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 +27 -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 +1 -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 +2 -1
  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 +279 -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 +89 -55
  219. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  220. package/dist/types/generator/json/JsonGenerator.d.ts +88 -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 +48 -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 +2 -4
  235. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  236. package/dist/types/model/enum/PropertyFormat.d.ts +4 -2
  237. package/dist/types/model/enum/PropertyFormat.d.ts.map +1 -1
  238. package/dist/types/model/enum/PropertyTag.d.ts +2 -0
  239. package/dist/types/model/enum/PropertyTag.d.ts.map +1 -1
  240. package/dist/types/model/json/BitJson.d.ts +32 -20
  241. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  242. package/dist/types/model/json/BodyBitJson.d.ts +16 -12
  243. package/dist/types/model/json/BodyBitJson.d.ts.map +1 -1
  244. package/dist/types/model/json/ResourceJson.d.ts +2 -22
  245. package/dist/types/model/json/ResourceJson.d.ts.map +1 -1
  246. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts +3 -2
  247. package/dist/types/parser/bitmark/peg/BitmarkPegParserHelper.d.ts.map +1 -1
  248. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts +2 -15
  249. package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
  250. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +83 -71
  251. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  252. package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts +2 -2
  253. package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts.map +1 -1
  254. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts +37 -0
  255. package/dist/types/parser/bitmark/peg/contentProcessors/BodyContentProcessor.d.ts.map +1 -0
  256. package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
  257. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts +2 -2
  258. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  259. package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.d.ts.map +1 -1
  260. package/dist/types/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.d.ts +15 -0
  261. package/dist/types/parser/bitmark/peg/contentProcessors/ContentProcessorUtils.d.ts.map +1 -0
  262. package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
  263. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
  264. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts +16 -0
  265. package/dist/types/parser/bitmark/peg/contentProcessors/FooterContentProcessor.d.ts.map +1 -0
  266. package/dist/types/parser/bitmark/peg/contentProcessors/GapChainContentProcessor.d.ts.map +1 -1
  267. package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
  268. package/dist/types/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.d.ts.map +1 -1
  269. package/dist/types/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.d.ts.map +1 -1
  270. package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
  271. package/dist/types/parser/bitmark/peg/contentProcessors/PersonChainContentProcessor.d.ts.map +1 -1
  272. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  273. package/dist/types/parser/bitmark/peg/contentProcessors/RatingLevelChainContentProcessor.d.ts.map +1 -1
  274. package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
  275. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts +2 -2
  276. package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
  277. package/dist/types/parser/bitmark/peg/contentProcessors/ServingsChainContentProcessor.d.ts.map +1 -1
  278. package/dist/types/parser/bitmark/peg/contentProcessors/TechnicalTermChainContentProcessor.d.ts.map +1 -1
  279. package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts +5 -2
  280. package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts.map +1 -1
  281. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.d.ts +1 -1
  282. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseChainContentProcessor.d.ts.map +1 -1
  283. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
  284. package/dist/types/parser/json/JsonParser.d.ts +9 -72
  285. package/dist/types/parser/json/JsonParser.d.ts.map +1 -1
  286. package/dist/types/parser/text/TextParser.d.ts +16 -1
  287. package/dist/types/parser/text/TextParser.d.ts.map +1 -1
  288. package/dist/types/utils/BitUtils.d.ts +8 -8
  289. package/dist/types/utils/BitUtils.d.ts.map +1 -1
  290. package/package.json +1 -1
@@ -27,10 +27,7 @@ const Config_1 = require("../../config/Config");
27
27
  const NodeType_1 = require("../../model/ast/NodeType");
28
28
  const BitType_1 = require("../../model/enum/BitType");
29
29
  const BitmarkVersion_1 = require("../../model/enum/BitmarkVersion");
30
- const BodyBitType_1 = require("../../model/enum/BodyBitType");
31
30
  const ExampleType_1 = require("../../model/enum/ExampleType");
32
- const PropertyAstKey_1 = require("../../model/enum/PropertyAstKey");
33
- const PropertyTag_1 = require("../../model/enum/PropertyTag");
34
31
  const ResourceTag_1 = require("../../model/enum/ResourceTag");
35
32
  const TextFormat_1 = require("../../model/enum/TextFormat");
36
33
  const TextNodeType_1 = require("../../model/enum/TextNodeType");
@@ -38,9 +35,8 @@ const TextParser_1 = require("../../parser/text/TextParser");
38
35
  const ArrayUtils_1 = require("../../utils/ArrayUtils");
39
36
  const BooleanUtils_1 = require("../../utils/BooleanUtils");
40
37
  const NumberUtils_1 = require("../../utils/NumberUtils");
41
- const StringUtils_1 = require("../../utils/StringUtils");
42
- const UrlUtils_1 = require("../../utils/UrlUtils");
43
38
  const AstWalkerGenerator_1 = require("../AstWalkerGenerator");
39
+ const TextGenerator_1 = require("../text/TextGenerator");
44
40
  const DEFAULT_OPTIONS = {
45
41
  // debugGenerationInline: true,
46
42
  };
@@ -68,7 +64,13 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
68
64
  this.textDefault = Breakscape_1.Breakscape.EMPTY_STRING;
69
65
  this.bodyDefault = Breakscape_1.Breakscape.EMPTY_STRING;
70
66
  this.bodyJson = this.bodyDefault;
71
- this.startPlaceholderIndex = 0;
67
+ this.placeholderIndex = 0;
68
+ // Bind callbacks
69
+ this.enter = this.enter.bind(this);
70
+ this.between = this.between.bind(this);
71
+ this.exit = this.exit.bind(this);
72
+ this.leaf = this.leaf.bind(this);
73
+ this.bodyBitCallback = this.bodyBitCallback.bind(this);
72
74
  this.bitmarkVersion = (_a = BitmarkVersion_1.BitmarkVersion.fromValue(options === null || options === void 0 ? void 0 : options.bitmarkVersion)) !== null && _a !== void 0 ? _a : BitmarkVersion_1.DEFAULT_BITMARK_VERSION;
73
75
  this.textParserVersion = this.textParser.version();
74
76
  this.options = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options === null || options === void 0 ? void 0 : options.jsonOptions);
@@ -85,11 +87,13 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
85
87
  this.options.textAsPlainText = false;
86
88
  }
87
89
  }
90
+ // Create the text generator for generating v2 texts
91
+ this.textGenerator = new TextGenerator_1.TextGenerator(this.bitmarkVersion, {
92
+ // writeCallback: this.write,
93
+ bodyBitCallback: this.bodyBitCallback,
94
+ debugGenerationInline: this.debugGenerationInline,
95
+ });
88
96
  this.writer = writer;
89
- this.enter = this.enter.bind(this);
90
- this.between = this.between.bind(this);
91
- this.exit = this.exit.bind(this);
92
- this.leaf = this.leaf.bind(this);
93
97
  this.generatePropertyHandlers();
94
98
  }
95
99
  /**
@@ -133,7 +137,8 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
133
137
  this.textDefault = this.options.textAsPlainText ? Breakscape_1.Breakscape.EMPTY_STRING : [];
134
138
  this.bodyDefault = this.options.textAsPlainText ? Breakscape_1.Breakscape.EMPTY_STRING : [];
135
139
  this.bodyJson = this.bodyDefault;
136
- this.startPlaceholderIndex = 0;
140
+ this.listItem = undefined;
141
+ this.placeholderIndex = 0;
137
142
  this.printed = false;
138
143
  }
139
144
  walkAndWrite(ast) {
@@ -151,6 +156,16 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
151
156
  // Reset the JSON
152
157
  this.json = [];
153
158
  }
159
+ exit_bitmarkAst(_node, _route) {
160
+ // Convert all bitmark text to plain text if required
161
+ if (this.options.textAsPlainText) {
162
+ // Convert all bitmark text to plain text
163
+ this.convertAllBitmarkTextsToStringsForPlainText(this.json);
164
+ }
165
+ // Walk the entire json object and remove all' '_xxx' properties
166
+ // (which are used to store temporary data during the generation process)
167
+ this.removeTemporaryProperties(this.json);
168
+ }
154
169
  // bitmarkAst -> bits
155
170
  // bitmarkAst -> bits -> bitsValue
156
171
  enter_bitsValue(node, _route) {
@@ -184,7 +199,7 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
184
199
  }
185
200
  else {
186
201
  // String example
187
- defaultExample = (_c = Breakscape_1.Breakscape.unbreakscape(ArrayUtils_1.ArrayUtils.asSingle(bit.sampleSolution))) !== null && _c !== void 0 ? _c : '';
202
+ defaultExample = (_c = ArrayUtils_1.ArrayUtils.asSingle(bit.sampleSolution)) !== null && _c !== void 0 ? _c : '';
188
203
  }
189
204
  const exampleRes = this.toExample(bit, {
190
205
  defaultExample,
@@ -196,87 +211,34 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
196
211
  else if (bit.isExample) {
197
212
  this.bitJson.isExample = true;
198
213
  }
214
+ // Reset the placeholder index
215
+ this.placeholderIndex = 0;
199
216
  }
200
217
  exit_bitsValue(_node, _route) {
201
218
  // Clean up the bit JSON, removing any unwanted values
202
- this.cleanAndSetDefaultsForBitJson(this.bitJson);
219
+ this.cleanBitJson(this.bitJson);
203
220
  }
204
221
  // bitmarkAst -> bits -> bitsValue -> imageSource
205
222
  enter_imageSource(node, route) {
206
- const imageSource = node.value;
207
- // Ignore values that are not at the bit level as they might be handled elsewhere
208
- const parent = this.getParentNode(route);
209
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
210
- return;
211
- const { url, mockupId, size, format, trim } = imageSource;
212
- const imageSourceJson = {};
213
- this.addProperty(imageSourceJson, 'url', url !== null && url !== void 0 ? url : '', true);
214
- this.addProperty(imageSourceJson, 'mockupId', mockupId !== null && mockupId !== void 0 ? mockupId : '', true);
215
- this.addProperty(imageSourceJson, 'size', size !== null && size !== void 0 ? size : null, true);
216
- this.addProperty(imageSourceJson, 'format', format !== null && format !== void 0 ? format : null, true);
217
- this.addProperty(imageSourceJson, 'trim', BooleanUtils_1.BooleanUtils.isBoolean(trim) ? trim : null, true);
218
- this.bitJson.imageSource = imageSourceJson;
223
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
219
224
  }
220
225
  // bitmarkAst -> bits -> bitsValue -> person
221
226
  enter_person(node, route) {
222
- const person = node.value;
223
227
  const bitType = this.getBitType(route);
224
- // Ignore values that are not at the bit level as they might be handled elsewhere
225
- const parent = this.getParentNode(route);
226
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue || !bitType)
227
- return;
228
- const { name, title, avatarImage } = person;
229
- const personJson = {};
230
- this.addProperty(personJson, 'name', name !== null && name !== void 0 ? name : '', true);
231
- if (title) {
232
- this.addProperty(personJson, 'title', title, true);
233
- }
234
- if (avatarImage) {
235
- const res = this.parseResourceToJson(bitType, avatarImage);
236
- if (res && res.type === ResourceTag_1.ResourceTag.image) {
237
- personJson.avatarImage = res.image;
238
- }
239
- }
228
+ let keyOverride = 'person';
240
229
  if (Config_1.Config.isOfBitType(bitType, BitType_1.BitType.conversationLeft1)) {
241
230
  // Use the legacy partner property in the JSON for conversation bits, so change to person is backwards compatible
242
- this.bitJson.partner = personJson;
243
- }
244
- else {
245
- this.bitJson.person = personJson;
231
+ keyOverride = 'partner';
246
232
  }
233
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false, keyOverride });
247
234
  }
248
235
  // bitmarkAst -> bits -> bitsValue -> ratingLevelStart
249
236
  enter_ratingLevelStart(node, route) {
250
- const json = this.enterRatingLevelStartEndCommon(node, route);
251
- if (json)
252
- this.bitJson.ratingLevelStart = json;
253
- // Stop traversal of this branch
254
- return false;
237
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
255
238
  }
256
239
  // bitmarkAst -> bits -> bitsValue -> ratingLevelEnd
257
240
  enter_ratingLevelEnd(node, route) {
258
- const json = this.enterRatingLevelStartEndCommon(node, route);
259
- if (json)
260
- this.bitJson.ratingLevelEnd = json;
261
- // Stop traversal of this branch
262
- return false;
263
- }
264
- // Common code for ratingLevelStart and ratingLevelEnd
265
- enterRatingLevelStartEndCommon(node, route) {
266
- const n = node.value;
267
- // Ignore statements that are not at the bit level
268
- const parent = this.getParentNode(route);
269
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
270
- return;
271
- const json = {};
272
- this.addProperty(json, 'level', n.level, true);
273
- if (n.label) {
274
- json.label = this.convertBreakscapedStringToJsonText(n.label, TextFormat_1.TextFormat.bitmarkMinusMinus);
275
- }
276
- // Delete unwanted properties
277
- if ((json === null || json === void 0 ? void 0 : json.label) == null)
278
- delete json.label;
279
- return json;
241
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
280
242
  }
281
243
  // bitmarkAst -> bits -> bitsValue -> productId
282
244
  enter_productId(node, route) {
@@ -284,53 +246,76 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
284
246
  // Ignore item that is not at the correct level
285
247
  const parent = this.getParentNode(route);
286
248
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
287
- return;
249
+ return true;
288
250
  const bitType = this.getBitType(route);
289
251
  if (bitType === BitType_1.BitType.module) {
290
- this.addProperty(this.bitJson, 'productId', productIds);
252
+ this.addProperty(this.bitJson, 'productId', productIds, { array: true });
291
253
  }
292
254
  else if (productIds.length > 0) {
293
- this.addProperty(this.bitJson, 'productId', productIds[productIds.length - 1], true);
255
+ this.addProperty(this.bitJson, 'productId', productIds[productIds.length - 1], { array: false });
294
256
  }
257
+ // Stop traversal of this branch
258
+ return false;
259
+ }
260
+ // bitmarkAst -> bits -> bitsValue -> markConfig
261
+ enter_markConfig(_node, _route) {
262
+ // Handler so markConfig is not processed by the default property handler
263
+ // Continue traversal
264
+ return true;
295
265
  }
296
266
  // bitmarkAst -> bits -> bitsValue -> markConfig -> markConfigValue
297
267
  enter_markConfigValue(node, route) {
298
- const markConfig = node.value;
268
+ const markJson = node.value;
299
269
  // Ignore item that is not at the correct level
300
270
  const parent = this.getParentNode(route);
301
271
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.markConfig)
302
- return;
303
- const { mark, color, emphasis } = markConfig;
304
- const markJson = {};
305
- this.addProperty(markJson, 'mark', mark !== null && mark !== void 0 ? mark : 'unknown', true);
306
- if (color)
307
- this.addProperty(markJson, 'color', color !== null && color !== void 0 ? color : '', true);
308
- if (emphasis)
309
- this.addProperty(markJson, 'emphasis', emphasis !== null && emphasis !== void 0 ? emphasis : '', true);
272
+ return true;
310
273
  if (!this.bitJson.marks)
311
274
  this.bitJson.marks = [];
312
275
  this.bitJson.marks.push(markJson);
276
+ // Stop traversal of this branch
277
+ return false;
313
278
  }
314
- // bitmarkAst -> bits -> bitsValue -> itemLead
315
- enter_itemLead(node, route) {
316
- const itemLead = node.value;
317
- const { item, lead, pageNumber, marginNumber } = itemLead;
318
- // Ignore item / lead that are not at the bit level as they are handled elsewhere
319
- const parent = this.getParentNode(route);
320
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
321
- return;
322
- if (item != null) {
323
- this.bitJson.item = this.convertBreakscapedStringToJsonText(item, TextFormat_1.TextFormat.bitmarkMinusMinus);
324
- }
325
- if (lead != null) {
326
- this.bitJson.lead = this.convertBreakscapedStringToJsonText(lead, TextFormat_1.TextFormat.bitmarkMinusMinus);
327
- }
328
- if (pageNumber != null) {
329
- this.bitJson.pageNumber = this.convertBreakscapedStringToJsonText(pageNumber, TextFormat_1.TextFormat.bitmarkMinusMinus);
330
- }
331
- if (marginNumber != null) {
332
- this.bitJson.marginNumber = this.convertBreakscapedStringToJsonText(marginNumber, TextFormat_1.TextFormat.bitmarkMinusMinus);
333
- }
279
+ // bitmarkAst -> bits -> bitsValue -> item
280
+ enter_item(node, route) {
281
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
282
+ }
283
+ // bitmarkAst -> bits -> bitsValue -> lead
284
+ enter_lead(node, route) {
285
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
286
+ }
287
+ // bitmarkAst -> bits -> bitsValue -> pageNumber
288
+ enter_pageNumber(node, route) {
289
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
290
+ }
291
+ // bitmarkAst -> bits -> bitsValue -> marginNumber
292
+ enter_marginNumber(node, route) {
293
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
294
+ }
295
+ // bitmarkAst -> bits -> bitsValue -> hint
296
+ enter_hint(node, route) {
297
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
298
+ }
299
+ // bitmarkAst -> bits -> bitsValue -> instruction
300
+ enter_instruction(node, route) {
301
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
302
+ }
303
+ // bitmarkAst -> bits -> bitsValue -> title
304
+ enter_title(node, route) {
305
+ // // Ignore title that are not at the bit or card node level as they are handled elsewhere
306
+ // const parent = this.getParentNode(route);
307
+ // if (parent?.key !== NodeType.bitsValue && parent?.key !== NodeType.cardNode) return;
308
+ // this.bitJson.title = node.value;
309
+ return this.standardHandler(node, route, [NodeType_1.NodeType.bitsValue, NodeType_1.NodeType.cardNode], { array: true });
310
+ }
311
+ // bitmarkAst -> bits -> bitsValue -> subtitle
312
+ enter_subtitle(node, route) {
313
+ // this.bitJson.subtitle = node.value;
314
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
315
+ }
316
+ // bitmarkAst -> bits -> bitsValue -> caption
317
+ enter_caption(node, route) {
318
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: true });
334
319
  }
335
320
  // bitmarkAst -> bits -> bitsValue -> width
336
321
  enter_width(node, route) {
@@ -342,8 +327,7 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
342
327
  value = (_a = NumberUtils_1.NumberUtils.asNumber(value, 0)) !== null && _a !== void 0 ? _a : 0;
343
328
  }
344
329
  // Add the property
345
- this.addProperty(this.bitJson, 'width', value, true);
346
- return false;
330
+ return this.standardHandler(node, route, undefined, { array: false, valueOverride: value });
347
331
  }
348
332
  // bitmarkAst -> bits -> bitsValue -> height
349
333
  enter_height(node, route) {
@@ -355,8 +339,7 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
355
339
  value = (_a = NumberUtils_1.NumberUtils.asNumber(value, 0)) !== null && _a !== void 0 ? _a : 0;
356
340
  }
357
341
  // Add the property
358
- this.addProperty(this.bitJson, 'height', value, true);
359
- return false;
342
+ return this.standardHandler(node, route, undefined, { array: false, valueOverride: value });
360
343
  }
361
344
  // bitmarkAst -> bits -> bitsValue -> extraProperties
362
345
  enter_extraProperties(node, _route) {
@@ -367,12 +350,14 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
367
350
  if (Object.prototype.hasOwnProperty.call(this.bitJson, key)) {
368
351
  k = `_${key}`;
369
352
  }
370
- this.addProperty(this.bitJson, k, values);
353
+ this.addProperty(this.bitJson, k, values, { array: true });
371
354
  }
372
355
  }
373
356
  }
374
357
  // bitmarkAst -> bits -> bitsValue -> cardNode -> cardBits -> cardBitsValue
375
358
  enter_cardBitsValue(node, route) {
359
+ var _a, _b, _c, _d;
360
+ const cardBit = node.value;
376
361
  // How cardBits are handled depends on the bit type
377
362
  const bitType = this.getBitType(route);
378
363
  if (!bitType)
@@ -390,7 +375,14 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
390
375
  listItems = this.bitJson.listItems;
391
376
  }
392
377
  // Create this list item
393
- this.listItem = Object.assign(Object.assign({}, this.toItemLeadHintInstruction(node.value)), { body: this.bodyDefault });
378
+ this.listItem = {
379
+ item: ((_a = cardBit.item) !== null && _a !== void 0 ? _a : []),
380
+ lead: ((_b = cardBit.lead) !== null && _b !== void 0 ? _b : []),
381
+ hint: ((_c = cardBit.hint) !== null && _c !== void 0 ? _c : []),
382
+ instruction: ((_d = cardBit.instruction) !== null && _d !== void 0 ? _d : []),
383
+ // ...this.toItemLeadHintInstruction(node.value),
384
+ body: this.bodyDefault,
385
+ };
394
386
  // Delete unwanted properties
395
387
  // const nv = node.value;
396
388
  // const li: Partial<ListItemJson> = this.listItem;
@@ -400,220 +392,58 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
400
392
  this.listItem = undefined;
401
393
  }
402
394
  // bitmarkAst -> bits -> bitsValue -> body
403
- enter_body(_node, _route) {
404
- // Override the bodyDefault if the textFormat is json
405
- const textFormat = this.getTextFormat(_route);
406
- if (textFormat === TextFormat_1.TextFormat.json)
407
- this.bodyDefault = null;
408
- this.bodyJson = this.bodyDefault;
409
- }
410
- exit_body(_node, route) {
395
+ enter_body(node, route) {
396
+ const value = node.value;
411
397
  const parent = this.getParentNode(route);
412
398
  if (!parent)
413
- return;
399
+ return false;
400
+ const textFormat = this.getTextFormat(route);
401
+ const isBitmarkText = textFormat === TextFormat_1.TextFormat.bitmarkMinusMinus || textFormat === TextFormat_1.TextFormat.bitmarkPlusPlus;
402
+ this.bodyJson = value.body;
403
+ // Set the correct body property
414
404
  if (parent.key === NodeType_1.NodeType.bitsValue) {
415
405
  // Body is at the bit level
416
406
  this.bitJson.body = this.bodyJson;
407
+ // Convert the body to plain text if required
408
+ if (this.options.textAsPlainText && isBitmarkText && this.isBitmarkText(this.bodyJson)) {
409
+ const textBody = this.textGenerator.generateSync(this.bodyJson, textFormat);
410
+ this.bitJson.body = (Breakscape_1.Breakscape.unbreakscape(textBody, {
411
+ textFormat: TextFormat_1.TextFormat.bitmarkMinusMinus,
412
+ }) || '').trim();
413
+ }
417
414
  }
418
415
  else if (parent.key === NodeType_1.NodeType.cardBitsValue) {
419
416
  // Body is at the list item (card bit) level
420
417
  if (this.listItem)
421
418
  this.listItem.body = this.bodyJson;
422
419
  }
423
- }
424
- // bitmarkAst -> bits -> bitsValue -> * -> bodyParts (body, cardBody (e.g. cloze-list, page-footer))
425
- enter_bodyParts(node, route) {
426
- const bodyParts = node.value;
427
- const plainText = this.options.textAsPlainText;
428
- const textFormat = this.getTextFormat(route);
429
- let fullBodyTextStr = '';
430
- let plainBodyTextStr = '';
431
- let placeholderIndex = this.startPlaceholderIndex;
432
- // Function for creating the placeholder keys
433
- const createPlaceholderKeys = (i) => {
434
- return {
435
- // Old placeholder style (for backwards compatibility) = {0}
436
- legacyPlaceholderKey: `{${i}}`,
437
- // New placeholder style (cannot clash as bitmark parser would have removed it) = [!0]
438
- placeholderKey: `[!${i}]`,
439
- };
440
- };
441
- // Loop the text bodyParts creating full body text with the correct placeholders
442
- //
443
- // For text output 'fullBodyTextStr:
444
- // - is created and written to the JSON
445
- // - has placeholders inserted into 'fullBodyTextStr' in the format {0}
446
- //
447
- // For JSON output 'fullBodyTextStr:
448
- // - is created and passed into the text parser to create the body text AST
449
- // - has placeholders inserted into 'fullBodyTextStr' in the format [!0] to allow the text parser to identify
450
- // where the body bits should be inserted
451
- //
452
- for (let i = 0; i < bodyParts.length; i++) {
453
- const bodyPart = bodyParts[i];
454
- const isText = bodyPart.type === BodyBitType_1.BodyBitType.text;
455
- if (isText) {
456
- const asText = bodyPart;
457
- const bodyTextPart = asText.data.bodyText;
458
- // Append the text part to the full text body
459
- if (asText.data.isPlain) {
460
- plainBodyTextStr = Breakscape_1.Breakscape.concatenate(plainBodyTextStr, bodyTextPart);
461
- }
462
- else {
463
- fullBodyTextStr = Breakscape_1.Breakscape.concatenate(fullBodyTextStr, bodyTextPart);
464
- }
465
- }
466
- else {
467
- const { legacyPlaceholderKey, placeholderKey } = createPlaceholderKeys(placeholderIndex);
468
- // Append the placeholder to the full text body
469
- fullBodyTextStr = Breakscape_1.Breakscape.concatenate(fullBodyTextStr, plainText ? legacyPlaceholderKey : placeholderKey);
470
- placeholderIndex++;
471
- }
472
- }
473
- // Add string or AST to the body
474
- const bodyJson = this.convertBreakscapedStringToJsonText(fullBodyTextStr, textFormat);
475
- const plainTextBodyJson = this.convertBreakscapedStringToJsonText(plainBodyTextStr, TextFormat_1.TextFormat.text);
476
- const bodyAst = bodyJson;
477
- // Newlines will have been lost from the end of fullBodyTextStr, and start of plainBodyTextStr
478
- // Count then and add them back when merging
479
- const newlines = StringUtils_1.StringUtils.countOccurrencesAtEnd(fullBodyTextStr, '\n') +
480
- StringUtils_1.StringUtils.countOccurrencesAtStart(plainBodyTextStr, '\n');
481
- this.bodyJson = this.concatenatePlainTextWithJsonTexts(bodyJson, newlines, plainTextBodyJson);
482
- // Loop the body parts again to create the body bits:
483
- // - For text output the body bits are inserted into the 'placeholders' object
484
- // - For JSON output the body bits are inserted into body AST, replacing the placeholders created by the text parser
485
- placeholderIndex = this.startPlaceholderIndex;
486
- for (let i = 0; i < bodyParts.length; i++) {
487
- const bodyPart = bodyParts[i];
488
- // Skip text body parts as they are handled above
489
- const isText = bodyPart.type === BodyBitType_1.BodyBitType.text;
490
- if (isText)
491
- continue;
492
- const bodyBit = bodyPart;
493
- let bodyBitJson;
494
- const { legacyPlaceholderKey } = createPlaceholderKeys(placeholderIndex);
495
- switch (bodyPart.type) {
496
- case BodyBitType_1.BodyBitType.gap: {
497
- const gap = bodyBit;
498
- bodyBitJson = this.createGapJson(gap);
499
- break;
500
- }
501
- case BodyBitType_1.BodyBitType.mark: {
502
- const mark = bodyBit;
503
- bodyBitJson = this.createMarkJson(mark);
504
- break;
505
- }
506
- case BodyBitType_1.BodyBitType.select: {
507
- const select = bodyBit;
508
- bodyBitJson = this.createSelectJson(select);
509
- break;
510
- }
511
- case BodyBitType_1.BodyBitType.highlight: {
512
- const highlight = bodyBit;
513
- bodyBitJson = this.createHighlightJson(highlight);
514
- break;
515
- }
516
- }
517
- // Add the gap to the placeholders
518
- if (bodyBitJson) {
519
- if (plainText) {
520
- // Ensure placeholders exists
521
- if (!this.bitJson.placeholders)
522
- this.bitJson.placeholders = {};
523
- // Add the body bit to the placeholders
524
- this.bitJson.placeholders[legacyPlaceholderKey] = bodyBitJson;
525
- }
526
- else {
527
- // Insert the body bit into the body AST
528
- this.replacePlaceholderWithBodyBit(bodyAst, bodyBitJson, placeholderIndex);
529
- }
530
- }
531
- placeholderIndex++;
532
- }
533
- // Save the current placeholder index for the next body (body, card bodies)
534
- this.startPlaceholderIndex = placeholderIndex;
535
- // Stop traversal of this branch for efficiency
420
+ // Stop traversal of this branch
536
421
  return false;
537
422
  }
538
- // bitmarkAst -> bits -> bitsValue -> * -> bodyJson (body when textFormat === TextFormat.json)
539
- enter_bodyJson(node, _route) {
540
- const bodyJson = node.value;
541
- // NOTE: type is not really JsonText, but unknown, but it is better for type checking to use JsonText for
542
- // the bodyJson property in the BitJson interface
543
- this.bodyJson = bodyJson;
544
- // Stop traversal of this branch to avoid processing the bodyJson
545
- return false;
423
+ bodyBitCallback(bodyBit, _index, _route) {
424
+ // console.log('bodyBitCallback', bodyBit, index, route);
425
+ var _a;
426
+ const placeholder = `{${this.placeholderIndex}}`;
427
+ this.placeholderIndex++;
428
+ this.bitJson.placeholders = (_a = this.bitJson.placeholders) !== null && _a !== void 0 ? _a : {};
429
+ this.bitJson.placeholders[placeholder] = bodyBit;
430
+ return placeholder;
431
+ }
432
+ // bitmarkAst -> bits -> bitsValue -> footer
433
+ enter_footer(node, route) {
434
+ return this.standardHandler(node, route, undefined, { array: true, valueOverride: node.value.footer });
546
435
  }
547
436
  // bitmarkAst -> bits -> bitsValue -> cardNode -> elements
548
- enter_elements(node, _route) {
549
- const elements = node.value;
550
- // Ignore elements that are not at the bit level as they are handled elsewhere as quizzes
551
- // if (parent?.key !== NodeType.bitsValue) return;
552
- if (elements && elements.length > 0) {
553
- this.bitJson.elements = Breakscape_1.Breakscape.unbreakscape(elements);
554
- }
437
+ enter_elements(node, route) {
438
+ return this.standardHandler(node, route, undefined, { array: true });
555
439
  }
556
440
  // bitmarkAst -> bits -> bitsValue -> cardNode -> flashcards
557
441
  enter_flashcards(node, route) {
558
- var _a, _b, _c, _d;
559
- const flashcards = node.value;
560
- // Ignore responses that are not at the correct level as they are potentially handled elsewhere
561
- const parent = this.getParentNode(route);
562
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
563
- return;
564
- const flashcardsJson = [];
565
- if (flashcards) {
566
- for (const c of flashcards) {
567
- // Create the flashcard
568
- const flashcardJson = Object.assign(Object.assign({ question: this.convertBreakscapedStringToJsonText((_a = c.question) !== null && _a !== void 0 ? _a : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus), answer: this.convertBreakscapedStringToJsonText((_b = c.answer) !== null && _b !== void 0 ? _b : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus), alternativeAnswers: ((_c = c.alternativeAnswers) !== null && _c !== void 0 ? _c : []).map((a) => this.convertBreakscapedStringToJsonText(a !== null && a !== void 0 ? a : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus)) }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
569
- defaultExample: c.isDefaultExample,
570
- isBoolean: true,
571
- }));
572
- // Delete unwanted properties
573
- if (((_d = c.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
574
- delete flashcardJson.lead;
575
- flashcardsJson.push(flashcardJson);
576
- }
577
- }
578
- if (flashcardsJson.length > 0) {
579
- this.bitJson.cards = flashcardsJson;
580
- }
442
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true, keyOverride: 'cards' });
581
443
  }
582
444
  // bitmarkAst -> bits -> bitsValue -> cardNode -> definitions
583
445
  enter_definitions(node, route) {
584
- var _a, _b, _c, _d;
585
- const definitionListItem = node.value;
586
- // Ignore responses that are not at the correct level as they are potentially handled elsewhere
587
- const parent = this.getParentNode(route);
588
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
589
- return;
590
- const definitionsJson = [];
591
- if (definitionListItem) {
592
- for (const c of definitionListItem) {
593
- // Create the flashcard
594
- const definitionListItemJson = Object.assign(Object.assign({ term: this.convertBreakscapedStringToJsonText((_a = c.term) !== null && _a !== void 0 ? _a : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus), description: this.convertBreakscapedStringToJsonText((_b = c.description) !== null && _b !== void 0 ? _b : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus), alternativeDefinitions: ((_c = c.alternativeDefinitions) !== null && _c !== void 0 ? _c : []).map((a) => this.convertBreakscapedStringToJsonText(a !== null && a !== void 0 ? a : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus)) }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
595
- defaultExample: c.isDefaultExample,
596
- isBoolean: true,
597
- }));
598
- // Delete unwanted properties
599
- if (((_d = c.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
600
- delete definitionListItemJson.lead;
601
- // description-list is an alias of definition-list. Just rename the properties
602
- if (Config_1.Config.isOfBitType(this.getBitType(route), BitType_1.BitType.descriptionList)) {
603
- definitionListItemJson.alternativeDescriptions = definitionListItemJson.alternativeDefinitions;
604
- delete definitionListItemJson.alternativeDefinitions;
605
- }
606
- definitionsJson.push(definitionListItemJson);
607
- }
608
- }
609
- if (definitionsJson.length > 0) {
610
- if (Config_1.Config.isOfBitType(this.getBitType(route), BitType_1.BitType.descriptionList)) {
611
- this.bitJson.descriptions = definitionsJson;
612
- }
613
- else {
614
- this.bitJson.definitions = definitionsJson;
615
- }
616
- }
446
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
617
447
  }
618
448
  // bitmarkAst -> bits -> bitsValue -> statement
619
449
  enter_statement(node, route) {
@@ -624,405 +454,74 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
624
454
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
625
455
  return;
626
456
  if (statement) {
627
- this.bitJson.statement = (_a = Breakscape_1.Breakscape.unbreakscape(statement.text)) !== null && _a !== void 0 ? _a : '';
457
+ this.bitJson.statement = (_a = statement.statement) !== null && _a !== void 0 ? _a : '';
628
458
  this.bitJson.isCorrect = (_b = statement.isCorrect) !== null && _b !== void 0 ? _b : false;
459
+ this.bitJson.example = statement.example;
460
+ this.bitJson.isExample = statement.isExample;
629
461
  }
630
462
  }
631
463
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
632
464
  enter_statements(node, route) {
633
- var _a, _b, _c;
634
- const statements = node.value;
635
- // Ignore statements that are not at the card node level as they are handled elsewhere
636
- const parent = this.getParentNode(route);
637
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
638
- return;
639
- const statementsJson = [];
640
- if (statements) {
641
- for (const s of statements) {
642
- // Create the statement
643
- const statementJson = Object.assign(Object.assign({ statement: (_a = Breakscape_1.Breakscape.unbreakscape(s.text)) !== null && _a !== void 0 ? _a : '', isCorrect: !!s.isCorrect }, this.toItemLeadHintInstruction(s)), this.toExample(s, {
644
- defaultExample: !!s.isCorrect,
645
- isBoolean: true,
646
- }));
647
- // Delete unwanted properties
648
- if (((_b = s.itemLead) === null || _b === void 0 ? void 0 : _b.item) == null)
649
- delete statementJson.item;
650
- if (((_c = s.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
651
- delete statementJson.lead;
652
- if ((s === null || s === void 0 ? void 0 : s.hint) == null)
653
- delete statementJson.hint;
654
- if ((s === null || s === void 0 ? void 0 : s.instruction) == null)
655
- delete statementJson.instruction;
656
- statementsJson.push(statementJson);
657
- }
658
- }
659
- if (statementsJson.length > 0) {
660
- this.bitJson.statements = statementsJson;
661
- }
465
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
662
466
  }
663
467
  // bitmarkAst -> bits -> bitsValue -> choices
664
468
  // X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> choices
665
469
  enter_choices(node, route) {
666
- var _a, _b, _c;
667
- const choices = node.value;
668
- // Ignore choices that are not at the bit level as they are handled elsewhere as quizzes
669
- const parent = this.getParentNode(route);
670
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
671
- return;
672
- const choicesJson = [];
673
- if (choices) {
674
- for (const c of choices) {
675
- // Create the choice
676
- const choiceJson = Object.assign(Object.assign({ choice: (_a = Breakscape_1.Breakscape.unbreakscape(c.text)) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
677
- defaultExample: !!c.isCorrect,
678
- isBoolean: true,
679
- }));
680
- // Delete unwanted properties
681
- if (((_c = c.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
682
- delete choiceJson.lead;
683
- choicesJson.push(choiceJson);
684
- }
685
- }
686
- if (choicesJson.length > 0) {
687
- this.bitJson.choices = choicesJson;
688
- }
470
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
689
471
  }
690
472
  // bitmarkAst -> bits -> bitsValue -> responses
691
473
  // X bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes -> quizzesValue -> responses
692
474
  enter_responses(node, route) {
693
- var _a, _b, _c;
694
- const responses = node.value;
695
- // Ignore responses that are not at the correct level as they are handled elsewhere as quizzes
696
- const parent = this.getParentNode(route);
697
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
698
- return;
699
- const responsesJson = [];
700
- if (responses) {
701
- for (const r of responses) {
702
- // Create the response
703
- const responseJson = Object.assign(Object.assign({ response: (_a = Breakscape_1.Breakscape.unbreakscape(r.text)) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = r.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(r)), this.toExample(r, {
704
- defaultExample: !!r.isCorrect,
705
- isBoolean: true,
706
- }));
707
- // Delete unwanted properties
708
- if (((_c = r.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
709
- delete responseJson.lead;
710
- responsesJson.push(responseJson);
711
- }
712
- }
713
- if (responsesJson.length > 0) {
714
- this.bitJson.responses = responsesJson;
715
- }
475
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
716
476
  }
717
477
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
718
- enter_quizzes(node, _route) {
719
- var _a, _b, _c, _d, _e, _f, _g, _h;
720
- const quizzes = node.value;
721
- const quizzesJson = [];
722
- if (quizzes) {
723
- for (const q of quizzes) {
724
- // Choices
725
- const choicesJson = [];
726
- if (q.choices) {
727
- for (const c of q.choices) {
728
- // Create the choice
729
- const choiceJson = Object.assign(Object.assign({ choice: (_a = Breakscape_1.Breakscape.unbreakscape(c.text)) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
730
- defaultExample: !!c.isCorrect,
731
- isBoolean: true,
732
- }));
733
- // Delete unwanted properties
734
- if (((_c = q.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
735
- delete choiceJson.lead;
736
- choicesJson.push(choiceJson);
737
- }
738
- }
739
- // Responses
740
- const responsesJson = [];
741
- if (q.responses) {
742
- for (const r of q.responses) {
743
- // Create the choice
744
- const responseJson = Object.assign(Object.assign({ response: (_d = Breakscape_1.Breakscape.unbreakscape(r.text)) !== null && _d !== void 0 ? _d : '', isCorrect: (_e = r.isCorrect) !== null && _e !== void 0 ? _e : false }, this.toItemLeadHintInstruction(r)), this.toExample(r, {
745
- defaultExample: !!r.isCorrect,
746
- isBoolean: true,
747
- }));
748
- // Delete unwanted properties
749
- if (((_f = q.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
750
- delete responseJson.lead;
751
- responsesJson.push(responseJson);
752
- }
753
- }
754
- // Create the quiz
755
- const quizJson = Object.assign(Object.assign({}, this.toItemLeadHintInstruction(q)), { isExample: (_g = q.isExample) !== null && _g !== void 0 ? _g : false, choices: q.choices ? choicesJson : undefined, responses: q.responses ? responsesJson : undefined });
756
- // Delete unwanted properties
757
- if (((_h = q.itemLead) === null || _h === void 0 ? void 0 : _h.lead) == null)
758
- delete quizJson.lead;
759
- quizzesJson.push(quizJson);
760
- }
761
- }
762
- if (quizzesJson.length > 0) {
763
- this.bitJson.quizzes = quizzesJson;
764
- }
478
+ enter_quizzes(node, route) {
479
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
765
480
  }
766
481
  // bitmarkAst -> bits -> bitsValue -> cardNode -> heading
767
- enter_heading(node, _route) {
768
- var _a;
769
- const heading = node.value;
770
- // Check if the heading is for a match or a match matrix
771
- const bitType = this.getBitType(_route);
772
- const isMatrix = Config_1.Config.isOfBitType(bitType, BitType_1.BitType.matchMatrix);
773
- // Create the heading
774
- const headingJson = {
775
- forKeys: (_a = Breakscape_1.Breakscape.unbreakscape(heading.forKeys)) !== null && _a !== void 0 ? _a : '',
776
- };
777
- if (isMatrix) {
778
- // Matrix match, forValues is an array
779
- headingJson.forValues = [];
780
- if (Array.isArray(heading.forValues)) {
781
- if (heading.forValues.length >= 1) {
782
- headingJson.forValues = Breakscape_1.Breakscape.unbreakscape(heading.forValues);
783
- }
784
- }
785
- }
786
- else {
787
- // Standard match, forValues is a string
788
- headingJson.forValues = '';
789
- if (Array.isArray(heading.forValues)) {
790
- if (heading.forValues.length >= 1) {
791
- headingJson.forValues = Breakscape_1.Breakscape.unbreakscape(heading.forValues[heading.forValues.length - 1]);
792
- }
793
- }
794
- }
795
- this.bitJson.heading = headingJson;
482
+ enter_heading(node, route) {
483
+ return this.standardHandler(node, route, undefined, { array: false });
796
484
  }
797
485
  // bitmarkAst -> bits -> bitsValue -> cardNode -> pairs
798
486
  enter_pairs(node, route) {
799
- var _a, _b, _c, _d;
800
- const pairs = node.value;
801
- const pairsJson = [];
802
- const bitType = this.getBitType(route);
803
- if (pairs && bitType) {
804
- for (const p of pairs) {
805
- // Get default example
806
- const defaultExample = Array.isArray(p.values) && p.values.length > 0 && p.values[0];
807
- // Create the question
808
- const pairJson = Object.assign(Object.assign(Object.assign({ key: (_a = Breakscape_1.Breakscape.unbreakscape(p.key)) !== null && _a !== void 0 ? _a : '', keyAudio: p.keyAudio ? this.addAudioResource(bitType, p.keyAudio) : undefined, keyImage: p.keyImage ? this.addImageResource(bitType, p.keyImage) : undefined, values: (_b = Breakscape_1.Breakscape.unbreakscape(p.values)) !== null && _b !== void 0 ? _b : [] }, this.toItemLeadHintInstruction(p)), { isCaseSensitive: (_c = p.isCaseSensitive) !== null && _c !== void 0 ? _c : true }), this.toExample(p, {
809
- defaultExample,
810
- isBoolean: false,
811
- }));
812
- // Delete unwanted properties
813
- if (((_d = p.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
814
- delete pairJson.lead;
815
- if (pairJson.key) {
816
- delete pairJson.keyAudio;
817
- delete pairJson.keyImage;
818
- }
819
- if (pairJson.keyAudio != null) {
820
- delete pairJson.key;
821
- delete pairJson.keyImage;
822
- }
823
- if (pairJson.keyImage != null) {
824
- delete pairJson.key;
825
- delete pairJson.keyAudio;
826
- }
827
- pairsJson.push(pairJson);
828
- }
829
- }
830
- if (pairsJson.length > 0) {
831
- this.bitJson.pairs = pairsJson;
832
- }
487
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
833
488
  }
834
489
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
835
- enter_matrix(node, _route) {
836
- var _a, _b, _c, _d, _e, _f;
837
- const matrix = node.value;
838
- const matrixJsonArray = [];
839
- if (matrix) {
840
- for (const m of matrix) {
841
- // Choices
842
- const matrixCellsJson = [];
843
- if (m.cells) {
844
- for (const c of m.cells) {
845
- // Get default example
846
- const defaultExample = Array.isArray(c.values) && c.values.length > 0 && c.values[0];
847
- // Create the choice
848
- const matrixCellJson = Object.assign(Object.assign(Object.assign({ values: (_a = Breakscape_1.Breakscape.unbreakscape(c.values)) !== null && _a !== void 0 ? _a : [] }, this.toItemLeadHintInstruction(c)), { isCaseSensitive: (_b = c.isCaseSensitive) !== null && _b !== void 0 ? _b : true }), this.toExample(c, {
849
- defaultExample,
850
- isBoolean: false,
851
- }));
852
- // Delete unwanted properties
853
- if (((_c = c.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
854
- delete matrixCellJson.lead;
855
- if (c.hint == null)
856
- delete matrixCellJson.hint;
857
- matrixCellsJson.push(matrixCellJson);
858
- }
859
- }
860
- // Create the matrix
861
- const matrixJson = Object.assign(Object.assign({ key: (_d = Breakscape_1.Breakscape.unbreakscape(m.key)) !== null && _d !== void 0 ? _d : '', cells: matrixCellsJson !== null && matrixCellsJson !== void 0 ? matrixCellsJson : [] }, this.toItemLeadHintInstruction(m)), {
862
- // ...this.toExample(m.example, m.isExample),
863
- isExample: (_e = m.isExample) !== null && _e !== void 0 ? _e : false });
864
- // Delete unwanted properties
865
- if (((_f = m.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
866
- delete matrixJson.lead;
867
- if (m.instruction == null)
868
- delete matrixJson.instruction;
869
- matrixJsonArray.push(matrixJson);
870
- }
871
- }
872
- if (matrixJsonArray.length > 0) {
873
- this.bitJson.matrix = matrixJsonArray;
874
- }
490
+ enter_matrix(node, route) {
491
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
875
492
  }
876
493
  // bitmarkAst -> bits -> bitsValue -> cardNode -> table
877
- enter_table(node, _route) {
878
- const table = node.value;
879
- // const bitType = this.getBitType(route);
880
- if (table) {
881
- const tableJson = {
882
- columns: Breakscape_1.Breakscape.unbreakscape(table.columns),
883
- data: table.rows.map((row) => Breakscape_1.Breakscape.unbreakscape(row)),
884
- };
885
- // const isEmpty = !table.columns || table.columns.length === 0 || !table.rows || table.rows.length === 0;
886
- this.bitJson.table = tableJson;
887
- }
888
- // Stop traversal of this branch to avoid unnecessary processing
889
- return false;
494
+ enter_table(node, route) {
495
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: false });
890
496
  }
891
497
  // bitmarkAst -> bits -> bitsValue -> cardNode -> questions
892
- enter_questions(node, _route) {
893
- var _a, _b, _c, _d, _e;
894
- const questions = node.value;
895
- const questionsJson = [];
896
- if (questions) {
897
- for (const q of questions) {
898
- // Create the question
899
- const questionJson = Object.assign(Object.assign(Object.assign({ question: (_a = Breakscape_1.Breakscape.unbreakscape(q.question)) !== null && _a !== void 0 ? _a : '', partialAnswer: (_b = Breakscape_1.Breakscape.unbreakscape(ArrayUtils_1.ArrayUtils.asSingle(q.partialAnswer))) !== null && _b !== void 0 ? _b : '', sampleSolution: (_c = Breakscape_1.Breakscape.unbreakscape(ArrayUtils_1.ArrayUtils.asSingle(q.sampleSolution))) !== null && _c !== void 0 ? _c : '', additionalSolutions: (_d = Breakscape_1.Breakscape.unbreakscape(q.additionalSolutions)) !== null && _d !== void 0 ? _d : [] }, this.toItemLeadHintInstruction(q)), { reasonableNumOfChars: q.reasonableNumOfChars }), this.toExample(q, {
900
- defaultExample: q.sampleSolution || '',
901
- isBoolean: false,
902
- }));
903
- // Delete unwanted properties
904
- if (((_e = q.itemLead) === null || _e === void 0 ? void 0 : _e.lead) == null)
905
- delete questionJson.lead;
906
- if (q.additionalSolutions == null || q.additionalSolutions.length === 0) {
907
- delete questionJson.additionalSolutions;
908
- }
909
- questionsJson.push(questionJson);
910
- }
911
- }
912
- if (questionsJson.length > 0) {
913
- this.bitJson.questions = questionsJson;
914
- }
498
+ enter_questions(node, route) {
499
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
915
500
  }
916
501
  // bitmarkAst -> bits -> bitsValue -> cardNode -> botResponses
917
502
  enter_botResponses(node, route) {
918
- var _a, _b, _c, _d;
919
- const botResponses = node.value;
920
- // Ignore responses that are not at the cardNode level as they are handled elsewhere
921
- const parent = this.getParentNode(route);
922
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
923
- return;
924
- const responsesJson = [];
925
- if (botResponses) {
926
- for (const r of botResponses) {
927
- // Create the response
928
- const responseJson = Object.assign({ response: (_a = Breakscape_1.Breakscape.unbreakscape(r.response)) !== null && _a !== void 0 ? _a : '', reaction: (_b = Breakscape_1.Breakscape.unbreakscape(r.reaction)) !== null && _b !== void 0 ? _b : '', feedback: (_c = Breakscape_1.Breakscape.unbreakscape(r.feedback)) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(r));
929
- // Delete unwanted properties
930
- if (((_d = r.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
931
- delete responseJson.lead;
932
- if (r.hint == null)
933
- delete responseJson.hint;
934
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
935
- delete responseJson.instruction;
936
- responsesJson.push(responseJson);
937
- }
938
- }
939
- if (responsesJson.length > 0) {
940
- this.bitJson.responses = responsesJson;
941
- }
503
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true, keyOverride: 'responses' });
942
504
  }
943
505
  // bitmarkAst -> bits -> bitsValue -> cardNode -> ingredients -> ingredientsValue
944
506
  enter_ingredients(node, route) {
945
- var _a, _b, _c, _d, _e, _f, _g, _h;
946
- const ingredients = node.value;
947
- // Ignore statements that are not at the card node level as they are handled elsewhere
948
- const parent = this.getParentNode(route);
949
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
950
- return;
951
- const ingredientsJson = [];
952
- if (ingredients) {
953
- for (const i of ingredients) {
954
- // Create the ingredient
955
- const ingredientJson = {
956
- title: (_a = Breakscape_1.Breakscape.unbreakscape(i.title)) !== null && _a !== void 0 ? _a : '',
957
- checked: (_b = i.checked) !== null && _b !== void 0 ? _b : false,
958
- item: (_c = Breakscape_1.Breakscape.unbreakscape(i.item)) !== null && _c !== void 0 ? _c : '',
959
- quantity: (_d = i.quantity) !== null && _d !== void 0 ? _d : 0,
960
- unit: (_e = Breakscape_1.Breakscape.unbreakscape(i.unit)) !== null && _e !== void 0 ? _e : '',
961
- unitAbbr: (_f = Breakscape_1.Breakscape.unbreakscape(i.unitAbbr)) !== null && _f !== void 0 ? _f : '',
962
- decimalPlaces: (_g = i.decimalPlaces) !== null && _g !== void 0 ? _g : 1,
963
- disableCalculation: (_h = i.disableCalculation) !== null && _h !== void 0 ? _h : false,
964
- };
965
- // Delete unwanted properties
966
- if ((i === null || i === void 0 ? void 0 : i.title) == null)
967
- delete ingredientJson.title;
968
- // if (i?.unit == null) delete ingredientJson.unit;
969
- if ((i === null || i === void 0 ? void 0 : i.unitAbbr) == null)
970
- delete ingredientJson.unitAbbr;
971
- // if (i?.instruction == null) delete ingredientJson.instruction;
972
- ingredientsJson.push(ingredientJson);
973
- }
974
- }
975
- if (ingredientsJson.length > 0) {
976
- this.bitJson.ingredients = ingredientsJson;
977
- }
507
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: true });
978
508
  }
979
509
  // bitmarkAst -> bits -> bitsValue -> cardNode -> captionDefinitionList
980
- enter_captionDefinitionList(node, _route) {
981
- var _a, _b;
982
- const list = node.value;
983
- // const bitType = this.getBitType(route);
984
- if (list) {
985
- const columns = (_a = list.columns) !== null && _a !== void 0 ? _a : [];
986
- const definitions = (_b = list.definitions) !== null && _b !== void 0 ? _b : [];
987
- const captionDefinitionListJson = {
988
- columns: Breakscape_1.Breakscape.unbreakscape(columns),
989
- definitions: definitions.map((d) => {
990
- var _a, _b;
991
- return {
992
- term: (_a = Breakscape_1.Breakscape.unbreakscape(d.term)) !== null && _a !== void 0 ? _a : '',
993
- description: (_b = Breakscape_1.Breakscape.unbreakscape(d.description)) !== null && _b !== void 0 ? _b : '',
994
- };
995
- }),
996
- };
997
- // const isEmpty = !table.columns || table.columns.length === 0 || !table.rows || table.rows.length === 0;
998
- this.bitJson.captionDefinitionList = captionDefinitionListJson;
999
- }
1000
- // Stop traversal of this branch to avoid unnecessary processing
1001
- return false;
510
+ enter_captionDefinitionList(node, route) {
511
+ return this.standardHandler(node, route, NodeType_1.NodeType.cardNode, { array: false });
1002
512
  }
1003
513
  // bitmarkAst -> bits -> bitsValue -> imagePlaceholder
1004
514
  enter_imagePlaceholder(node, route) {
1005
- // Ignore imagePlaceholder that is not at the bit level as it are handled elsewhere
1006
- const parent = this.getParentNode(route);
1007
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
1008
- return;
1009
- const resource = node.value;
1010
- const bitType = this.getBitType(route);
1011
- if (!resource || !bitType)
1012
- return;
1013
- const res = this.parseResourceToJson(bitType, resource);
1014
- if (res && res.type === ResourceTag_1.ResourceTag.image) {
1015
- this.bitJson.imagePlaceholder = res;
1016
- }
515
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1017
516
  }
1018
517
  // bitmarkAst -> bits -> bitsValue -> resources
1019
518
  enter_resources(node, route) {
1020
- var _a;
519
+ var _a, _b;
1021
520
  const resources = node.value;
1022
521
  const bitType = this.getBitType(route);
1023
522
  const resourceType = this.getResourceType(route);
1024
523
  if (!resources || !bitType)
1025
- return;
524
+ return true;
1026
525
  let resourceJson;
1027
526
  const bitConfig = Config_1.Config.getBitConfig(bitType);
1028
527
  const bitResourcesConfig = Config_1.Config.getBitResourcesConfig(bitType, resourceType);
@@ -1036,15 +535,17 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1036
535
  // Create the combo resource wrapper
1037
536
  const wrapper = {
1038
537
  type: comboTagType,
538
+ __typeAlias: comboTagType,
1039
539
  };
1040
540
  // For each of the resources in this combo resource, find the actual resource and add it to the JSON
1041
541
  for (const rt of resourceTags) {
1042
- const r = resources.find((r) => r.typeAlias === rt);
542
+ const r = resources.find((r) => r.__typeAlias === rt);
1043
543
  // Extract everything except the type from the resource
1044
544
  if (r) {
1045
- const tagConfig = Config_1.Config.getTagConfigForTag(bitConfig.tags, r.typeAlias);
1046
- const key = (_a = tagConfig === null || tagConfig === void 0 ? void 0 : tagConfig.jsonKey) !== null && _a !== void 0 ? _a : r.typeAlias;
1047
- const json = this.parseResourceToJson(bitType, r);
545
+ const tagConfig = Config_1.Config.getTagConfigForTag(bitConfig.tags, r.__typeAlias);
546
+ const key = (_a = tagConfig === null || tagConfig === void 0 ? void 0 : tagConfig.jsonKey) !== null && _a !== void 0 ? _a : r.__typeAlias;
547
+ const tag = (_b = tagConfig === null || tagConfig === void 0 ? void 0 : tagConfig.tag) !== null && _b !== void 0 ? _b : r.__typeAlias;
548
+ const json = r.__typeAlias === tag ? r : undefined;
1048
549
  if (json) {
1049
550
  for (const [k, v] of Object.entries(json)) {
1050
551
  if (k !== 'type') {
@@ -1062,9 +563,8 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1062
563
  // The resource is a logo-grave / prototpye-images resource
1063
564
  const images = [];
1064
565
  for (const r of resources) {
1065
- const json = this.parseResourceToJson(bitType, r);
1066
- if (json) {
1067
- images.push(json);
566
+ if (r.type === ResourceTag_1.ResourceTag.image) {
567
+ images.push(r);
1068
568
  }
1069
569
  }
1070
570
  if (bitType === BitType_1.BitType.imagesLogoGrave) {
@@ -1078,93 +578,49 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1078
578
  // This is a standard resource. If there is more than one resource, use the first one.
1079
579
  // There should not be more than one because of validation
1080
580
  if (resources.length >= 1) {
1081
- resourceJson = this.parseResourceToJson(bitType, resources[0]);
581
+ resourceJson = resources[0]; // this.parseResourceToJson(bitType, resources[0]);
1082
582
  }
1083
583
  }
1084
584
  this.bitJson.resource = resourceJson;
585
+ return false;
1085
586
  }
1086
587
  //
1087
588
  // Terminal nodes (leaves)
1088
589
  //
1089
- // bitmarkAst -> bits -> bitsValue -> title
1090
- leaf_title(node, route) {
1091
- // Ignore title that are not at the bit or card node level as they are handled elsewhere
1092
- const parent = this.getParentNode(route);
1093
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue && (parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
1094
- return;
1095
- this.bitJson.title = this.convertBreakscapedStringToJsonText(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1096
- }
1097
- // bitmarkAst -> bits -> bitsValue -> subtitle
1098
- leaf_subtitle(node, _route) {
1099
- this.bitJson.subtitle = this.convertBreakscapedStringToJsonText(node.value, TextFormat_1.TextFormat.bitmarkMinusMinus);
1100
- }
1101
- // // bitmarkAst -> bits -> bitsValue -> level
1102
- leaf_level(node, _route) {
1103
- var _a;
1104
- if (node.value != null)
1105
- this.addProperty(this.bitJson, 'level', (_a = node.value) !== null && _a !== void 0 ? _a : 1, true);
590
+ // bitmarkAst -> bits -> bitsValue -> level
591
+ leaf_level(node, route) {
592
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1106
593
  }
1107
594
  // bitmarkAst -> bits -> bitsValue -> book
1108
- leaf_book(node, _route) {
1109
- if (node.value != null)
1110
- this.addProperty(this.bitJson, 'book', node.value, true);
595
+ leaf_book(node, route) {
596
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1111
597
  }
1112
598
  // bitmarkAst -> bits -> bitsValue -> anchor
1113
- leaf_anchor(node, _route) {
1114
- if (node.value != null)
1115
- this.addProperty(this.bitJson, 'anchor', node.value, true);
599
+ leaf_anchor(node, route) {
600
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1116
601
  }
1117
602
  // bitmarkAst -> bits -> bitsValue -> reference
1118
- leaf_reference(node, _route) {
1119
- if (node.value != null)
1120
- this.addProperty(this.bitJson, 'reference', node.value, true);
603
+ leaf_reference(node, route) {
604
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1121
605
  }
1122
606
  // bitmarkAst -> bits -> bitsValue -> referenceEnd
1123
- leaf_referenceEnd(node, _route) {
1124
- if (node.value != null)
1125
- this.addProperty(this.bitJson, 'referenceEnd', node.value, true);
1126
- }
1127
- // bitmarkAst -> bits -> bitsValue -> caption
1128
- leaf_caption(node, route) {
1129
- const caption = node.value;
1130
- // Ignore caption that is not at the bit level as it are handled elsewhere
1131
- const parent = this.getParentNode(route);
1132
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
1133
- return;
1134
- this.bitJson.caption = this.convertBreakscapedStringToJsonText(caption, TextFormat_1.TextFormat.bitmarkMinusMinus);
1135
- }
1136
- // bitmarkAst -> bits -> bitsValue -> * -> hint
1137
- leaf_hint(node, route) {
1138
- const hint = node.value;
1139
- // Ignore hint that is not at the bit level as it are handled elsewhere
1140
- const parent = this.getParentNode(route);
1141
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
1142
- return;
1143
- this.bitJson.hint = this.convertBreakscapedStringToJsonText(hint, TextFormat_1.TextFormat.bitmarkMinusMinus);
1144
- }
1145
- // bitmarkAst -> bits -> bitsValue -> * -> instruction
1146
- leaf_instruction(node, route) {
1147
- const instruction = node.value;
1148
- // Ignore instruction that is not at the bit level as it are handled elsewhere
1149
- const parent = this.getParentNode(route);
1150
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
1151
- return;
1152
- this.bitJson.instruction = this.convertBreakscapedStringToJsonText(instruction, TextFormat_1.TextFormat.bitmarkMinusMinus);
1153
- }
1154
- // bitmarkAst -> bits -> footer -> footerText
1155
- leaf_footerText(node, route) {
1156
- const footer = node.value;
1157
- const textFormat = this.getTextFormat(route);
1158
- this.bitJson.footer = this.convertBreakscapedStringToJsonText(footer, textFormat);
607
+ leaf_referenceEnd(node, route) {
608
+ return this.standardHandler(node, route, NodeType_1.NodeType.bitsValue, { array: false });
1159
609
  }
1160
610
  // bitmarkAst -> bits -> bitsValue -> markup
1161
611
  leaf_markup(node, _route) {
1162
612
  const bitmark = node.value;
1163
613
  if (bitmark)
1164
614
  this.bitWrapperJson.bitmark = bitmark;
615
+ // Stop traversal of this branch
616
+ return false;
1165
617
  }
1166
- // bitmarkAst -> bits -> bitsValue -> parser
1167
618
  // bitmarkAst -> bits -> bitsValue -> * -> internalComment
619
+ enter_internalComment(_node, _route) {
620
+ // Stop traversal of this branch, handled in enter_parser()
621
+ return false;
622
+ }
623
+ // bitmarkAst -> bits -> bitsValue -> parser
1168
624
  enter_parser(node, route) {
1169
625
  const parser = node.value;
1170
626
  const bitType = this.getBitType(route);
@@ -1178,13 +634,11 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1178
634
  if (Array.isArray(parserExcessResources) && parserExcessResources.length > 0) {
1179
635
  excessResources = [];
1180
636
  for (const r of parserExcessResources) {
1181
- const rJson = this.parseResourceToJson(bitType, r);
1182
- if (rJson)
1183
- excessResources.push(rJson);
637
+ excessResources.push(r);
1184
638
  }
1185
639
  }
1186
640
  // Extract internal comments from the AST and add to the parser
1187
- const internalComments = Breakscape_1.Breakscape.unbreakscape(this.getInternalComments(route));
641
+ const internalComments = this.getInternalComments(route);
1188
642
  if ((parent === null || parent === void 0 ? void 0 : parent.key) === NodeType_1.NodeType.bitsValue) {
1189
643
  // Bit level parser information
1190
644
  this.bitWrapperJson.parser = Object.assign(Object.assign({ version,
@@ -1230,32 +684,12 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1230
684
  const propertiesConfig = Config_1.Config.getRawPropertiesConfig();
1231
685
  for (const propertyConfig of Object.values(propertiesConfig)) {
1232
686
  const astKey = (_a = propertyConfig.astKey) !== null && _a !== void 0 ? _a : propertyConfig.tag;
1233
- // Special cases (handled outside of the automatically generated handlers)
1234
- if (astKey === PropertyTag_1.PropertyTag.internalComment)
1235
- continue;
1236
- if (astKey === PropertyTag_1.PropertyTag.caption)
1237
- continue;
1238
- if (astKey === PropertyTag_1.PropertyTag.example)
1239
- continue;
1240
- if (astKey === PropertyTag_1.PropertyTag.imageSource)
1241
- continue;
1242
- if (astKey === PropertyTag_1.PropertyTag.person)
1243
- continue;
1244
- if (astKey === PropertyTag_1.PropertyTag.imagePlaceholder)
1245
- continue;
1246
- if (astKey === PropertyTag_1.PropertyTag.width)
1247
- continue;
1248
- if (astKey === PropertyTag_1.PropertyTag.height)
1249
- continue;
1250
- if (astKey === PropertyAstKey_1.PropertyAstKey.ast_markConfig)
1251
- continue;
1252
- if (astKey === PropertyTag_1.PropertyTag.ratingLevelStart)
1253
- continue;
1254
- if (astKey === PropertyTag_1.PropertyTag.ratingLevelEnd)
1255
- continue;
1256
- if (astKey === PropertyTag_1.PropertyTag.productId)
1257
- continue;
1258
687
  const funcName = `enter_${astKey}`;
688
+ // Skip if the function already exists, allows for custom handlers
689
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
690
+ if (typeof this[funcName] === 'function') {
691
+ continue;
692
+ }
1259
693
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1260
694
  this[funcName] = (node, route) => {
1261
695
  var _a;
@@ -1270,7 +704,7 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1270
704
  // Convert key as needed
1271
705
  const jsonKey = (_a = propertyConfig.jsonKey) !== null && _a !== void 0 ? _a : propertyConfig.tag;
1272
706
  // Add the property
1273
- this.addProperty(this.bitJson, jsonKey, value, propertyConfig.single);
707
+ this.addProperty(this.bitJson, jsonKey, value, { array: !propertyConfig.single });
1274
708
  };
1275
709
  // Bind this
1276
710
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1281,605 +715,51 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1281
715
  //
1282
716
  // HELPER FUNCTIONS
1283
717
  //
1284
- createGapJson(gap) {
1285
- var _a;
1286
- const data = gap.data;
1287
- const defaultExample = data.solutions && data.solutions.length > 0 ? data.solutions[0] : '';
1288
- // Create the gap
1289
- const gapJson = Object.assign(Object.assign(Object.assign(Object.assign({ type: 'gap' }, this.toItemLeadHintInstruction(data)), { isCaseSensitive: (_a = data.isCaseSensitive) !== null && _a !== void 0 ? _a : true }), this.toExample(data, {
1290
- defaultExample,
1291
- isBoolean: false,
1292
- })), { solutions: Breakscape_1.Breakscape.unbreakscape(data.solutions) });
1293
- // Remove unwanted properties
1294
- // if (!data.itemLead?.lead) delete gapJson.lead;
1295
- return gapJson;
1296
- }
1297
- createMarkJson(mark) {
1298
- const data = mark.data;
1299
- // Create the mark
1300
- const markJson = Object.assign(Object.assign({ type: 'mark', solution: Breakscape_1.Breakscape.unbreakscape(data.solution), mark: Breakscape_1.Breakscape.unbreakscape(data.mark) }, this.toItemLeadHintInstruction(data)), this.toExample(data, {
1301
- defaultExample: true,
1302
- isBoolean: true,
1303
- }));
1304
- // Remove unwanted properties
1305
- // if (!data.itemLead?.lead) delete markJson.lead;
1306
- return markJson;
1307
- }
1308
- createSelectJson(select) {
1309
- var _a, _b, _c, _d;
1310
- const data = select.data;
1311
- // Create the select options
1312
- const options = [];
1313
- for (const option of data.options) {
1314
- const optionJson = Object.assign(Object.assign({ text: Breakscape_1.Breakscape.unbreakscape(option.text), isCorrect: (_a = option.isCorrect) !== null && _a !== void 0 ? _a : false }, this.toItemLeadHintInstruction(option)), this.toExample(option, {
1315
- defaultExample: !!option.isCorrect,
1316
- isBoolean: true,
1317
- }));
1318
- // Remove unwanted properties
1319
- // if (!option.itemLead?.item) delete optionJson.item;
1320
- // if (!option.itemLead?.lead) delete optionJson.lead;
1321
- // if (!option.instruction) delete optionJson.instruction;
1322
- options.push(optionJson);
1323
- }
1324
- // Create the select
1325
- const selectJson = Object.assign(Object.assign({ type: 'select', prefix: (_b = Breakscape_1.Breakscape.unbreakscape(data.prefix)) !== null && _b !== void 0 ? _b : '', postfix: (_c = Breakscape_1.Breakscape.unbreakscape(data.postfix)) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(data)), { isExample: (_d = data.isExample) !== null && _d !== void 0 ? _d : false, options });
1326
- // Remove unwanted properties
1327
- // if (!data.itemLead?.lead) delete selectJson.lead;
1328
- return selectJson;
1329
- }
1330
- createHighlightJson(highlight) {
1331
- var _a, _b, _c, _d, _e;
1332
- const data = highlight.data;
1333
- // Create the highlight options
1334
- const texts = [];
1335
- for (const text of data.texts) {
1336
- const textJson = Object.assign(Object.assign({ text: Breakscape_1.Breakscape.unbreakscape(text.text), isCorrect: (_a = text.isCorrect) !== null && _a !== void 0 ? _a : false, isHighlighted: (_b = text.isHighlighted) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(text)), this.toExample(text, {
1337
- defaultExample: !!text.isCorrect,
1338
- isBoolean: true,
1339
- }));
1340
- // Remove unwanted properties
1341
- // if (!text.itemLead?.item) delete textJson.item;
1342
- // if (!text.itemLead?.lead) delete textJson.lead;
1343
- // if (!text.hint) delete textJson.hint;
1344
- texts.push(textJson);
1345
- }
1346
- // Create the select
1347
- const highlightJson = Object.assign(Object.assign({ type: 'highlight', prefix: (_c = Breakscape_1.Breakscape.unbreakscape(data.prefix)) !== null && _c !== void 0 ? _c : '', postfix: (_d = Breakscape_1.Breakscape.unbreakscape(data.postfix)) !== null && _d !== void 0 ? _d : '' }, this.toItemLeadHintInstruction(data)), { isExample: (_e = data.isExample) !== null && _e !== void 0 ? _e : false, texts });
1348
- // Remove unwanted properties
1349
- // if (!data.itemLead?.lead) delete highlightJson.lead;
1350
- return highlightJson;
1351
- }
1352
- parseResourceToJson(bitType, resource) {
1353
- if (!resource)
1354
- return undefined;
1355
- // All resources should now be valid as they are validated in the AST
1356
- // TODO: remove code below
1357
- // // Check if a resource has a value, if not, we should not write it (or any of its chained properties)
1358
- // let valid = false;
1359
- // if (resource.value) {
1360
- // valid = true;
1361
- // }
1362
- // // Resource is not valid, return undefined
1363
- // if (!valid) return undefined;
1364
- // // Resource is valid, write it.
1365
- let resourceJson;
1366
- switch (resource.type) {
1367
- case ResourceTag_1.ResourceTag.image:
1368
- resourceJson = {
1369
- type: ResourceTag_1.ResourceTag.image,
1370
- image: this.addImageResource(bitType, resource),
1371
- };
1372
- break;
1373
- case ResourceTag_1.ResourceTag.imageLink:
1374
- resourceJson = {
1375
- type: ResourceTag_1.ResourceTag.imageLink,
1376
- imageLink: this.addImageLinkResource(bitType, resource),
1377
- };
1378
- break;
1379
- case ResourceTag_1.ResourceTag.audio:
1380
- resourceJson = {
1381
- type: ResourceTag_1.ResourceTag.audio,
1382
- audio: this.addAudioResource(bitType, resource),
1383
- };
1384
- break;
1385
- case ResourceTag_1.ResourceTag.audioEmbed:
1386
- resourceJson = {
1387
- type: ResourceTag_1.ResourceTag.audioEmbed,
1388
- audioEmbed: this.addAudioEmbedResource(bitType, resource),
1389
- };
1390
- break;
1391
- case ResourceTag_1.ResourceTag.audioLink:
1392
- resourceJson = {
1393
- type: ResourceTag_1.ResourceTag.audioLink,
1394
- audioLink: this.addAudioLinkResource(bitType, resource),
1395
- };
1396
- break;
1397
- case ResourceTag_1.ResourceTag.video:
1398
- resourceJson = {
1399
- type: ResourceTag_1.ResourceTag.video,
1400
- video: this.addVideoResource(bitType, resource),
1401
- };
1402
- break;
1403
- case ResourceTag_1.ResourceTag.videoEmbed:
1404
- resourceJson = {
1405
- type: ResourceTag_1.ResourceTag.videoEmbed,
1406
- videoEmbed: this.addVideoEmbedResource(bitType, resource),
1407
- };
1408
- resourceJson.videoEmbed = this.addVideoLinkResource(bitType, resource);
1409
- break;
1410
- case ResourceTag_1.ResourceTag.videoLink:
1411
- resourceJson = {
1412
- type: ResourceTag_1.ResourceTag.videoLink,
1413
- videoLink: this.addVideoLinkResource(bitType, resource),
1414
- };
1415
- break;
1416
- case ResourceTag_1.ResourceTag.stillImageFilmEmbed:
1417
- resourceJson = {
1418
- type: ResourceTag_1.ResourceTag.stillImageFilmEmbed,
1419
- stillImageFilmEmbed: this.addStillImageFilmEmbedResource(bitType, resource),
1420
- };
1421
- break;
1422
- case ResourceTag_1.ResourceTag.stillImageFilmLink:
1423
- resourceJson = {
1424
- type: ResourceTag_1.ResourceTag.stillImageFilmLink,
1425
- stillImageFilmLink: this.addStillImageFilmLinkResource(bitType, resource),
1426
- };
1427
- break;
1428
- case ResourceTag_1.ResourceTag.article:
1429
- resourceJson = {
1430
- type: ResourceTag_1.ResourceTag.article,
1431
- article: this.addArticleResource(bitType, resource),
1432
- };
1433
- break;
1434
- case ResourceTag_1.ResourceTag.document:
1435
- resourceJson = {
1436
- type: ResourceTag_1.ResourceTag.document,
1437
- document: this.addDocumentResource(bitType, resource),
1438
- };
1439
- break;
1440
- case ResourceTag_1.ResourceTag.documentEmbed:
1441
- resourceJson = {
1442
- type: ResourceTag_1.ResourceTag.documentEmbed,
1443
- documentEmbed: this.addDocumentEmbedResource(bitType, resource),
1444
- };
1445
- break;
1446
- case ResourceTag_1.ResourceTag.documentLink:
1447
- resourceJson = {
1448
- type: ResourceTag_1.ResourceTag.documentLink,
1449
- documentLink: this.addDocumentLinkResource(bitType, resource),
1450
- };
1451
- break;
1452
- case ResourceTag_1.ResourceTag.documentDownload:
1453
- resourceJson = {
1454
- type: ResourceTag_1.ResourceTag.documentDownload,
1455
- documentDownload: this.addDocumentDownloadResource(bitType, resource),
1456
- };
1457
- break;
1458
- case ResourceTag_1.ResourceTag.appLink:
1459
- resourceJson = {
1460
- type: ResourceTag_1.ResourceTag.appLink,
1461
- appLink: this.addAppLinkResource(bitType, resource),
1462
- };
1463
- break;
1464
- case ResourceTag_1.ResourceTag.websiteLink:
1465
- resourceJson = {
1466
- type: ResourceTag_1.ResourceTag.websiteLink,
1467
- websiteLink: this.addWebsiteLinkResource(bitType, resource),
1468
- };
1469
- break;
1470
- default:
1471
- }
1472
- return resourceJson;
1473
- }
1474
- addImageResource(bitType, resource) {
1475
- var _a, _b, _c;
1476
- const resourceJson = {};
1477
- if (StringUtils_1.StringUtils.isString(resource)) {
1478
- const value = resource;
1479
- resource = {
1480
- type: ResourceTag_1.ResourceTag.image,
1481
- typeAlias: ResourceTag_1.ResourceTag.image,
1482
- value: value,
1483
- format: UrlUtils_1.UrlUtils.fileExtensionFromUrl(value),
1484
- provider: UrlUtils_1.UrlUtils.domainFromUrl(value),
1485
- };
1486
- }
1487
- resource = resource; // Keep TS compiler happy
1488
- if (resource.format != null)
1489
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1490
- if (resource.provider != null)
1491
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1492
- if (resource.value != null)
1493
- resourceJson.src = Breakscape_1.Breakscape.unbreakscape(resource.value);
1494
- if (resource.src1x != null)
1495
- resourceJson.src1x = Breakscape_1.Breakscape.unbreakscape(resource.src1x);
1496
- if (resource.src2x != null)
1497
- resourceJson.src2x = Breakscape_1.Breakscape.unbreakscape(resource.src2x);
1498
- if (resource.src3x != null)
1499
- resourceJson.src3x = Breakscape_1.Breakscape.unbreakscape(resource.src3x);
1500
- if (resource.src4x != null)
1501
- resourceJson.src4x = Breakscape_1.Breakscape.unbreakscape(resource.src4x);
1502
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1503
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1504
- resourceJson.alt = (_c = Breakscape_1.Breakscape.unbreakscape(resource.alt)) !== null && _c !== void 0 ? _c : '';
1505
- resourceJson.zoomDisabled = this.getZoomDisabled(bitType, resource.zoomDisabled);
1506
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1507
- return resourceJson;
1508
- }
1509
- addImageLinkResource(bitType, resource) {
1510
- var _a, _b, _c;
1511
- const resourceJson = {};
1512
- if (StringUtils_1.StringUtils.isString(resource)) {
1513
- const value = resource;
1514
- resource = {
1515
- type: ResourceTag_1.ResourceTag.imageLink,
1516
- typeAlias: ResourceTag_1.ResourceTag.imageLink,
1517
- value,
1518
- format: UrlUtils_1.UrlUtils.fileExtensionFromUrl(value),
1519
- provider: UrlUtils_1.UrlUtils.domainFromUrl(value),
1520
- };
1521
- }
1522
- resource = resource; // Keep TS compiler happy
1523
- if (resource.format != null)
1524
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1525
- if (resource.provider != null)
1526
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1527
- if (resource.value != null)
1528
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1529
- if (resource.src1x != null)
1530
- resourceJson.src1x = Breakscape_1.Breakscape.unbreakscape(resource.src1x);
1531
- if (resource.src2x != null)
1532
- resourceJson.src2x = Breakscape_1.Breakscape.unbreakscape(resource.src2x);
1533
- if (resource.src3x != null)
1534
- resourceJson.src3x = Breakscape_1.Breakscape.unbreakscape(resource.src3x);
1535
- if (resource.src4x != null)
1536
- resourceJson.src4x = Breakscape_1.Breakscape.unbreakscape(resource.src4x);
1537
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1538
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1539
- resourceJson.alt = (_c = Breakscape_1.Breakscape.unbreakscape(resource.alt)) !== null && _c !== void 0 ? _c : '';
1540
- resourceJson.zoomDisabled = this.getZoomDisabled(bitType, resource.zoomDisabled);
1541
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1542
- return resourceJson;
1543
- }
1544
- addAudioResource(bitType, resource) {
1545
- const resourceJson = {};
1546
- if (resource.format != null)
1547
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1548
- if (resource.provider != null)
1549
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1550
- if (resource.value != null)
1551
- resourceJson.src = Breakscape_1.Breakscape.unbreakscape(resource.value);
1552
- if (resource.duration != null)
1553
- resourceJson.duration = resource.duration;
1554
- if (resource.mute != null)
1555
- resourceJson.mute = resource.mute;
1556
- if (resource.autoplay != null)
1557
- resourceJson.autoplay = resource.autoplay;
1558
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1559
- return resourceJson;
1560
- }
1561
- addAudioEmbedResource(bitType, resource) {
1562
- const resourceJson = {};
1563
- if (resource.format != null)
1564
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1565
- if (resource.provider != null)
1566
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1567
- if (resource.value != null)
1568
- resourceJson.src = Breakscape_1.Breakscape.unbreakscape(resource.value);
1569
- if (resource.duration != null)
1570
- resourceJson.duration = resource.duration;
1571
- if (resource.mute != null)
1572
- resourceJson.mute = resource.mute;
1573
- if (resource.autoplay != null)
1574
- resourceJson.autoplay = resource.autoplay;
1575
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1576
- return resourceJson;
1577
- }
1578
- addAudioLinkResource(bitType, resource) {
1579
- const resourceJson = {};
1580
- if (resource.format != null)
1581
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1582
- if (resource.provider != null)
1583
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1584
- if (resource.value != null)
1585
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1586
- if (resource.duration != null)
1587
- resourceJson.duration = resource.duration;
1588
- if (resource.mute != null)
1589
- resourceJson.mute = resource.mute;
1590
- if (resource.autoplay != null)
1591
- resourceJson.autoplay = resource.autoplay;
1592
- this.addGenericResourceProperties(bitType, resource, resourceJson, true);
1593
- return resourceJson;
1594
- }
1595
- addVideoResource(bitType, resource) {
1596
- var _a, _b;
1597
- const resourceJson = {};
1598
- if (resource.format != null)
1599
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1600
- if (resource.provider != null)
1601
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1602
- if (resource.value != null)
1603
- resourceJson.src = Breakscape_1.Breakscape.unbreakscape(resource.value);
1604
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1605
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1606
- if (resource.duration != null)
1607
- resourceJson.duration = resource.duration;
1608
- if (resource.mute != null)
1609
- resourceJson.mute = resource.mute;
1610
- if (resource.autoplay != null)
1611
- resourceJson.autoplay = resource.autoplay;
1612
- if (resource.allowSubtitles != null)
1613
- resourceJson.allowSubtitles = resource.allowSubtitles;
1614
- if (resource.showSubtitles != null)
1615
- resourceJson.showSubtitles = resource.showSubtitles;
1616
- if (resource.alt != null)
1617
- resourceJson.alt = Breakscape_1.Breakscape.unbreakscape(resource.alt);
1618
- if (resource.posterImage != null)
1619
- resourceJson.posterImage = this.addImageResource(bitType, resource.posterImage);
1620
- if (resource.thumbnails != null && resource.thumbnails.length > 0) {
1621
- resourceJson.thumbnails = [];
1622
- for (const thumbnail of resource.thumbnails) {
1623
- resourceJson.thumbnails.push(this.addImageResource(bitType, thumbnail));
1624
- }
1625
- }
1626
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1627
- return resourceJson;
1628
- }
1629
- addVideoEmbedResource(bitType, resource) {
1630
- var _a, _b;
1631
- const resourceJson = {};
1632
- if (resource.format != null)
1633
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1634
- if (resource.provider != null)
1635
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1636
- if (resource.value != null)
1637
- resourceJson.src = Breakscape_1.Breakscape.unbreakscape(resource.value);
1638
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1639
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1640
- if (resource.duration != null)
1641
- resourceJson.duration = resource.duration;
1642
- if (resource.mute != null)
1643
- resourceJson.mute = resource.mute;
1644
- if (resource.autoplay != null)
1645
- resourceJson.autoplay = resource.autoplay;
1646
- if (resource.allowSubtitles != null)
1647
- resourceJson.allowSubtitles = resource.allowSubtitles;
1648
- if (resource.showSubtitles != null)
1649
- resourceJson.showSubtitles = resource.showSubtitles;
1650
- if (resource.alt != null)
1651
- resourceJson.alt = Breakscape_1.Breakscape.unbreakscape(resource.alt);
1652
- if (resource.posterImage != null)
1653
- resourceJson.posterImage = this.addImageResource(bitType, resource.posterImage);
1654
- if (resource.thumbnails != null && resource.thumbnails.length > 0) {
1655
- resourceJson.thumbnails = [];
1656
- for (const thumbnail of resource.thumbnails) {
1657
- resourceJson.thumbnails.push(this.addImageResource(bitType, thumbnail));
1658
- }
1659
- }
1660
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1661
- return resourceJson;
1662
- }
1663
- addVideoLinkResource(bitType, resource) {
718
+ /**
719
+ * Default handler for properties.
720
+ *
721
+ * @param node the node
722
+ * @param route the route to the node
723
+ * @param parentNodeTypes the parent node types for which to handle the node
724
+ * @returns
725
+ */
726
+ standardHandler(node, route, parentNodeTypes, options) {
1664
727
  var _a, _b;
1665
- const resourceJson = {};
1666
- if (resource.format != null)
1667
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1668
- if (resource.provider != null)
1669
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1670
- if (resource.value != null)
1671
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1672
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1673
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1674
- if (resource.duration != null)
1675
- resourceJson.duration = resource.duration;
1676
- if (resource.mute != null)
1677
- resourceJson.mute = resource.mute;
1678
- if (resource.autoplay != null)
1679
- resourceJson.autoplay = resource.autoplay;
1680
- if (resource.allowSubtitles != null)
1681
- resourceJson.allowSubtitles = resource.allowSubtitles;
1682
- if (resource.showSubtitles != null)
1683
- resourceJson.showSubtitles = resource.showSubtitles;
1684
- if (resource.alt != null)
1685
- resourceJson.alt = Breakscape_1.Breakscape.unbreakscape(resource.alt);
1686
- if (resource.posterImage != null)
1687
- resourceJson.posterImage = this.addImageResource(bitType, resource.posterImage);
1688
- if (resource.thumbnails != null && resource.thumbnails.length > 0) {
1689
- resourceJson.thumbnails = [];
1690
- for (const thumbnail of resource.thumbnails) {
1691
- resourceJson.thumbnails.push(this.addImageResource(bitType, thumbnail));
1692
- }
728
+ // Ignore items not at the nodeType level
729
+ if (parentNodeTypes) {
730
+ const nodeTypeArray = Array.isArray(parentNodeTypes) ? parentNodeTypes : [parentNodeTypes];
731
+ const parent = this.getParentNode(route);
732
+ if (!(parent === null || parent === void 0 ? void 0 : parent.key) || !nodeTypeArray.includes(parent === null || parent === void 0 ? void 0 : parent.key))
733
+ return true;
1693
734
  }
1694
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1695
- return resourceJson;
735
+ // Add the property
736
+ this.addProperty(this.bitJson, (_a = options.keyOverride) !== null && _a !== void 0 ? _a : node.key, (_b = options.valueOverride) !== null && _b !== void 0 ? _b : node.value, options);
737
+ // Stop traversal of this branch
738
+ return false;
1696
739
  }
1697
- addStillImageFilmEmbedResource(bitType, resource) {
1698
- var _a, _b;
1699
- const resourceJson = {};
1700
- if (resource.format != null)
1701
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1702
- if (resource.provider != null)
1703
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1704
- if (resource.value != null)
1705
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1706
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1707
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1708
- if (resource.duration != null)
1709
- resourceJson.duration = resource.duration;
1710
- if (resource.mute != null)
1711
- resourceJson.mute = resource.mute;
1712
- if (resource.autoplay != null)
1713
- resourceJson.autoplay = resource.autoplay;
1714
- if (resource.allowSubtitles != null)
1715
- resourceJson.allowSubtitles = resource.allowSubtitles;
1716
- if (resource.showSubtitles != null)
1717
- resourceJson.showSubtitles = resource.showSubtitles;
1718
- if (resource.alt != null)
1719
- resourceJson.alt = Breakscape_1.Breakscape.unbreakscape(resource.alt);
1720
- if (resource.posterImage != null)
1721
- resourceJson.posterImage = this.addImageResource(bitType, resource.posterImage);
1722
- if (resource.thumbnails != null && resource.thumbnails.length > 0) {
1723
- resourceJson.thumbnails = [];
1724
- for (const thumbnail of resource.thumbnails) {
1725
- resourceJson.thumbnails.push(this.addImageResource(bitType, thumbnail));
740
+ addProperty(
741
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
742
+ target, name, values, options) {
743
+ if (values !== undefined) {
744
+ let finalValue;
745
+ if (!Array.isArray(values))
746
+ values = [values];
747
+ const valuesArr = values;
748
+ // if (valuesArr.length > 0) {
749
+ if (!options.array && valuesArr.length >= 1) {
750
+ finalValue = valuesArr[valuesArr.length - 1];
1726
751
  }
1727
- }
1728
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1729
- return resourceJson;
1730
- }
1731
- addStillImageFilmLinkResource(bitType, resource) {
1732
- var _a, _b;
1733
- const resourceJson = {};
1734
- if (resource.format != null)
1735
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1736
- if (resource.provider != null)
1737
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1738
- if (resource.value != null)
1739
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1740
- resourceJson.width = (_a = resource.width) !== null && _a !== void 0 ? _a : null;
1741
- resourceJson.height = (_b = resource.height) !== null && _b !== void 0 ? _b : null;
1742
- if (resource.duration != null)
1743
- resourceJson.duration = resource.duration;
1744
- if (resource.mute != null)
1745
- resourceJson.mute = resource.mute;
1746
- if (resource.autoplay != null)
1747
- resourceJson.autoplay = resource.autoplay;
1748
- if (resource.allowSubtitles != null)
1749
- resourceJson.allowSubtitles = resource.allowSubtitles;
1750
- if (resource.showSubtitles != null)
1751
- resourceJson.showSubtitles = resource.showSubtitles;
1752
- if (resource.alt != null)
1753
- resourceJson.alt = Breakscape_1.Breakscape.unbreakscape(resource.alt);
1754
- if (resource.posterImage != null)
1755
- resourceJson.posterImage = this.addImageResource(bitType, resource.posterImage);
1756
- if (resource.thumbnails != null && resource.thumbnails.length > 0) {
1757
- resourceJson.thumbnails = [];
1758
- for (const thumbnail of resource.thumbnails) {
1759
- resourceJson.thumbnails.push(this.addImageResource(bitType, thumbnail));
752
+ else {
753
+ finalValue = valuesArr;
1760
754
  }
1761
- }
1762
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1763
- return resourceJson;
1764
- }
1765
- addArticleResource(bitType, resource) {
1766
- const resourceJson = {};
1767
- if (resource.format != null)
1768
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1769
- if (resource.provider != null)
1770
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1771
- if (resource.value != null)
1772
- resourceJson.body = Breakscape_1.Breakscape.unbreakscape(resource.value);
1773
- // if (resource.href != null) resourceJson.href = BreakscapeUtils.unbreakscape(resource.href); // It is never used (and doesn't exist in the AST model)
1774
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1775
- return resourceJson;
1776
- }
1777
- addDocumentResource(bitType, resource) {
1778
- const resourceJson = {};
1779
- if (resource.format != null)
1780
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1781
- if (resource.provider != null)
1782
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1783
- if (resource.value != null)
1784
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1785
- // if (resource.href != null) resourceJson.href = BreakscapeUtils.unbreakscape(resource.href); // It is never used (and doesn't exist in the AST model)
1786
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1787
- return resourceJson;
1788
- }
1789
- addDocumentEmbedResource(bitType, resource) {
1790
- const resourceJson = {};
1791
- if (resource.format != null)
1792
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1793
- if (resource.provider != null)
1794
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1795
- if (resource.value != null)
1796
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1797
- // if (resource.href != null) resourceJson.href = BreakscapeUtils.unbreakscape(resource.href); // It is never used (and doesn't exist in the AST model)
1798
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1799
- return resourceJson;
1800
- }
1801
- addDocumentLinkResource(bitType, resource) {
1802
- const resourceJson = {};
1803
- if (resource.format != null)
1804
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1805
- if (resource.provider != null)
1806
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1807
- if (resource.value != null)
1808
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1809
- // if (resource.href != null) resourceJson.href = BreakscapeUtils.unbreakscape(resource.href); // It is never used (and doesn't exist in the AST model)
1810
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1811
- return resourceJson;
1812
- }
1813
- addDocumentDownloadResource(bitType, resource) {
1814
- const resourceJson = {};
1815
- if (resource.format != null)
1816
- resourceJson.format = Breakscape_1.Breakscape.unbreakscape(resource.format);
1817
- if (resource.provider != null)
1818
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1819
- if (resource.value != null)
1820
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1821
- // if (resource.href != null) resourceJson.href = resource.href; // It is never used (and doesn't exist in the AST model)
1822
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1823
- return resourceJson;
1824
- }
1825
- addAppLinkResource(bitType, resource) {
1826
- const resourceJson = {};
1827
- // if (resource.format != null) resourceJson.format = BreakscapeUtils.unbreakscape(resource.format);
1828
- if (resource.value != null)
1829
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1830
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1831
- return resourceJson;
1832
- }
1833
- addWebsiteLinkResource(bitType, resource) {
1834
- const resourceJson = {};
1835
- // if (resource.format != null) resourceJson.format = BreakscapeUtils.unbreakscape(resource.format);
1836
- if (resource.value != null)
1837
- resourceJson.url = Breakscape_1.Breakscape.unbreakscape(resource.value);
1838
- if (resource.siteName != null)
1839
- resourceJson.siteName = Breakscape_1.Breakscape.unbreakscape(resource.siteName);
1840
- this.addGenericResourceProperties(bitType, resource, resourceJson);
1841
- return resourceJson;
1842
- }
1843
- addGenericResourceProperties(_bitType, resource, resourceJson, noDefaults) {
1844
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1845
- if (noDefaults) {
1846
- if (resource.license != null)
1847
- resourceJson.license = (_a = Breakscape_1.Breakscape.unbreakscape(resource.license)) !== null && _a !== void 0 ? _a : '';
1848
- if (resource.copyright != null)
1849
- resourceJson.copyright = (_b = Breakscape_1.Breakscape.unbreakscape(resource.copyright)) !== null && _b !== void 0 ? _b : '';
1850
- if (resource.provider != null)
1851
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1852
- if (resource.showInIndex != null)
1853
- resourceJson.showInIndex = (_c = resource.showInIndex) !== null && _c !== void 0 ? _c : false;
1854
- if (resource.caption != null) {
1855
- resourceJson.caption = this.convertBreakscapedStringToJsonText((_d = resource.caption) !== null && _d !== void 0 ? _d : '', TextFormat_1.TextFormat.bitmarkMinusMinus);
755
+ // }
756
+ if (options.allowNull || finalValue != null) {
757
+ target[name] = finalValue;
1856
758
  }
1857
- if (resource.search != null)
1858
- resourceJson.search = (_e = Breakscape_1.Breakscape.unbreakscape(resource.search)) !== null && _e !== void 0 ? _e : '';
1859
759
  }
1860
- else {
1861
- resourceJson.license = (_f = Breakscape_1.Breakscape.unbreakscape(resource.license)) !== null && _f !== void 0 ? _f : '';
1862
- resourceJson.copyright = (_g = Breakscape_1.Breakscape.unbreakscape(resource.copyright)) !== null && _g !== void 0 ? _g : '';
1863
- if (resource.provider != null)
1864
- resourceJson.provider = Breakscape_1.Breakscape.unbreakscape(resource.provider);
1865
- resourceJson.showInIndex = (_h = resource.showInIndex) !== null && _h !== void 0 ? _h : false;
1866
- resourceJson.caption = this.convertBreakscapedStringToJsonText((_j = resource.caption) !== null && _j !== void 0 ? _j : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus);
1867
- if (resource.search != null)
1868
- resourceJson.search = (_k = Breakscape_1.Breakscape.unbreakscape(resource.search)) !== null && _k !== void 0 ? _k : '';
1869
- }
1870
- return resourceJson;
1871
- }
1872
- toItemLeadHintInstruction(item) {
1873
- var _a, _b, _c, _d, _e, _f;
1874
- return {
1875
- item: this.convertBreakscapedStringToJsonText((_b = (_a = item.itemLead) === null || _a === void 0 ? void 0 : _a.item) !== null && _b !== void 0 ? _b : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus),
1876
- lead: this.convertBreakscapedStringToJsonText((_d = (_c = item.itemLead) === null || _c === void 0 ? void 0 : _c.lead) !== null && _d !== void 0 ? _d : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus),
1877
- hint: this.convertBreakscapedStringToJsonText((_e = item.hint) !== null && _e !== void 0 ? _e : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus),
1878
- instruction: this.convertBreakscapedStringToJsonText((_f = item.instruction) !== null && _f !== void 0 ? _f : Breakscape_1.Breakscape.EMPTY_STRING, TextFormat_1.TextFormat.bitmarkMinusMinus),
1879
- };
1880
760
  }
1881
761
  toExample(node, options) {
1882
- const { isExample, example, isDefaultExample } = node;
762
+ const { isExample, example, __isDefaultExample } = node;
1883
763
  const { defaultExample, isBoolean } = options;
1884
764
  if (!isExample) {
1885
765
  return {
@@ -1888,7 +768,7 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1888
768
  };
1889
769
  }
1890
770
  let exampleValue;
1891
- if (isDefaultExample) {
771
+ if (__isDefaultExample) {
1892
772
  exampleValue = isBoolean
1893
773
  ? BooleanUtils_1.BooleanUtils.toBoolean(defaultExample)
1894
774
  : this.convertBreakscapedStringToJsonText(defaultExample, TextFormat_1.TextFormat.bitmarkMinusMinus);
@@ -1903,53 +783,6 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
1903
783
  example: exampleValue,
1904
784
  };
1905
785
  }
1906
- addProperty(
1907
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1908
- target, name, values, singleWithoutArray) {
1909
- if (values !== undefined) {
1910
- let finalValue;
1911
- if (!Array.isArray(values))
1912
- values = [values];
1913
- if (Array.isArray(values) && values.length > 0) {
1914
- // Unbreakscape values that are strings
1915
- values = Breakscape_1.Breakscape.unbreakscape(values);
1916
- if (Array.isArray(values) && singleWithoutArray && values.length >= 1) {
1917
- finalValue = values[values.length - 1];
1918
- }
1919
- else {
1920
- finalValue = values;
1921
- }
1922
- }
1923
- // if (finalValue != null) {
1924
- target[name] = finalValue;
1925
- // }
1926
- }
1927
- }
1928
- //
1929
- // Helper functions
1930
- //
1931
- /**
1932
- * Get the value for the zoomDisabled property, setting the appropriate default value if no value is set.
1933
- *
1934
- * @param bitType
1935
- * @param zoomDisabled
1936
- * @returns
1937
- */
1938
- getZoomDisabled(bitType, zoomDisabled) {
1939
- if (zoomDisabled != null)
1940
- return zoomDisabled;
1941
- // The default value in the JSON is hardcoded, because there is currently no good way to set a different
1942
- // default per bit in the BitConfig.
1943
- if (Config_1.Config.isOfBitType(bitType, [
1944
- BitType_1.BitType.imageSeparator,
1945
- BitType_1.BitType.pageBanner,
1946
- BitType_1.BitType.imagesLogoGrave,
1947
- BitType_1.BitType.prototypeImages,
1948
- ])) {
1949
- return true;
1950
- }
1951
- return false;
1952
- }
1953
786
  /**
1954
787
  * Get the bit type from any node
1955
788
  *
@@ -2039,13 +872,11 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2039
872
  const isBitmarkText = format === TextFormat_1.TextFormat.bitmarkMinusMinus || format === TextFormat_1.TextFormat.bitmarkPlusPlus;
2040
873
  if (!isBitmarkText) {
2041
874
  // Not bitmark text, so plain text, so unbreakscape only the start of bit tags
2042
- return (Breakscape_1.Breakscape.unbreakscape(text, {
2043
- bitTagOnly: true,
2044
- }) || Breakscape_1.Breakscape.EMPTY_STRING);
875
+ return text || '';
2045
876
  }
2046
877
  const asPlainText = this.options.textAsPlainText;
2047
878
  if (asPlainText) {
2048
- return Breakscape_1.Breakscape.unbreakscape(text) || Breakscape_1.Breakscape.EMPTY_STRING;
879
+ return text || '';
2049
880
  }
2050
881
  // Use the text parser to parse the text
2051
882
  const textAst = this.textParser.toAst(text, {
@@ -2105,40 +936,22 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2105
936
  return `${text !== null && text !== void 0 ? text : ''}${'\n'.repeat(extraBreaks)}${textPlain !== null && textPlain !== void 0 ? textPlain : ''}`;
2106
937
  }
2107
938
  /**
2108
- * Walk the body AST to find the placeholder and replace it with the body bit.
939
+ * Check if an object is bitmark text
940
+ * The check looks for a special tag on the array (__tag: 'text')
2109
941
  *
2110
- * @param bodyAst the body AST
2111
- * @param bodyBitJson the body bit json to insert at the placeholder position
2112
- * @param index the index of the placeholder to replace
942
+ * @param obj object that might be bitmark text
943
+ * @returns
2113
944
  */
2114
- replacePlaceholderWithBodyBit(bodyAst, bodyBitJson, index) {
2115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2116
- const walkRecursive = (node, parent, parentKey) => {
2117
- if (Array.isArray(node)) {
2118
- // Walk the array of nodes
2119
- for (let i = 0; i < node.length; i++) {
2120
- const child = node[i];
2121
- const done = walkRecursive(child, node, i);
2122
- if (done)
2123
- return true;
2124
- }
2125
- }
2126
- else {
2127
- if (node.type === 'bit' && node.index === index) {
2128
- // Found the placeholder, replace it with the body bit
2129
- parent[parentKey] = bodyBitJson;
2130
- return true;
2131
- }
2132
- if (node.content) {
2133
- // Walk the child content
2134
- const done = walkRecursive(node.content, node, 'content');
2135
- if (done)
2136
- return true;
2137
- }
2138
- }
945
+ isBitmarkText(obj) {
946
+ if (obj == null)
2139
947
  return false;
2140
- };
2141
- walkRecursive(bodyAst, null, null);
948
+ if (!Array.isArray(obj))
949
+ return false;
950
+ // Check for the hidden text tag
951
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
952
+ if (obj.__tag === 'text')
953
+ return true;
954
+ return false;
2142
955
  }
2143
956
  //
2144
957
  // WRITE FUNCTIONS
@@ -2173,211 +986,23 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2173
986
  originalType: bit.isCommented ? bit.bitType : undefined,
2174
987
  format: bit.textFormat,
2175
988
  bitLevel: bit.bitLevel,
2176
- // Properties
2177
- id: undefined,
2178
- internalComment: undefined,
2179
- externalId: undefined,
2180
- spaceId: undefined,
2181
- padletId: undefined,
2182
- jupyterId: undefined,
2183
- jupyterExecutionCount: undefined,
2184
- isPublic: undefined,
2185
- aiGenerated: undefined,
2186
- machineTranslated: undefined,
2187
- analyticsTag: undefined,
2188
- feedbackEngine: undefined,
2189
- feedbackType: undefined,
2190
- disableFeedback: undefined,
2191
- releaseVersion: undefined,
2192
- releaseKind: undefined,
2193
- releaseDate: undefined,
2194
- book: undefined,
2195
- ageRange: undefined,
2196
- lang: undefined,
2197
- language: undefined,
2198
- publisher: undefined,
2199
- publisherName: undefined,
2200
- theme: undefined,
2201
- computerLanguage: undefined,
2202
- target: undefined,
2203
- slug: undefined,
2204
- tag: undefined,
2205
- reductionTag: undefined,
2206
- bubbleTag: undefined,
2207
- levelCEFRp: undefined,
2208
- levelCEFR: undefined,
2209
- levelILR: undefined,
2210
- levelACTFL: undefined,
2211
- icon: undefined,
2212
- iconTag: undefined,
2213
- colorTag: undefined,
2214
- flashcardSet: undefined,
2215
- subtype: undefined,
2216
- bookAlias: undefined,
2217
- coverImage: undefined,
2218
- coverColor: undefined,
2219
- publications: undefined,
2220
- author: undefined,
2221
- subject: undefined,
2222
- date: undefined,
2223
- dateEnd: undefined,
2224
- location: undefined,
2225
- kind: undefined,
2226
- hasMarkAsDone: undefined,
2227
- processHandIn: undefined,
2228
- action: undefined,
2229
- showInIndex: undefined,
2230
- blockId: undefined,
2231
- pageNo: undefined,
2232
- x: undefined,
2233
- y: undefined,
2234
- width: undefined,
2235
- height: undefined,
2236
- index: undefined,
2237
- classification: undefined,
2238
- availableClassifications: undefined,
2239
- allowedBit: undefined,
2240
- tableFixedHeader: undefined,
2241
- tableSearch: undefined,
2242
- tableSort: undefined,
2243
- tablePagination: undefined,
2244
- tablePaginationLimit: undefined,
2245
- tableHeight: undefined,
2246
- tableWhitespaceNoWrap: undefined,
2247
- tableAutoWidth: undefined,
2248
- tableResizableColumns: undefined,
2249
- quizCountItems: undefined,
2250
- quizStrikethroughSolutions: undefined,
2251
- codeLineNumbers: undefined,
2252
- codeMinimap: undefined,
2253
- stripePricingTableId: undefined,
2254
- stripePublishableKey: undefined,
2255
- thumbImage: undefined,
2256
- scormSource: undefined,
2257
- posterImage: undefined,
2258
- focusX: undefined,
2259
- focusY: undefined,
2260
- pointerLeft: undefined,
2261
- pointerTop: undefined,
2262
- listItemIndent: undefined,
2263
- backgroundWallpaper: undefined,
2264
- hasBookNavigation: undefined,
2265
- duration: undefined,
2266
- deeplink: undefined,
2267
- externalLink: undefined,
2268
- externalLinkText: undefined,
2269
- videoCallLink: undefined,
2270
- vendorUrl: undefined,
2271
- search: undefined,
2272
- list: undefined,
2273
- textReference: undefined,
2274
- isTracked: undefined,
2275
- isInfoOnly: undefined,
2276
- imageFirst: undefined,
2277
- activityType: undefined,
2278
- labelTrue: undefined,
2279
- labelFalse: undefined,
2280
- content2Buy: undefined,
2281
- mailingList: undefined,
2282
- buttonCaption: undefined,
2283
- callToActionUrl: undefined,
2284
- caption: undefined,
2285
- quotedPerson: undefined,
2286
- reasonableNumOfChars: undefined,
2287
- resolved: undefined,
2288
- resolvedDate: undefined,
2289
- resolvedBy: undefined,
2290
- maxCreatedBits: undefined,
2291
- maxDisplayLevel: undefined,
2292
- page: undefined,
2293
- productId: undefined,
2294
- product: undefined,
2295
- productVideo: undefined,
2296
- productFolder: undefined,
2297
- technicalTerm: undefined,
2298
- servings: undefined,
2299
- ratingLevelStart: undefined,
2300
- ratingLevelEnd: undefined,
2301
- ratingLevelSelected: undefined,
2302
- // Book data
2303
- title: undefined,
2304
- subtitle: undefined,
2305
- level: undefined,
2306
- toc: undefined,
2307
- progress: undefined,
2308
- anchor: undefined,
2309
- reference: undefined,
2310
- referenceEnd: undefined,
2311
- // Item, Lead, Hint, Instruction
2312
- item: undefined,
2313
- lead: undefined,
2314
- pageNumber: undefined,
2315
- marginNumber: undefined,
2316
- hint: undefined,
2317
- instruction: undefined,
2318
- // Example
2319
- isExample: undefined,
2320
- example: undefined,
2321
- // Person .conversion-xxx, page-person, etc
2322
- person: undefined,
2323
- // Marks (config)
2324
- marks: undefined,
2325
- // Extra Properties
2326
- extraProperties: undefined,
2327
- // Body
2328
- body: undefined,
2329
- // Resource
2330
- imagePlaceholder: undefined,
2331
- resource: undefined,
2332
- logos: undefined,
2333
- images: undefined,
2334
- // Children
2335
- statement: undefined,
2336
- isCorrect: undefined,
2337
- sampleSolution: undefined,
2338
- additionalSolutions: undefined,
2339
- partialAnswer: undefined,
2340
- elements: undefined,
2341
- cards: undefined,
2342
- definitions: undefined,
2343
- statements: undefined,
2344
- responses: undefined,
2345
- quizzes: undefined,
2346
- heading: undefined,
2347
- pairs: undefined,
2348
- matrix: undefined,
2349
- choices: undefined,
2350
- questions: undefined,
2351
- captionDefinitionList: undefined,
2352
- listItems: undefined,
2353
- sections: undefined,
2354
- // Placeholders
2355
- placeholders: undefined,
2356
- // Footer
2357
- footer: undefined,
2358
989
  };
2359
- // Add the resource template if there should be a resource (indicated by resourceType) but there is none defined.
2360
- // if (bit.resourceType && !bitJson.resource) {
2361
- // const jsonKey = ResourceTag.keyFromValue(bit.resourceType);
2362
- // bitJson.resource = {
2363
- // type: bit.resourceType,
2364
- // } as ResourceJson;
2365
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
2366
- // if (jsonKey) (bitJson.resource as any)[jsonKey] = {};
2367
- // }
2368
990
  return bitJson;
2369
991
  }
2370
992
  /**
2371
993
  * Remove wanted properties from bit json object.
2372
994
  * - This function defines the defaults for properties in the json.
2373
995
  *
996
+ * TODO: All these defaults should come from the config and be set in the Builder.
997
+ *
2374
998
  * @param bit
2375
999
  * @returns
2376
1000
  */
2377
- cleanAndSetDefaultsForBitJson(bitJson) {
1001
+ cleanBitJson(bitJson) {
1002
+ var _a, _b, _c, _d, _e, _f;
2378
1003
  const bitType = Config_1.Config.getBitType(bitJson.type);
2379
- const textFormat = bitJson.format;
2380
- const plainText = this.options.textAsPlainText;
1004
+ // const textFormat = bitJson.format;
1005
+ // const plainText = this.options.textAsPlainText;
2381
1006
  // Clear 'originalType' if not set
2382
1007
  if (bitJson.originalType == null)
2383
1008
  bitJson.originalType = undefined;
@@ -2391,8 +1016,14 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2391
1016
  // The properties used are a bit random sometimes?
2392
1017
  // It would be better if this functionality was generated from the bit config
2393
1018
  if (Config_1.Config.isOfBitType(bitType, [BitType_1.BitType._error, BitType_1.BitType._comment])) {
2394
- // Special caes for _error and _comment bits
1019
+ // Special case for _error and _comment bits
2395
1020
  delete bitJson.format;
1021
+ delete bitJson.item;
1022
+ delete bitJson.lead;
1023
+ delete bitJson.pageNumber;
1024
+ delete bitJson.marginNumber;
1025
+ delete bitJson.hint;
1026
+ delete bitJson.instruction;
2396
1027
  //
2397
1028
  }
2398
1029
  else {
@@ -2401,6 +1032,18 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2401
1032
  // Most bits have these defaults, but there are special cases (not sure if that is by error or design)
2402
1033
  if (Config_1.Config.isOfBitType(bitType, [BitType_1.BitType.page])) {
2403
1034
  // Bits without item, lead, etc
1035
+ if (bitJson.item == null || ((_a = bitJson.item) === null || _a === void 0 ? void 0 : _a.length) === 0)
1036
+ delete bitJson.item;
1037
+ if (bitJson.lead == null || ((_b = bitJson.lead) === null || _b === void 0 ? void 0 : _b.length) === 0)
1038
+ delete bitJson.lead;
1039
+ if (bitJson.pageNumber == null || ((_c = bitJson.pageNumber) === null || _c === void 0 ? void 0 : _c.length) === 0)
1040
+ delete bitJson.pageNumber;
1041
+ if (bitJson.marginNumber == null || ((_d = bitJson.marginNumber) === null || _d === void 0 ? void 0 : _d.length) === 0)
1042
+ delete bitJson.marginNumber;
1043
+ if (bitJson.hint == null || ((_e = bitJson.hint) === null || _e === void 0 ? void 0 : _e.length) === 0)
1044
+ delete bitJson.hint;
1045
+ if (bitJson.instruction == null || ((_f = bitJson.instruction) === null || _f === void 0 ? void 0 : _f.length) === 0)
1046
+ delete bitJson.instruction;
2404
1047
  }
2405
1048
  else {
2406
1049
  // Majority of bits
@@ -2568,6 +1211,8 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2568
1211
  bitJson.tableAutoWidth = true;
2569
1212
  if (bitJson.tableResizableColumns == null)
2570
1213
  bitJson.tableResizableColumns = false;
1214
+ if (bitJson.tableColumnMinWidth == null)
1215
+ bitJson.tableColumnMinWidth = 0;
2571
1216
  //
2572
1217
  }
2573
1218
  if (Config_1.Config.isOfBitType(bitType, [
@@ -2708,361 +1353,42 @@ class JsonGenerator extends AstWalkerGenerator_1.AstWalkerGenerator {
2708
1353
  delete bitJson.example;
2709
1354
  }
2710
1355
  }
2711
- // Remove unwanted properties
2712
- // Properties
2713
- if (bitJson.id == null)
2714
- delete bitJson.id;
2715
- if (bitJson.internalComment == null)
2716
- delete bitJson.internalComment;
2717
- if (bitJson.externalId == null)
2718
- delete bitJson.externalId;
2719
- if (bitJson.spaceId == null)
2720
- delete bitJson.spaceId;
2721
- if (bitJson.padletId == null)
2722
- delete bitJson.padletId;
2723
- if (bitJson.jupyterId == null)
2724
- delete bitJson.jupyterId;
2725
- if (bitJson.jupyterExecutionCount == null)
2726
- delete bitJson.jupyterExecutionCount;
2727
- if (bitJson.isPublic == null)
2728
- delete bitJson.isPublic;
2729
- if (bitJson.aiGenerated == null)
2730
- delete bitJson.aiGenerated;
2731
- if (bitJson.machineTranslated == null)
2732
- delete bitJson.machineTranslated;
2733
- if (bitJson.analyticsTag == null)
2734
- delete bitJson.analyticsTag;
2735
- if (bitJson.feedbackEngine == null)
2736
- delete bitJson.feedbackEngine;
2737
- if (bitJson.feedbackType == null)
2738
- delete bitJson.feedbackType;
2739
- if (bitJson.disableFeedback == null)
2740
- delete bitJson.disableFeedback;
2741
- if (bitJson.releaseVersion == null)
2742
- delete bitJson.releaseVersion;
2743
- if (bitJson.releaseKind == null)
2744
- delete bitJson.releaseKind;
2745
- if (bitJson.releaseDate == null)
2746
- delete bitJson.releaseDate;
2747
- if (bitJson.book == null)
2748
- delete bitJson.book;
2749
- if (bitJson.ageRange == null)
2750
- delete bitJson.ageRange;
2751
- if (bitJson.lang == null)
2752
- delete bitJson.lang;
2753
- if (bitJson.language == null)
2754
- delete bitJson.language;
2755
- if (bitJson.publisher == null)
2756
- delete bitJson.publisher;
2757
- if (bitJson.publisherName == null)
2758
- delete bitJson.publisherName;
2759
- if (bitJson.theme == null)
2760
- delete bitJson.theme;
2761
- if (bitJson.computerLanguage == null)
2762
- delete bitJson.computerLanguage;
2763
- if (bitJson.target == null)
2764
- delete bitJson.target;
2765
- if (bitJson.slug == null)
2766
- delete bitJson.slug;
2767
- if (bitJson.tag == null)
2768
- delete bitJson.tag;
2769
- if (bitJson.reductionTag == null)
2770
- delete bitJson.reductionTag;
2771
- if (bitJson.bubbleTag == null)
2772
- delete bitJson.bubbleTag;
2773
- if (bitJson.levelCEFRp == null)
2774
- delete bitJson.levelCEFRp;
2775
- if (bitJson.levelCEFR == null)
2776
- delete bitJson.levelCEFR;
2777
- if (bitJson.levelILR == null)
2778
- delete bitJson.levelILR;
2779
- if (bitJson.levelACTFL == null)
2780
- delete bitJson.levelACTFL;
2781
- if (bitJson.icon == null)
2782
- delete bitJson.icon;
2783
- if (bitJson.iconTag == null)
2784
- delete bitJson.iconTag;
2785
- if (bitJson.colorTag == null)
2786
- delete bitJson.colorTag;
2787
- if (bitJson.flashcardSet == null)
2788
- delete bitJson.flashcardSet;
2789
- if (bitJson.subtype == null)
2790
- delete bitJson.subtype;
2791
- if (bitJson.bookAlias == null)
2792
- delete bitJson.bookAlias;
2793
- if (bitJson.coverImage == null)
2794
- delete bitJson.coverImage;
2795
- if (bitJson.coverColor == null)
2796
- delete bitJson.coverColor;
2797
- if (bitJson.publications == null)
2798
- delete bitJson.publications;
2799
- if (bitJson.author == null)
2800
- delete bitJson.author;
2801
- if (bitJson.subject == null)
2802
- delete bitJson.subject;
2803
- if (bitJson.date == null)
2804
- delete bitJson.date;
2805
- if (bitJson.dateEnd == null)
2806
- delete bitJson.dateEnd;
2807
- if (bitJson.location == null)
2808
- delete bitJson.location;
2809
- if (bitJson.kind == null)
2810
- delete bitJson.kind;
2811
- if (bitJson.hasMarkAsDone == null)
2812
- delete bitJson.hasMarkAsDone;
2813
- if (bitJson.processHandIn == null)
2814
- delete bitJson.processHandIn;
2815
- if (bitJson.action == null)
2816
- delete bitJson.action;
2817
- if (bitJson.showInIndex == null)
2818
- delete bitJson.showInIndex;
2819
- if (bitJson.blockId == null)
2820
- delete bitJson.blockId;
2821
- if (bitJson.pageNo == null)
2822
- delete bitJson.pageNo;
2823
- if (bitJson.x == null)
2824
- delete bitJson.x;
2825
- if (bitJson.y == null)
2826
- delete bitJson.y;
2827
- if (bitJson.width == null)
2828
- delete bitJson.width;
2829
- if (bitJson.height == null)
2830
- delete bitJson.height;
2831
- if (bitJson.index == null)
2832
- delete bitJson.index;
2833
- if (bitJson.classification == null)
2834
- delete bitJson.classification;
2835
- if (bitJson.availableClassifications == null)
2836
- delete bitJson.availableClassifications;
2837
- if (bitJson.allowedBit == null)
2838
- delete bitJson.allowedBit;
2839
- if (bitJson.tableFixedHeader == null)
2840
- delete bitJson.tableFixedHeader;
2841
- if (bitJson.tableSearch == null)
2842
- delete bitJson.tableSearch;
2843
- if (bitJson.tableSort == null)
2844
- delete bitJson.tableSort;
2845
- if (bitJson.tablePagination == null)
2846
- delete bitJson.tablePagination;
2847
- if (bitJson.tablePaginationLimit == null)
2848
- delete bitJson.tablePaginationLimit;
2849
- if (bitJson.tableHeight == null)
2850
- delete bitJson.tableHeight;
2851
- if (bitJson.tableWhitespaceNoWrap == null)
2852
- delete bitJson.tableWhitespaceNoWrap;
2853
- if (bitJson.tableAutoWidth == null)
2854
- delete bitJson.tableAutoWidth;
2855
- if (bitJson.tableResizableColumns == null)
2856
- delete bitJson.tableResizableColumns;
2857
- if (bitJson.quizCountItems == null)
2858
- delete bitJson.quizCountItems;
2859
- if (bitJson.quizStrikethroughSolutions == null)
2860
- delete bitJson.quizStrikethroughSolutions;
2861
- if (bitJson.codeLineNumbers == null)
2862
- delete bitJson.codeLineNumbers;
2863
- if (bitJson.codeMinimap == null)
2864
- delete bitJson.codeMinimap;
2865
- if (bitJson.stripePricingTableId == null)
2866
- delete bitJson.stripePricingTableId;
2867
- if (bitJson.stripePublishableKey == null)
2868
- delete bitJson.stripePublishableKey;
2869
- if (bitJson.thumbImage == null)
2870
- delete bitJson.thumbImage;
2871
- if (bitJson.scormSource == null)
2872
- delete bitJson.scormSource;
2873
- if (bitJson.posterImage == null)
2874
- delete bitJson.posterImage;
2875
- if (bitJson.focusX == null)
2876
- delete bitJson.focusX;
2877
- if (bitJson.focusY == null)
2878
- delete bitJson.focusY;
2879
- if (bitJson.pointerLeft == null)
2880
- delete bitJson.pointerLeft;
2881
- if (bitJson.pointerTop == null)
2882
- delete bitJson.pointerTop;
2883
- if (bitJson.listItemIndent == null)
2884
- delete bitJson.listItemIndent;
2885
- if (bitJson.backgroundWallpaper == null)
2886
- delete bitJson.backgroundWallpaper;
2887
- if (bitJson.hasBookNavigation == null)
2888
- delete bitJson.hasBookNavigation;
2889
- if (bitJson.duration == null)
2890
- delete bitJson.duration;
2891
- if (bitJson.deeplink == null)
2892
- delete bitJson.deeplink;
2893
- if (bitJson.externalLink == null)
2894
- delete bitJson.externalLink;
2895
- if (bitJson.externalLinkText == null)
2896
- delete bitJson.externalLinkText;
2897
- if (bitJson.videoCallLink == null)
2898
- delete bitJson.videoCallLink;
2899
- if (bitJson.vendorUrl == null)
2900
- delete bitJson.vendorUrl;
2901
- if (bitJson.search == null)
2902
- delete bitJson.search;
2903
- if (bitJson.list == null)
2904
- delete bitJson.list;
2905
- if (bitJson.textReference == null)
2906
- delete bitJson.textReference;
2907
- if (bitJson.isTracked == null)
2908
- delete bitJson.isTracked;
2909
- if (bitJson.isInfoOnly == null)
2910
- delete bitJson.isInfoOnly;
2911
- if (bitJson.imageFirst == null)
2912
- delete bitJson.imageFirst;
2913
- if (bitJson.activityType == null)
2914
- delete bitJson.activityType;
2915
- if (bitJson.labelTrue == null)
2916
- delete bitJson.labelTrue;
2917
- if (bitJson.labelFalse == null)
2918
- delete bitJson.labelFalse;
2919
- if (bitJson.content2Buy == null)
2920
- delete bitJson.content2Buy;
2921
- if (bitJson.mailingList == null)
2922
- delete bitJson.mailingList;
2923
- if (bitJson.buttonCaption == null)
2924
- delete bitJson.buttonCaption;
2925
- if (bitJson.callToActionUrl == null)
2926
- delete bitJson.callToActionUrl;
2927
- if (bitJson.caption == null)
2928
- delete bitJson.caption;
2929
- if (bitJson.quotedPerson == null)
2930
- delete bitJson.quotedPerson;
2931
- if (bitJson.resolved == null)
2932
- delete bitJson.resolved;
2933
- if (bitJson.resolvedDate == null)
2934
- delete bitJson.resolvedDate;
2935
- if (bitJson.resolvedBy == null)
2936
- delete bitJson.resolvedBy;
2937
- if (bitJson.maxCreatedBits == null)
2938
- delete bitJson.maxCreatedBits;
2939
- if (bitJson.maxDisplayLevel == null)
2940
- delete bitJson.maxDisplayLevel;
2941
- if (bitJson.page == null)
2942
- delete bitJson.page;
2943
- if (bitJson.productId == null)
2944
- delete bitJson.productId;
2945
- if (bitJson.product == null)
2946
- delete bitJson.product;
2947
- if (bitJson.productVideo == null)
2948
- delete bitJson.productVideo;
2949
- if (bitJson.productFolder == null)
2950
- delete bitJson.productFolder;
2951
- if (bitJson.technicalTerm == null)
2952
- delete bitJson.technicalTerm;
2953
- if (bitJson.servings == null)
2954
- delete bitJson.servings;
2955
- if (bitJson.ratingLevelStart == null)
2956
- delete bitJson.ratingLevelStart;
2957
- if (bitJson.ratingLevelEnd == null)
2958
- delete bitJson.ratingLevelEnd;
2959
- if (bitJson.ratingLevelSelected == null)
2960
- delete bitJson.ratingLevelSelected;
2961
- // Book data
2962
- if (bitJson.title == null)
2963
- delete bitJson.title;
2964
- if (bitJson.subtitle == null)
2965
- delete bitJson.subtitle;
2966
- if (bitJson.level == null)
2967
- delete bitJson.level;
2968
- if (bitJson.toc == null)
2969
- delete bitJson.toc;
2970
- if (bitJson.progress == null)
2971
- delete bitJson.progress;
2972
- if (bitJson.anchor == null)
2973
- delete bitJson.anchor;
2974
- if (bitJson.reference == null)
2975
- delete bitJson.reference;
2976
- if (bitJson.referenceEnd == null)
2977
- delete bitJson.referenceEnd;
2978
- // Item, Lead, Hint, Instruction
2979
- if (bitJson.item == null)
2980
- delete bitJson.item;
2981
- if (bitJson.lead == null)
2982
- delete bitJson.lead;
2983
- if (bitJson.pageNumber == null)
2984
- delete bitJson.pageNumber;
2985
- if (bitJson.marginNumber == null)
2986
- delete bitJson.marginNumber;
2987
- if (bitJson.hint == null)
2988
- delete bitJson.hint;
2989
- if (bitJson.instruction == null)
2990
- delete bitJson.instruction;
2991
- // Example
2992
- if (bitJson.example === undefined)
2993
- delete bitJson.example;
2994
- if (bitJson.isExample == null)
2995
- delete bitJson.isExample;
2996
- // Mark
2997
- if (bitJson.marks == null)
2998
- delete bitJson.marks;
2999
- // Extra Properties
3000
- if (bitJson.extraProperties == null)
3001
- delete bitJson.extraProperties;
3002
- // Body
3003
- if (bitJson.body == null && textFormat !== TextFormat_1.TextFormat.json)
3004
- delete bitJson.body;
3005
- // Placeholders
3006
- if (bitJson.placeholders == null || Object.keys(bitJson.placeholders).length === 0)
3007
- delete bitJson.placeholders;
3008
- // Resource
3009
- if (bitJson.imagePlaceholder == null)
3010
- delete bitJson.imagePlaceholder;
3011
- if (bitJson.resource == null)
3012
- delete bitJson.resource;
3013
- if (bitJson.logos == null)
3014
- delete bitJson.logos;
3015
- if (bitJson.images == null)
3016
- delete bitJson.images;
3017
- // Children
3018
- if (bitJson.statement == null)
3019
- delete bitJson.statement;
3020
- if (bitJson.isCorrect == null)
3021
- delete bitJson.isCorrect;
3022
- if (bitJson.sampleSolution == null)
3023
- delete bitJson.sampleSolution;
3024
- if (bitJson.additionalSolutions == null)
3025
- delete bitJson.additionalSolutions;
3026
- if (bitJson.partialAnswer == null)
3027
- delete bitJson.partialAnswer;
3028
- if (bitJson.elements == null)
3029
- delete bitJson.elements;
3030
- if (bitJson.cards == null)
3031
- delete bitJson.cards;
3032
- if (bitJson.definitions == null)
3033
- delete bitJson.definitions;
3034
- if (bitJson.statements == null)
3035
- delete bitJson.statements;
3036
- if (bitJson.responses == null)
3037
- delete bitJson.responses;
3038
- if (bitJson.quizzes == null)
3039
- delete bitJson.quizzes;
3040
- if (bitJson.heading == null)
3041
- delete bitJson.heading;
3042
- if (bitJson.pairs == null)
3043
- delete bitJson.pairs;
3044
- if (bitJson.matrix == null)
3045
- delete bitJson.matrix;
3046
- if (bitJson.table == null)
3047
- delete bitJson.table;
3048
- if (bitJson.choices == null)
3049
- delete bitJson.choices;
3050
- if (bitJson.questions == null)
3051
- delete bitJson.questions;
3052
- if (bitJson.captionDefinitionList == null)
3053
- delete bitJson.captionDefinitionList;
3054
- if (bitJson.listItems == null)
3055
- delete bitJson.listItems;
3056
- if (bitJson.sections == null)
3057
- delete bitJson.sections;
3058
- // Placeholders
3059
- if (!plainText || bitJson.placeholders == null)
3060
- delete bitJson.placeholders;
3061
- // Footer
3062
- if (bitJson.footer == null)
3063
- delete bitJson.footer;
3064
1356
  return bitJson;
3065
1357
  }
1358
+ /**
1359
+ * Convert any bitmark texts to strings.
1360
+ */
1361
+ convertAllBitmarkTextsToStringsForPlainText(json) {
1362
+ if (!this.options.textAsPlainText)
1363
+ return;
1364
+ const obj = json;
1365
+ for (const key in obj) {
1366
+ const val = obj[key];
1367
+ if (this.isBitmarkText(val)) {
1368
+ const s = this.textGenerator.generateSync(val, TextFormat_1.TextFormat.bitmarkMinusMinus);
1369
+ obj[key] = (Breakscape_1.Breakscape.unbreakscape(s) || '').trim();
1370
+ }
1371
+ else if (typeof obj[key] === 'object') {
1372
+ this.convertAllBitmarkTextsToStringsForPlainText(obj[key]);
1373
+ }
1374
+ }
1375
+ }
1376
+ /**
1377
+ * Remove any property with a key starting with an double underscore.
1378
+ *
1379
+ * @param json
1380
+ */
1381
+ removeTemporaryProperties(json) {
1382
+ const obj = json;
1383
+ for (const key in obj) {
1384
+ if (key.startsWith('__')) {
1385
+ delete obj[key];
1386
+ }
1387
+ else if (typeof obj[key] === 'object') {
1388
+ this.removeTemporaryProperties(obj[key]);
1389
+ }
1390
+ }
1391
+ }
3066
1392
  //
3067
1393
  // Writer interface
3068
1394
  //