@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
@@ -1,24 +1,25 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { Builder } from '../../ast/Builder';
2
- import { ResourceBuilder } from '../../ast/ResourceBuilder';
3
- import { Breakscape } from '../../breakscaping/Breakscape';
4
13
  import { Config } from '../../config/Config';
5
- import { TextGenerator } from '../../generator/text/TextGenerator';
6
14
  import { BitType } from '../../model/enum/BitType';
7
- import { BodyBitType } from '../../model/enum/BodyBitType';
8
15
  import { ResourceTag } from '../../model/enum/ResourceTag';
9
16
  import { TextFormat } from '../../model/enum/TextFormat';
10
17
  import { StringUtils } from '../../utils/StringUtils';
11
- import { TextParser } from '../text/TextParser';
12
18
  const builder = new Builder();
13
- const resourceBuilder = new ResourceBuilder();
14
19
  /**
15
20
  * A parser for parsing bitmark JSON to bitmark AST
16
21
  */
17
22
  class JsonParser {
18
- constructor() {
19
- this.textGenerator = new TextGenerator();
20
- this.textParser = new TextParser();
21
- }
22
23
  /**
23
24
  * Convert JSON to AST.
24
25
  *
@@ -39,7 +40,7 @@ class JsonParser {
39
40
  }
40
41
  }
41
42
  const bits = bitsNodes.length > 0 ? { bits: bitsNodes } : {};
42
- const ast = builder.bitmark(bits);
43
+ const ast = builder.buildBitmark(bits);
43
44
  return ast;
44
45
  }
45
46
  /**
@@ -122,476 +123,63 @@ class JsonParser {
122
123
  };
123
124
  }
124
125
  bitToAst(bit, internalComments) {
125
- var _a;
126
- const { type, originalType, bitLevel, format, id, externalId, spaceId, padletId, jupyterId, jupyterExecutionCount, isPublic, aiGenerated, machineTranslated, analyticsTag, feedbackEngine, feedbackType, disableFeedback, releaseVersion, releaseKind, releaseDate, ageRange, lang, language, publisher, publisherName, theme, computerLanguage, target, slug, tag, reductionTag, bubbleTag, levelCEFRp, levelCEFR, levelILR, levelACTFL, icon, iconTag, colorTag, flashcardSet, subtype, bookAlias, coverImage, coverColor, publications, author, date, dateEnd, location, kind, hasMarkAsDone, processHandIn, showInIndex, blockId, pageNo, x, y, width, height, index, classification, availableClassifications, allowedBit, tableFixedHeader, tableSearch, tableSort, tablePagination, tablePaginationLimit, tableHeight, tableWhitespaceNoWrap, tableAutoWidth, tableResizableColumns, quizCountItems, quizStrikethroughSolutions, codeLineNumbers, codeMinimap, stripePricingTableId, stripePublishableKey, action, thumbImage, scormSource, posterImage, focusX, focusY, pointerLeft, pointerTop, listItemIndent, backgroundWallpaper, hasBookNavigation, duration, deeplink, externalLink, externalLinkText, videoCallLink, vendorUrl, search, bot, list, textReference, isTracked, isInfoOnly, imageFirst, activityType, labelTrue, labelFalse, content2Buy, mailingList, buttonCaption, callToActionUrl, caption, quotedPerson, partialAnswer, reasonableNumOfChars, sampleSolution, additionalSolutions, resolved, resolvedDate, resolvedBy, maxCreatedBits, maxDisplayLevel, page, productId, product, productVideo, productFolder, technicalTerm, servings, ratingLevelStart, ratingLevelEnd, ratingLevelSelected, book, title, subtitle, level, toc, progress, anchor, reference: referenceIn, referenceEnd, item, lead, pageNumber, marginNumber, hint, instruction, example, imageSource, person, partner, marks, imagePlaceholder, resource, logos, images, body, elements, statement, isCorrect, cards, definitions, descriptions, statements, responses, quizzes, heading, pairs, matrix, table, captionDefinitionList, choices, questions, ingredients, listItems, sections, footer, placeholders, } = bit;
127
- const isCommented = type === BitType._comment && originalType !== undefined;
126
+ var _a, _b, _c, _d;
127
+ const { statement, product, productVideo, reference: referenceBit } = bit, bitRest = __rest(bit, ["statement", "product", "productVideo", "reference"]);
128
+ const isCommented = bit.type === BitType._comment && bit.originalType !== undefined;
128
129
  // Bit type
129
- const bitType = Config.getBitType(isCommented ? originalType : type);
130
- // Bit level
131
- const bitLevelValidated = Math.max(Math.min(bitLevel !== null && bitLevel !== void 0 ? bitLevel : 1, Config.bitLevelMax), Config.bitLevelMin);
130
+ const bitType = Config.getBitType(isCommented ? bit.originalType : bit.type);
132
131
  // Get the bit config for the bit type
133
132
  const bitConfig = Config.getBitConfig(bitType);
134
133
  // Text Format
135
- const textFormat = (_a = TextFormat.fromValue(format)) !== null && _a !== void 0 ? _a : bitConfig.textFormatDefault;
136
- // Resource attachement type
137
- const resourceAttachmentType = this.getResourceType(resource);
138
- // resource(s)
139
- const resourcesNode = this.resourceBitToAst(bitType, resource, images !== null && images !== void 0 ? images : logos);
140
- // body & placeholders
141
- const bodyNode = this.bodyToAst(body, textFormat, placeholders);
142
- // imagePlaceholder
143
- const imagePlaceholderNode = this.imagePlaceholderBitToAst(imagePlaceholder);
144
- // imageSource
145
- const imageSourceNode = this.imageSourceBitToAst(imageSource);
146
- // Person (partner, deprecated)
147
- const personNode = this.personBitToAst(person !== null && person !== void 0 ? person : partner);
148
- // Mark Config
149
- const markConfigNode = this.markConfigBitToAst(marks);
150
- // flashcards
151
- const flashcardNodes = this.flashcardBitsToAst(cards);
152
- // definitions
153
- // descriptions are treated as alias for definitions
154
- const definitionNodes = Config.isOfBitType(bitType, BitType.descriptionList)
155
- ? this.descriptionsBitsToAst(descriptions)
156
- : this.definitionsBitsToAst(definitions);
157
- //+-statement
158
- const statementNodes = this.statementBitsToAst(statement, isCorrect, statements, example);
159
- //+-response
160
- const responseNodes = this.responseBitsToAst(bitType, responses);
161
- // quizzes
162
- const quizNodes = this.quizBitsToAst(bitType, quizzes);
163
- // heading
164
- const headingNode = this.headingBitToAst(heading);
165
- // pairs
166
- const pairsNodes = this.pairBitsToAst(pairs);
167
- // matrix
168
- const matrixNodes = this.matrixBitsToAst(matrix);
169
- // table / captionDefinitionList
170
- const tableNode = this.tableToAst(table);
171
- //+-choice
172
- const choiceNodes = this.choiceBitsToAst(choices);
173
- // questions
174
- const questionNodes = this.questionBitsToAst(questions);
175
- // botResponses
176
- const botResponseNodes = this.botResponseBitsToAst(bitType, responses);
177
- // technicalTerm
178
- const technicalTermNode = this.technicalTermToAst(technicalTerm);
179
- // servings
180
- const servingsNode = this.servingsToAst(servings);
181
- // ingredients
182
- const ingredientsNodes = this.ingredientsBitsToAst(ingredients);
183
- // ratingLevelStart
184
- const ratingLevelStartNodes = this.ratingLevelStartEndToAst(ratingLevelStart);
185
- // ratingLevelEnd
186
- const ratingLevelEndNodes = this.ratingLevelStartEndToAst(ratingLevelEnd);
187
- // captionDefinitionList
188
- const captionDefinitionListNode = this.captionDefinitionListToAst(captionDefinitionList);
189
- // listItems / sections (cardBits)
190
- const cardBitNodes = this.listItemsToAst(listItems !== null && listItems !== void 0 ? listItems : sections, textFormat, placeholders);
191
- // footer
192
- const footerNode = this.footerToAst(footer, textFormat);
193
- // Convert reference to referenceProperty
194
- const { reference, referenceProperty } = this.referenceToAst(referenceIn);
134
+ const textFormat = (_a = TextFormat.fromValue(bit.format)) !== null && _a !== void 0 ? _a : bitConfig.textFormatDefault;
135
+ textFormat; // Unused
195
136
  // Build bit
196
- const bitNode = builder.bit(Object.assign(Object.assign(Object.assign({ bitType, bitLevel: bitLevelValidated, textFormat: format, resourceType: resourceAttachmentType, isCommented, id: this.convertStringToBreakscapedString(id), internalComment: this.convertStringToBreakscapedString(internalComments), externalId: this.convertStringToBreakscapedString(externalId), spaceId: this.convertStringToBreakscapedString(spaceId), padletId: this.convertStringToBreakscapedString(padletId), jupyterId: this.convertStringToBreakscapedString(jupyterId), jupyterExecutionCount,
197
- isPublic,
198
- aiGenerated, machineTranslated: this.convertStringToBreakscapedString(machineTranslated), analyticsTag: this.convertStringToBreakscapedString(analyticsTag), feedbackEngine: this.convertStringToBreakscapedString(feedbackEngine), feedbackType: this.convertStringToBreakscapedString(feedbackType), disableFeedback, releaseVersion: this.convertStringToBreakscapedString(releaseVersion), releaseKind: this.convertStringToBreakscapedString(releaseKind), releaseDate: this.convertStringToBreakscapedString(releaseDate), ageRange, lang: this.convertStringToBreakscapedString(lang), language: this.convertStringToBreakscapedString(language), publisher: this.convertStringToBreakscapedString(publisher), publisherName: this.convertStringToBreakscapedString(publisherName), theme: this.convertStringToBreakscapedString(theme), computerLanguage: this.convertStringToBreakscapedString(computerLanguage), target: this.convertStringToBreakscapedString(target), slug: this.convertStringToBreakscapedString(slug), tag: this.convertStringToBreakscapedString(tag), reductionTag: this.convertStringToBreakscapedString(reductionTag), bubbleTag: this.convertStringToBreakscapedString(bubbleTag), levelCEFRp: this.convertStringToBreakscapedString(levelCEFRp), levelCEFR: this.convertStringToBreakscapedString(levelCEFR), levelILR: this.convertStringToBreakscapedString(levelILR), levelACTFL: this.convertStringToBreakscapedString(levelACTFL), icon: this.convertStringToBreakscapedString(icon), iconTag: this.convertStringToBreakscapedString(iconTag), colorTag: this.convertStringToBreakscapedString(colorTag), flashcardSet: this.convertStringToBreakscapedString(flashcardSet), subtype: this.convertStringToBreakscapedString(subtype), bookAlias: this.convertStringToBreakscapedString(bookAlias), coverImage: this.convertStringToBreakscapedString(coverImage), coverColor: this.convertStringToBreakscapedString(coverColor), publications: this.convertStringToBreakscapedString(publications), author: this.convertStringToBreakscapedString(author), date: this.convertStringToBreakscapedString(date), dateEnd: this.convertStringToBreakscapedString(dateEnd), location: this.convertStringToBreakscapedString(location), kind: this.convertStringToBreakscapedString(kind), hasMarkAsDone,
199
- processHandIn, action: this.convertStringToBreakscapedString(action), showInIndex, blockId: this.convertStringToBreakscapedString(blockId), pageNo,
200
- x,
201
- y,
202
- width,
203
- height,
204
- index, classification: this.convertStringToBreakscapedString(classification), availableClassifications: this.convertStringToBreakscapedString(availableClassifications), allowedBit: this.convertStringToBreakscapedString(allowedBit), tableFixedHeader,
205
- tableSearch,
206
- tableSort,
207
- tablePagination,
208
- tablePaginationLimit,
209
- tableHeight,
210
- tableWhitespaceNoWrap,
211
- tableAutoWidth,
212
- tableResizableColumns,
213
- quizCountItems,
214
- quizStrikethroughSolutions,
215
- codeLineNumbers,
216
- codeMinimap, stripePricingTableId: this.convertStringToBreakscapedString(stripePricingTableId), stripePublishableKey: this.convertStringToBreakscapedString(stripePublishableKey), duration: this.convertStringToBreakscapedString(duration), referenceProperty: this.convertStringToBreakscapedString(referenceProperty), thumbImage: this.convertStringToBreakscapedString(thumbImage), scormSource: this.convertStringToBreakscapedString(scormSource), posterImage: this.convertStringToBreakscapedString(posterImage), focusX,
217
- focusY, pointerLeft: this.convertStringToBreakscapedString(pointerLeft), pointerTop: this.convertStringToBreakscapedString(pointerTop), listItemIndent, backgroundWallpaper: this.convertStringToBreakscapedString(backgroundWallpaper), hasBookNavigation, deeplink: this.convertStringToBreakscapedString(deeplink), externalLink: this.convertStringToBreakscapedString(externalLink), externalLinkText: this.convertStringToBreakscapedString(externalLinkText), videoCallLink: this.convertStringToBreakscapedString(videoCallLink), vendorUrl: this.convertStringToBreakscapedString(vendorUrl), search: this.convertStringToBreakscapedString(search), bot: this.convertStringToBreakscapedString(bot), list: this.convertStringToBreakscapedString(list), textReference: this.convertStringToBreakscapedString(textReference), isTracked,
218
- isInfoOnly,
219
- imageFirst, activityType: this.convertStringToBreakscapedString(activityType), labelTrue: this.convertStringToBreakscapedString(labelTrue), labelFalse: this.convertStringToBreakscapedString(labelFalse), content2Buy: this.convertStringToBreakscapedString(content2Buy), mailingList: this.convertStringToBreakscapedString(mailingList), buttonCaption: this.convertStringToBreakscapedString(buttonCaption), callToActionUrl: this.convertStringToBreakscapedString(callToActionUrl), caption: this.convertJsonTextToBreakscapedString(caption), quotedPerson: this.convertStringToBreakscapedString(quotedPerson), partialAnswer: this.convertStringToBreakscapedString(partialAnswer), reasonableNumOfChars, sampleSolution: this.convertStringToBreakscapedString(sampleSolution), additionalSolutions: this.convertStringToBreakscapedString(additionalSolutions), resolved, resolvedDate: this.convertStringToBreakscapedString(resolvedDate), resolvedBy: this.convertStringToBreakscapedString(resolvedBy), maxCreatedBits,
220
- maxDisplayLevel, page: this.convertStringToBreakscapedString(page), productId: this.convertStringToBreakscapedString(productId), productList: this.convertStringToBreakscapedString(product), productVideoList: this.convertStringToBreakscapedString(productVideo), productFolder: this.convertStringToBreakscapedString(productFolder), technicalTerm: technicalTermNode, servings: servingsNode, ratingLevelStart: ratingLevelStartNodes, ratingLevelEnd: ratingLevelEndNodes, ratingLevelSelected, book: this.convertStringToBreakscapedString(book), title: this.convertJsonTextToBreakscapedString(title), subtitle: this.convertJsonTextToBreakscapedString(subtitle), level,
221
- toc,
222
- progress, anchor: this.convertStringToBreakscapedString(anchor), reference: this.convertStringToBreakscapedString(reference), referenceEnd: this.convertStringToBreakscapedString(referenceEnd) }, this.parseItemLeadHintInstructionPageNumberMarginNumber(item, lead, hint, instruction, pageNumber, marginNumber)), this.parseExample(example)), { imageSource: imageSourceNode, person: personNode, markConfig: markConfigNode, imagePlaceholder: imagePlaceholderNode, resources: resourcesNode, body: bodyNode, elements: this.convertStringToBreakscapedString(elements), flashcards: flashcardNodes, definitions: definitionNodes, statements: statementNodes, responses: responseNodes, quizzes: quizNodes, heading: headingNode, pairs: pairsNodes, matrix: matrixNodes, table: tableNode, choices: choiceNodes, questions: questionNodes, botResponses: botResponseNodes, ingredients: ingredientsNodes, captionDefinitionList: captionDefinitionListNode, cardBits: cardBitNodes, footer: footerNode }));
137
+ const bitNode = builder.buildBit(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bitRest), { bitType, bitLevel: Math.max(Math.min((_b = bit.bitLevel) !== null && _b !== void 0 ? _b : 1, Config.bitLevelMax), Config.bitLevelMin), textFormat: bit.format, resourceType: this.getResourceType(bit.resource), isCommented, internalComment: internalComments, productList: product, productVideoList: productVideo }), this.processReference(referenceBit)), this.parseExample(bit.example)), { person: (_c = bit.partner) !== null && _c !== void 0 ? _c : bit.person, markConfig: bit.marks, resources: this.processResources(bitType, bit.resource, bit.images, bit.logos), body: this.processBody(bit.body, bit.placeholders), flashcards: bit.cards, statements: this.processStatements(statement, bit.isCorrect, bit.statements, bit.example), responses: this.processResponses(bitType, bit.responses), botResponses: this.processBotResponse(bitType, bit.responses), cardBits: this.processListItems((_d = bit.listItems) !== null && _d !== void 0 ? _d : bit.sections, bit.placeholders), footer: this.processFooter(bit.footer) }));
223
138
  return bitNode;
224
139
  }
225
- imageSourceBitToAst(imageSource) {
226
- var _a, _b;
227
- let node;
228
- if (imageSource) {
229
- const { url, mockupId, format, size, trim } = imageSource;
230
- node = builder.imageSource({
231
- url: (_a = this.convertStringToBreakscapedString(url)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
232
- mockupId: (_b = this.convertStringToBreakscapedString(mockupId)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING,
233
- format: this.convertStringToBreakscapedString(format),
234
- size,
235
- trim,
236
- });
237
- }
238
- return node;
239
- }
240
- imagePlaceholderBitToAst(imagePlaceholder) {
241
- let node;
242
- if (imagePlaceholder) {
243
- const { image } = imagePlaceholder;
244
- node = this.resourceDataToAst(ResourceTag.image, image);
245
- }
246
- return node;
247
- }
248
- personBitToAst(person) {
249
- var _a;
250
- let node;
251
- if (person) {
252
- const avatarImage = this.resourceDataToAst(ResourceTag.image, person.avatarImage);
253
- node = builder.person({
254
- name: (_a = this.convertStringToBreakscapedString(person.name)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
255
- title: this.convertStringToBreakscapedString(person.title),
256
- avatarImage,
257
- });
258
- }
259
- return node;
260
- }
261
- markConfigBitToAst(marks) {
262
- var _a;
263
- const nodes = [];
264
- if (Array.isArray(marks)) {
265
- for (const m of marks) {
266
- const { mark, color, emphasis } = m;
267
- const node = builder.markConfig({
268
- mark: (_a = this.convertStringToBreakscapedString(mark)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
269
- color: this.convertStringToBreakscapedString(color),
270
- emphasis: this.convertStringToBreakscapedString(emphasis),
271
- });
272
- nodes.push(node);
273
- }
274
- }
275
- if (nodes.length === 0)
276
- return undefined;
277
- return nodes;
278
- }
279
- flashcardBitsToAst(flashcards) {
280
- var _a;
281
- const nodes = [];
282
- if (Array.isArray(flashcards)) {
283
- for (const c of flashcards) {
284
- const { question, answer, alternativeAnswers, item, lead, hint, instruction, example } = c;
285
- const node = builder.flashcard(Object.assign(Object.assign({ question: (_a = this.convertJsonTextToBreakscapedString(question)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, answer: this.convertJsonTextToBreakscapedString(answer), alternativeAnswers: this.convertJsonTextToBreakscapedString(alternativeAnswers) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
286
- nodes.push(node);
287
- }
288
- }
289
- if (nodes.length === 0)
290
- return undefined;
291
- return nodes;
292
- }
293
- definitionsBitsToAst(definitionList) {
294
- var _a;
295
- const nodes = [];
296
- if (Array.isArray(definitionList)) {
297
- for (const c of definitionList) {
298
- const { term, description, alternativeDefinitions, item, lead, hint, instruction, example } = c;
299
- const node = builder.definitionListItem(Object.assign(Object.assign({ term: (_a = this.convertJsonTextToBreakscapedString(term)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, description: this.convertJsonTextToBreakscapedString(description), alternativeDefinitions: this.convertJsonTextToBreakscapedString(alternativeDefinitions) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
300
- nodes.push(node);
301
- }
302
- }
303
- if (nodes.length === 0)
304
- return undefined;
305
- return nodes;
306
- }
307
- descriptionsBitsToAst(definitionList) {
308
- var _a;
309
- const nodes = [];
310
- if (Array.isArray(definitionList)) {
311
- for (const c of definitionList) {
312
- const { term, description, alternativeDescriptions, item, lead, hint, instruction, example } = c;
313
- const node = builder.definitionListItem(Object.assign(Object.assign({ term: (_a = this.convertJsonTextToBreakscapedString(term)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, description: this.convertJsonTextToBreakscapedString(description), alternativeDefinitions: this.convertJsonTextToBreakscapedString(alternativeDescriptions) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
314
- nodes.push(node);
315
- }
316
- }
317
- if (nodes.length === 0)
318
- return undefined;
319
- return nodes;
320
- }
321
- statementBitsToAst(statement, isCorrect, statements, example) {
322
- var _a, _b;
140
+ processStatements(statement, isCorrect, statements, example) {
323
141
  const nodes = [];
142
+ // Add statement defined in the bit
324
143
  if (statement) {
325
- const node = builder.statement(Object.assign({ text: (_a = this.convertStringToBreakscapedString(statement)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, isCorrect: isCorrect !== null && isCorrect !== void 0 ? isCorrect : false }, this.parseExample(example)));
326
- nodes.push(node);
327
- }
328
- if (Array.isArray(statements)) {
329
- for (const s of statements) {
330
- const { statement, isCorrect, item, lead, hint, instruction, example } = s;
331
- const node = builder.statement(Object.assign(Object.assign({ text: (_b = this.convertStringToBreakscapedString(statement)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING, isCorrect }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
332
- nodes.push(node);
333
- }
334
- }
335
- if (nodes.length === 0)
336
- return undefined;
337
- return nodes;
338
- }
339
- choiceBitsToAst(choices) {
340
- var _a;
341
- const nodes = [];
342
- if (Array.isArray(choices)) {
343
- for (const c of choices) {
344
- const { choice, isCorrect, item, lead, hint, instruction, example } = c;
345
- const node = builder.choice(Object.assign(Object.assign({ text: (_a = this.convertStringToBreakscapedString(choice)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, isCorrect }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
144
+ const node = Object.assign({ statement: statement !== null && statement !== void 0 ? statement : '', isCorrect: isCorrect !== null && isCorrect !== void 0 ? isCorrect : false }, this.parseExample(example));
145
+ if (node)
346
146
  nodes.push(node);
347
- }
348
147
  }
148
+ // add standard statements
149
+ if (Array.isArray(statements))
150
+ for (const item of statements)
151
+ nodes.push(item);
349
152
  if (nodes.length === 0)
350
153
  return undefined;
351
154
  return nodes;
352
155
  }
353
- responseBitsToAst(bitType, responses) {
354
- var _a;
355
- const nodes = [];
156
+ processResponses(bitType, responses) {
356
157
  // Return early if bot response as the responses should be interpreted as bot responses
357
158
  if (Config.isOfBitType(bitType, BitType.botActionResponse))
358
159
  return undefined;
359
- if (Array.isArray(responses)) {
360
- for (const r of responses) {
361
- const { response, isCorrect, item, lead, hint, instruction, example } = r;
362
- const node = builder.response(Object.assign(Object.assign({ text: (_a = this.convertStringToBreakscapedString(response)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, isCorrect }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
363
- nodes.push(node);
364
- }
365
- }
366
- if (nodes.length === 0)
367
- return undefined;
368
- return nodes;
369
- }
370
- selectOptionBitsToAst(options) {
371
- var _a;
372
- const nodes = [];
373
- if (Array.isArray(options)) {
374
- for (const o of options) {
375
- const { text, isCorrect, item, lead, hint, instruction, example } = o;
376
- const node = builder.selectOption(Object.assign(Object.assign({ text: (_a = this.convertStringToBreakscapedString(text)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, isCorrect }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
377
- nodes.push(node);
378
- }
379
- }
380
- return nodes;
381
- }
382
- highlightTextBitsToAst(highlightTexts) {
383
- var _a;
384
- const nodes = [];
385
- if (Array.isArray(highlightTexts)) {
386
- for (const t of highlightTexts) {
387
- const { text, isCorrect, isHighlighted, item, lead, hint, instruction, example } = t;
388
- const node = builder.highlightText(Object.assign(Object.assign({ text: (_a = this.convertStringToBreakscapedString(text)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, isCorrect,
389
- isHighlighted }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
390
- nodes.push(node);
391
- }
392
- }
393
- return nodes;
394
- }
395
- quizBitsToAst(bitType, quizzes) {
396
- const nodes = [];
397
- if (Array.isArray(quizzes)) {
398
- for (const q of quizzes) {
399
- const { item, lead, hint, instruction, choices, responses } = q;
400
- const choiceNodes = this.choiceBitsToAst(choices);
401
- const responseNodes = this.responseBitsToAst(bitType, responses);
402
- const node = builder.quiz(Object.assign(Object.assign({}, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), { choices: choiceNodes, responses: responseNodes }));
403
- nodes.push(node);
404
- }
405
- }
406
- if (nodes.length === 0)
407
- return undefined;
408
- return nodes;
409
- }
410
- headingBitToAst(heading) {
411
- var _a, _b;
412
- let node;
413
- if (heading && Object.keys(heading).length > 0) {
414
- node = builder.heading({
415
- forKeys: (_a = this.convertStringToBreakscapedString(heading.forKeys)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
416
- forValues: (_b = this.convertStringToBreakscapedString(heading.forValues)) !== null && _b !== void 0 ? _b : [],
417
- });
418
- }
419
- return node;
420
- }
421
- pairBitsToAst(pairs) {
422
- var _a;
423
- const nodes = [];
424
- if (Array.isArray(pairs)) {
425
- for (const p of pairs) {
426
- const { key, keyAudio, keyImage, values, item, lead, hint, instruction, example, isCaseSensitive } = p;
427
- const audio = this.resourceDataToAst(ResourceTag.audio, keyAudio);
428
- const image = this.resourceDataToAst(ResourceTag.image, keyImage);
429
- const node = builder.pair(Object.assign(Object.assign(Object.assign({ key: this.convertStringToBreakscapedString(key), keyAudio: audio, keyImage: image, values: (_a = this.convertStringToBreakscapedString(values)) !== null && _a !== void 0 ? _a : [] }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)), { isCaseSensitive }));
430
- nodes.push(node);
431
- }
432
- }
433
- if (nodes.length === 0)
434
- return undefined;
435
- return nodes;
436
- }
437
- matrixBitsToAst(matrix) {
438
- var _a, _b;
439
- const nodes = [];
440
- if (Array.isArray(matrix)) {
441
- for (const m of matrix) {
442
- const { key, cells, item, lead, hint, instruction, example } = m;
443
- const node = builder.matrix(Object.assign(Object.assign({ key: (_a = this.convertStringToBreakscapedString(key)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, cells: (_b = this.matrixCellsToAst(cells)) !== null && _b !== void 0 ? _b : [] }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
444
- nodes.push(node);
445
- }
446
- }
447
- if (nodes.length === 0)
448
- return undefined;
449
- return nodes;
450
- }
451
- matrixCellsToAst(matrixCells) {
452
- var _a;
453
- const nodes = [];
454
- if (Array.isArray(matrixCells)) {
455
- for (const mc of matrixCells) {
456
- const { values, item, lead, hint, instruction, isCaseSensitive, example } = mc;
457
- const node = builder.matrixCell(Object.assign(Object.assign(Object.assign({ values: (_a = this.convertStringToBreakscapedString(values)) !== null && _a !== void 0 ? _a : [] }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), { isCaseSensitive }), this.parseExample(example)));
458
- nodes.push(node);
459
- }
460
- }
461
- if (nodes.length === 0)
462
- return undefined;
463
- return nodes;
464
- }
465
- tableToAst(table) {
466
- var _a, _b;
467
- let node;
468
- if (table) {
469
- const { columns, data } = table;
470
- node = builder.table({
471
- columns: (_a = this.convertStringToBreakscapedString(columns)) !== null && _a !== void 0 ? _a : [],
472
- rows: data ? ((_b = data.map((row) => { var _a; return (_a = this.convertStringToBreakscapedString(row)) !== null && _a !== void 0 ? _a : []; })) !== null && _b !== void 0 ? _b : []) : [],
473
- });
474
- }
475
- return node;
476
- }
477
- questionBitsToAst(questions) {
478
- var _a;
479
- const nodes = [];
480
- if (Array.isArray(questions)) {
481
- for (const q of questions) {
482
- const { question, partialAnswer, sampleSolution, additionalSolutions, item, lead, hint, instruction, example, reasonableNumOfChars, } = q;
483
- const node = builder.question(Object.assign(Object.assign(Object.assign({ question: (_a = this.convertStringToBreakscapedString(question)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, partialAnswer: this.convertStringToBreakscapedString(partialAnswer), sampleSolution: this.convertStringToBreakscapedString(sampleSolution), additionalSolutions: this.convertStringToBreakscapedString(additionalSolutions) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)), { reasonableNumOfChars }));
484
- nodes.push(node);
485
- }
486
- }
487
- if (nodes.length === 0)
160
+ if (!Array.isArray(responses))
488
161
  return undefined;
489
- return nodes;
162
+ return responses;
490
163
  }
491
- botResponseBitsToAst(bitType, responses) {
492
- var _a, _b, _c;
493
- const nodes = [];
164
+ processBotResponse(bitType, responses) {
494
165
  // Return early if NOT bot response as the responses should be interpreted as standard responses
495
166
  if (!Config.isOfBitType(bitType, BitType.botActionResponse))
496
167
  return undefined;
497
- if (Array.isArray(responses)) {
498
- for (const r of responses) {
499
- const { response, reaction, feedback, item, lead, hint } = r;
500
- const node = builder.botResponse(Object.assign({ response: (_a = this.convertStringToBreakscapedString(response)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, reaction: (_b = this.convertStringToBreakscapedString(reaction)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING, feedback: (_c = this.convertStringToBreakscapedString(feedback)) !== null && _c !== void 0 ? _c : Breakscape.EMPTY_STRING }, this.parseItemLeadHintInstruction(item, lead, hint, Breakscape.EMPTY_STRING)));
501
- nodes.push(node);
502
- }
503
- }
504
- if (nodes.length === 0)
168
+ if (!Array.isArray(responses))
505
169
  return undefined;
506
- return nodes;
507
- }
508
- technicalTermToAst(technicalTerm) {
509
- var _a, _b;
510
- let node;
511
- if (technicalTerm) {
512
- const { technicalTerm: t, lang } = technicalTerm;
513
- node = builder.technicalTerm({
514
- technicalTerm: (_a = this.convertStringToBreakscapedString(t)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
515
- lang: (_b = this.convertStringToBreakscapedString(lang)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING,
516
- });
517
- }
518
- return node;
170
+ return responses;
519
171
  }
520
- servingsToAst(servings) {
521
- var _a, _b, _c;
522
- let node;
523
- if (servings) {
524
- const { servings: s, unit, unitAbbr, decimalPlaces, disableCalculation, hint } = servings;
525
- node = builder.servings({
526
- servings: s,
527
- unit: (_a = this.convertStringToBreakscapedString(unit)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
528
- unitAbbr: (_b = this.convertStringToBreakscapedString(unitAbbr)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING,
529
- decimalPlaces: decimalPlaces !== null && decimalPlaces !== void 0 ? decimalPlaces : 1,
530
- disableCalculation: disableCalculation !== null && disableCalculation !== void 0 ? disableCalculation : false,
531
- hint: (_c = this.convertStringToBreakscapedString(hint)) !== null && _c !== void 0 ? _c : Breakscape.EMPTY_STRING,
532
- });
533
- }
534
- return node;
535
- }
536
- ingredientsBitsToAst(ingredients) {
537
- var _a, _b;
538
- const nodes = [];
539
- if (Array.isArray(ingredients)) {
540
- for (const i of ingredients) {
541
- const { title, checked, item, quantity, unit, unitAbbr, decimalPlaces, disableCalculation } = i;
542
- const node = builder.ingredient({
543
- title: this.convertStringToBreakscapedString(title),
544
- checked,
545
- item: (_a = this.convertStringToBreakscapedString(item)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
546
- quantity,
547
- unit: (_b = this.convertStringToBreakscapedString(unit)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING,
548
- unitAbbr: this.convertStringToBreakscapedString(unitAbbr),
549
- decimalPlaces: decimalPlaces !== null && decimalPlaces !== void 0 ? decimalPlaces : 1,
550
- disableCalculation,
551
- });
552
- nodes.push(node);
553
- }
554
- }
555
- if (nodes.length === 0)
556
- return undefined;
557
- return nodes;
558
- }
559
- ratingLevelStartEndToAst(ratingLevelStartEnd) {
560
- var _a;
561
- let node;
562
- if (ratingLevelStartEnd) {
563
- const { level, label } = ratingLevelStartEnd;
564
- node = builder.ratingLevelStartEnd({
565
- level,
566
- label: (_a = this.convertJsonTextToBreakscapedString(label)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
567
- });
568
- }
569
- return node;
570
- }
571
- captionDefinitionListToAst(captionDefinitionList) {
572
- var _a;
573
- let node;
574
- if (captionDefinitionList) {
575
- const { columns, definitions } = captionDefinitionList;
576
- node = builder.captionDefinitionList({
577
- columns: (_a = this.convertStringToBreakscapedString(columns)) !== null && _a !== void 0 ? _a : [],
578
- definitions: (definitions !== null && definitions !== void 0 ? definitions : []).map((d) => {
579
- var _a, _b;
580
- return builder.captionDefinition({
581
- term: (_a = this.convertStringToBreakscapedString(d.term)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING,
582
- description: (_b = this.convertStringToBreakscapedString(d.description)) !== null && _b !== void 0 ? _b : Breakscape.EMPTY_STRING,
583
- });
584
- }),
585
- });
586
- }
587
- return node;
588
- }
589
- listItemsToAst(listItems, textFormat, placeholders) {
172
+ processListItems(listItems, placeholders) {
590
173
  const nodes = [];
591
174
  if (Array.isArray(listItems)) {
592
175
  for (const li of listItems) {
593
- const { item, lead, hint, instruction, body } = li;
594
- const node = builder.cardBit(Object.assign(Object.assign({}, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), { body: this.bodyToAst(body, textFormat, placeholders) }));
176
+ const node = Object.assign({}, li);
177
+ if (node.body) {
178
+ node.body = {
179
+ body: node.body,
180
+ placeholders,
181
+ };
182
+ }
595
183
  if (node)
596
184
  nodes.push(node);
597
185
  }
@@ -607,200 +195,44 @@ class JsonParser {
607
195
  }
608
196
  return undefined;
609
197
  }
610
- resourceBitToAst(bitType, resource, images) {
611
- var _a;
198
+ processResources(bitType, resource, images, logos) {
612
199
  const nodes = [];
613
- if (resource) {
614
- const resourceKey = (_a = ResourceTag.keyFromValue(resource.type)) !== null && _a !== void 0 ? _a : ResourceTag.unknown;
615
- let data;
616
- // TODO: This code should use the config to handle the combo resources. For now the logic is hardcoded
617
- // Handle special cases for multiple resource bits (imageResponsive, stillImageFilm)
618
- if (resource.type === ResourceTag.imageResponsive) {
619
- const r = resource;
620
- const imagePortraitNode = this.resourceDataToAst(ResourceTag.imagePortrait, r.imagePortrait);
621
- const imageLandscapeNode = this.resourceDataToAst(ResourceTag.imageLandscape, r.imageLandscape);
622
- if (imagePortraitNode)
623
- nodes.push(imagePortraitNode);
624
- if (imageLandscapeNode)
625
- nodes.push(imageLandscapeNode);
626
- }
627
- else if (resource.type === ResourceTag.stillImageFilm) {
628
- const r = resource;
629
- const imageNode = this.resourceDataToAst(ResourceTag.image, r.image);
630
- const audioNode = this.resourceDataToAst(ResourceTag.audio, r.audio);
631
- if (imageNode)
632
- nodes.push(imageNode);
633
- if (audioNode)
634
- nodes.push(audioNode);
635
- }
636
- else {
637
- // Standard single resource case
638
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
639
- data = resource[resourceKey];
640
- if (!data)
641
- return undefined;
642
- const node = this.resourceDataToAst(resource.type, data);
643
- if (node)
644
- nodes.push(node);
645
- }
646
- }
647
- if (Config.isOfBitType(bitType, [BitType.imagesLogoGrave, BitType.prototypeImages])) {
200
+ if (resource)
201
+ nodes.push(resource);
202
+ if (Config.isOfBitType(bitType, [BitType.prototypeImages])) {
648
203
  // Add the logo images
649
204
  if (Array.isArray(images)) {
650
205
  for (const image of images) {
651
- const node = this.resourceDataToAst(ResourceTag.image, image.image);
652
- if (node)
653
- nodes.push(node);
206
+ if (image)
207
+ nodes.push(image);
654
208
  }
655
209
  }
656
210
  }
657
- return nodes;
658
- }
659
- resourceDataToAst(type, data) {
660
- var _a, _b;
661
- let node;
662
- if (data) {
663
- if (!data)
664
- return undefined;
665
- const dataAsString = StringUtils.isString(data) ? data : undefined;
666
- // url / src / href / app
667
- const url = data.url || data.src || data.href || data.app || data.body || dataAsString;
668
- // Sub resources
669
- const posterImage = this.resourceDataToAst(ResourceTag.image, data.posterImage);
670
- const thumbnails = data.thumbnails
671
- ? data.thumbnails.map((t) => {
672
- return this.resourceDataToAst(ResourceTag.image, t);
673
- })
674
- : undefined;
675
- // Resource
676
- node = resourceBuilder.resource({
677
- type,
678
- // Generic (except Article / Document)
679
- value: this.convertStringToBreakscapedString(url),
680
- // ImageLikeResource / AudioLikeResource / VideoLikeResource / Article / Document
681
- format: this.convertStringToBreakscapedString(data.format),
682
- // ImageLikeResource
683
- src1x: this.convertStringToBreakscapedString(data.src1x),
684
- src2x: this.convertStringToBreakscapedString(data.src2x),
685
- src3x: this.convertStringToBreakscapedString(data.src3x),
686
- src4x: this.convertStringToBreakscapedString(data.src4x),
687
- caption: this.convertJsonTextToBreakscapedString(data.caption),
688
- // ImageLikeResource / VideoLikeResource
689
- width: (_a = data.width) !== null && _a !== void 0 ? _a : undefined,
690
- height: (_b = data.height) !== null && _b !== void 0 ? _b : undefined,
691
- alt: this.convertStringToBreakscapedString(data.alt),
692
- zoomDisabled: data.zoomDisabled,
693
- // VideoLikeResource
694
- duration: data.duration,
695
- mute: data.mute,
696
- autoplay: data.autoplay,
697
- allowSubtitles: data.allowSubtitles,
698
- showSubtitles: data.showSubtitles,
699
- posterImage,
700
- thumbnails,
701
- // WebsiteLinkResource
702
- siteName: this.convertStringToBreakscapedString(data.siteName),
703
- // Generic Resource
704
- license: this.convertStringToBreakscapedString(data.license),
705
- copyright: this.convertStringToBreakscapedString(data.copyright),
706
- showInIndex: data.showInIndex,
707
- search: this.convertStringToBreakscapedString(data.search),
708
- });
709
- }
710
- return node;
711
- }
712
- bodyToAst(body, textFormat, placeholders) {
713
- let node;
714
- let bodyStr;
715
- const placeholderNodes = {};
716
- if (textFormat === TextFormat.json) {
717
- // If the text format is JSON, handle appropriately
718
- let bodyObject = body;
719
- // Attempt to parse a string body as JSON to support the legacy format
720
- if (typeof bodyObject === 'string') {
721
- try {
722
- bodyObject = JSON.parse(bodyObject);
723
- }
724
- catch (e) {
725
- // Could not parse JSON - set body to null
726
- bodyObject = null;
727
- }
728
- }
729
- node = builder.body({ bodyJson: bodyObject });
730
- }
731
- else {
732
- if (Array.isArray(body)) {
733
- // Body is an array (prosemirror like JSON)
734
- // Parse the body to string in case it is in JSON format
735
- bodyStr = this.convertJsonTextToBreakscapedString(body, textFormat);
736
- // Get the placeholders from the text parser
737
- placeholders = this.textGenerator.getPlaceholders();
738
- }
739
- else {
740
- // Body is a string (legacy bitmark v2, or not bitmark--/++)
741
- bodyStr = this.convertJsonTextToBreakscapedString(body, textFormat);
742
- }
743
- // Placeholders
744
- if (placeholders) {
745
- for (const [key, val] of Object.entries(placeholders)) {
746
- const bit = this.bodyBitToAst(val);
747
- placeholderNodes[key] = bit;
748
- }
749
- }
750
- if (bodyStr) {
751
- // Split the body string and insert the placeholders
752
- const bodyPartNodes = [];
753
- const bodyParts = StringUtils.splitPlaceholders(bodyStr, Object.keys(placeholderNodes));
754
- for (let i = 0, len = bodyParts.length; i < len; i++) {
755
- const bodyPart = bodyParts[i];
756
- if (placeholderNodes[bodyPart]) {
757
- // Replace the placeholder
758
- bodyPartNodes.push(placeholderNodes[bodyPart]);
759
- }
760
- else {
761
- // Treat as text
762
- const bodyText = this.bodyTextToAst(bodyPart);
763
- bodyPartNodes.push(bodyText);
764
- }
211
+ if (Config.isOfBitType(bitType, [BitType.imagesLogoGrave])) {
212
+ // Add the logo images
213
+ if (Array.isArray(logos)) {
214
+ for (const image of logos) {
215
+ if (image)
216
+ nodes.push(image);
765
217
  }
766
- node = builder.body({ bodyParts: bodyPartNodes });
767
218
  }
768
219
  }
769
- return node;
770
- }
771
- bodyTextToAst(bodyText) {
772
- return builder.bodyText({ text: bodyText !== null && bodyText !== void 0 ? bodyText : Breakscape.EMPTY_STRING }, false);
220
+ return nodes;
773
221
  }
774
- bodyBitToAst(bit) {
775
- switch (bit.type) {
776
- case BodyBitType.gap: {
777
- const gap = this.gapBitToAst(bit);
778
- return gap;
779
- }
780
- case BodyBitType.mark: {
781
- const mark = this.markBitToAst(bit);
782
- return mark;
783
- }
784
- case BodyBitType.select: {
785
- const select = this.selectBitToAst(bit);
786
- return select;
787
- }
788
- case BodyBitType.highlight: {
789
- const hightlight = this.highlightBitToAst(bit);
790
- return hightlight;
791
- }
792
- }
793
- return this.bodyTextToAst(Breakscape.EMPTY_STRING);
222
+ processBody(body, placeholders) {
223
+ return {
224
+ body,
225
+ placeholders,
226
+ };
794
227
  }
795
- footerToAst(footerText, textFormat) {
796
- const text = this.convertJsonTextToBreakscapedString(footerText, textFormat);
797
- if (text) {
798
- const footerText = builder.footerText({ text }, false);
799
- return builder.footer({ footerParts: [footerText] });
800
- }
801
- return undefined;
228
+ processFooter(footerText) {
229
+ if (!footerText)
230
+ return undefined;
231
+ return {
232
+ footer: footerText,
233
+ };
802
234
  }
803
- referenceToAst(reference) {
235
+ processReference(reference) {
804
236
  if (Array.isArray(reference) && reference.length > 0) {
805
237
  return {
806
238
  reference: undefined,
@@ -812,143 +244,19 @@ class JsonParser {
812
244
  referenceProperty: undefined,
813
245
  };
814
246
  }
815
- gapBitToAst(bit) {
816
- var _a;
817
- const { item, lead, hint, instruction, example, isCaseSensitive, solutions } = bit;
818
- // Build bit
819
- const bitNode = builder.gap(Object.assign(Object.assign(Object.assign({ solutions: (_a = this.convertStringToBreakscapedString(solutions)) !== null && _a !== void 0 ? _a : [] }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)), { isCaseSensitive }));
820
- return bitNode;
821
- }
822
- markBitToAst(bit) {
823
- var _a;
824
- const { solution, mark, item, lead, hint, instruction, example } = bit;
825
- // Build bit
826
- const bitNode = builder.mark(Object.assign(Object.assign({ solution: (_a = this.convertStringToBreakscapedString(solution)) !== null && _a !== void 0 ? _a : Breakscape.EMPTY_STRING, mark: this.convertStringToBreakscapedString(mark) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
827
- return bitNode;
828
- }
829
- selectBitToAst(bit) {
830
- const { options, prefix, postfix, item, lead, hint, instruction, example } = bit;
831
- // Build options bits
832
- const selectOptionNodes = this.selectOptionBitsToAst(options);
833
- // Build bit
834
- const node = builder.select(Object.assign(Object.assign({ options: selectOptionNodes, prefix: this.convertStringToBreakscapedString(prefix), postfix: this.convertStringToBreakscapedString(postfix) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
835
- return node;
836
- }
837
- highlightBitToAst(bit) {
838
- const { texts, prefix, postfix, item, lead, hint, instruction, example } = bit;
839
- // Build options bits
840
- const highlightTextNodes = this.highlightTextBitsToAst(texts);
841
- // Build bit
842
- const node = builder.highlight(Object.assign(Object.assign({ texts: highlightTextNodes, prefix: this.convertStringToBreakscapedString(prefix), postfix: this.convertStringToBreakscapedString(postfix) }, this.parseItemLeadHintInstruction(item, lead, hint, instruction)), this.parseExample(example)));
843
- return node;
844
- }
845
- parseItemLeadHintInstruction(item, lead, hint, instruction) {
846
- return {
847
- item: this.convertJsonTextToBreakscapedString(item),
848
- lead: this.convertJsonTextToBreakscapedString(lead),
849
- pageNumber: '',
850
- marginNumber: '',
851
- hint: this.convertJsonTextToBreakscapedString(hint),
852
- instruction: this.convertJsonTextToBreakscapedString(instruction),
853
- };
854
- }
855
- parseItemLeadHintInstructionPageNumberMarginNumber(item, lead, hint, instruction, pageNumber, marginNumber) {
856
- return {
857
- item: this.convertJsonTextToBreakscapedString(item),
858
- lead: this.convertJsonTextToBreakscapedString(lead),
859
- pageNumber: this.convertJsonTextToBreakscapedString(pageNumber),
860
- marginNumber: this.convertJsonTextToBreakscapedString(marginNumber),
861
- hint: this.convertJsonTextToBreakscapedString(hint),
862
- instruction: this.convertJsonTextToBreakscapedString(instruction),
863
- };
864
- }
865
247
  parseExample(example) {
866
248
  if (example == null)
867
249
  return undefined;
868
- const exampleStr = this.convertJsonTextToBreakscapedString(example);
869
- if (exampleStr) {
870
- return { example: exampleStr };
250
+ if (example === true)
251
+ return { example: true };
252
+ if (example === false)
253
+ return { example: false };
254
+ const exampleText = StringUtils.isString(example) || Array.isArray(example) ? example : undefined;
255
+ if (exampleText) {
256
+ return { example: exampleText };
871
257
  }
872
258
  return { example: !!example };
873
259
  }
874
- /**
875
- * Convert the JsonText from the JSON to the AST format:
876
- * Input:
877
- * - Bitmark v2: breakscaped string
878
- * - Bitmark v3: bitmark text JSON (TextAst)
879
- * Output:
880
- * - breakscaped string
881
- *
882
- * In the case of Bitmark v2 type texts, there is nothing to do but cast the type.
883
- *
884
- * @param breakscaped string or TextAst or breakscaped string[] or TextAst[]
885
- * @param textFormat format of TextAst
886
- * @returns Breakscaped string or breakscaped string[]
887
- */
888
- convertJsonTextToBreakscapedString(text, textFormat) {
889
- // NOTE: it is ok to default to bitmarkMinusMinus here as if the text is text then it will not be an array or
890
- // return true from isAst() and so will be treated as a string
891
- textFormat = textFormat !== null && textFormat !== void 0 ? textFormat : TextFormat.bitmarkMinusMinus;
892
- const bitTagOnly = (textFormat !== TextFormat.bitmarkPlusPlus &&
893
- textFormat !== TextFormat.bitmarkMinusMinus);
894
- if (text == null)
895
- return undefined;
896
- if (this.textParser.isAst(text)) {
897
- // Use the text generator to convert the TextAst to breakscaped string
898
- // this.ast.printTree(text, NodeType.textAst);
899
- const parsedText = this.textGenerator.generateSync(text, textFormat);
900
- return parsedText;
901
- }
902
- else if (Array.isArray(text)) {
903
- const strArray = [];
904
- for (let i = 0, len = text.length; i < len; i++) {
905
- const t = text[i];
906
- if (this.textParser.isAst(t)) {
907
- // Use the text generator to convert the TextAst to breakscaped string
908
- // this.ast.printTree(text, NodeType.textAst);
909
- const parsedText = this.textGenerator.generateSync(t, textFormat);
910
- strArray[i] = parsedText;
911
- }
912
- else {
913
- strArray[i] = Breakscape.breakscape(t, {
914
- bitTagOnly,
915
- });
916
- // strArray[i] = t as BreakscapedString;
917
- }
918
- }
919
- return strArray;
920
- }
921
- return Breakscape.breakscape(text, {
922
- bitTagOnly,
923
- });
924
- // return text as BreakscapedString as R;
925
- }
926
- /**
927
- * Convert the string from the JSON to the AST format:
928
- * Input:
929
- * - Bitmark v2/v3: string
930
- * Output:
931
- * - breakscaped string
932
- *
933
- * In the case of Bitmark v2 type texts, there is nothing to do but cast the type.
934
- *
935
- * @param text string or TextAst or string[] or TextAst[]
936
- * @param textFormat format of TextAst
937
- * @returns Breakscaped string or breakscaped string[]
938
- */
939
- convertStringToBreakscapedString(text) {
940
- if (text == null)
941
- return undefined;
942
- if (Array.isArray(text)) {
943
- const strArray = [];
944
- for (let i = 0, len = text.length; i < len; i++) {
945
- const t = text[i];
946
- strArray[i] = Breakscape.breakscape(t);
947
- }
948
- return strArray;
949
- }
950
- return Breakscape.breakscape(text);
951
- }
952
260
  }
953
261
  export { JsonParser };
954
262
  //# sourceMappingURL=JsonParser.js.map