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