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