diff --git a/package-lock.json b/package-lock.json index 301936ab..26528237 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2156,9 +2156,9 @@ } }, "node_modules/@diplodoc/transform": { - "version": "4.31.1", - "resolved": "https://registry.npmjs.org/@diplodoc/transform/-/transform-4.31.1.tgz", - "integrity": "sha512-StlV/GuSSJ52k+5ZhGUtMtBg/T+SUlYgCfQApR5cW5cNnmzobgoS9sAnJFohSlFWuBeRhXZS3puoEe1a7sjhxg==", + "version": "4.31.2", + "resolved": "https://registry.npmjs.org/@diplodoc/transform/-/transform-4.31.2.tgz", + "integrity": "sha512-nazb35uHC5uAHO8jA/lojhGtKTvrfUcp1flvqiiL8grCBEM3fi7j55Zhq2GqAM44/db0odXAkVZDbPdqxFEN7w==", "dependencies": { "@diplodoc/cut-extension": "^0.2.5", "@diplodoc/tabs-extension": "^3.3.1", @@ -2171,7 +2171,7 @@ "js-yaml": "^4.1.0", "lodash": "4.17.21", "markdown-it": "^13.0.2", - "markdown-it-attrs": "4.1.4", + "markdown-it-attrs": "^4.2.0", "markdown-it-deflist": "2.1.0", "markdown-it-meta": "0.0.1", "markdown-it-sup": "1.0.0", @@ -8041,9 +8041,9 @@ } }, "node_modules/markdown-it-attrs": { - "version": "4.1.4", - "resolved": "https://registry.npmjs.org/markdown-it-attrs/-/markdown-it-attrs-4.1.4.tgz", - "integrity": "sha512-53Zfv8PTb6rlVFDlD106xcZHKBSsRZKJ2IW/rTxEJBEVbVaoxaNsmRkG0HXfbHl2SK8kaxZ2QKqdthWy/QBwmA==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/markdown-it-attrs/-/markdown-it-attrs-4.2.0.tgz", + "integrity": "sha512-m7svtUBythvcGFFZAv9VjMEvs8UbHri2sojJ3juJumoOzv8sdkx9a7W3KxiHbXxAbvL3Xauak8TMwCnvigVPKw==", "engines": { "node": ">=6" }, diff --git a/src/models.ts b/src/models.ts index 23756d70..6825417c 100644 --- a/src/models.ts +++ b/src/models.ts @@ -84,6 +84,7 @@ interface YfmConfig { */ changelogs?: string | boolean; analytics?: DocAnalytics; + useLegacyConditions: boolean; } export interface YfmArgv extends YfmConfig { diff --git a/src/resolvers/md2html.ts b/src/resolvers/md2html.ts index b4d29c46..78dc21ce 100644 --- a/src/resolvers/md2html.ts +++ b/src/resolvers/md2html.ts @@ -203,11 +203,12 @@ function YamlFileTransformer(content: string, transformOptions: FileTransformOpt } export function liquidMd2Html(input: string, vars: Record, path: string) { - const {conditionsInCode} = ArgvService.getConfig(); + const {conditionsInCode, useLegacyConditions} = ArgvService.getConfig(); return liquid(input, vars, path, { conditionsInCode, withSourceMap: true, + useLegacyConditions, }); } diff --git a/src/resolvers/md2md.ts b/src/resolvers/md2md.ts index 42549360..ce36f57f 100644 --- a/src/resolvers/md2md.ts +++ b/src/resolvers/md2md.ts @@ -91,7 +91,8 @@ function copyFile(targetPath: string, targetDestPath: string, options?: PluginOp } export function liquidMd2Md(input: string, vars: Record, path: string) { - const {applyPresets, resolveConditions, conditionsInCode} = ArgvService.getConfig(); + const {applyPresets, resolveConditions, conditionsInCode, useLegacyConditions} = + ArgvService.getConfig(); return liquid(input, vars, path, { conditions: resolveConditions, @@ -99,6 +100,7 @@ export function liquidMd2Md(input: string, vars: Record, path: conditionsInCode, withSourceMap: true, keepNotVar: true, + useLegacyConditions, }); } diff --git a/src/services/metadata/parse.ts b/src/services/metadata/parse.ts index 0376d3fc..cb3a3b86 100644 --- a/src/services/metadata/parse.ts +++ b/src/services/metadata/parse.ts @@ -103,9 +103,7 @@ export const parseExistingMetadata = ( }; export const serializeMetadata = (objectMetadata: FileMetadata) => { - const dumped = unescapeLiquidSubstitutionSyntax( - dump(objectMetadata, {forceQuotes: true}).trimEnd(), - ); + const dumped = unescapeLiquidSubstitutionSyntax(dump(objectMetadata).trimEnd()); // This empty object check is a bit naive // The other option would be to check if all own fields are `undefined`, diff --git a/src/services/utils.ts b/src/services/utils.ts index 9bbcbd0d..b5a4d422 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -162,7 +162,7 @@ export function liquidFields( } export function liquidField(input: string, vars: Record, path: string) { - const {applyPresets, resolveConditions} = ArgvService.getConfig(); + const {applyPresets, resolveConditions, useLegacyConditions} = ArgvService.getConfig(); if (!applyPresets && !resolveConditions) { return input; @@ -173,6 +173,7 @@ export function liquidField(input: string, vars: Record, path: conditions: resolveConditions, keepNotVar: true, withSourceMap: false, + useLegacyConditions, }); } diff --git a/tests/e2e/__snapshots__/include-toc.test.ts.snap b/tests/e2e/__snapshots__/include-toc.test.ts.snap index 4397cef6..986277f4 100644 --- a/tests/e2e/__snapshots__/include-toc.test.ts.snap +++ b/tests/e2e/__snapshots__/include-toc.test.ts.snap @@ -4,14 +4,14 @@ exports[`Include toc Nested toc inclusions with mixed including modes 1`] = `"[" exports[`Include toc Nested toc inclusions with mixed including modes 2`] = ` "--- -sourcePath: 'product1/core/_includes/inc.md' +sourcePath: product1/core/_includes/inc.md --- This is the core include." `; exports[`Include toc Nested toc inclusions with mixed including modes 3`] = ` "--- -sourcePath: 'product1/core/article1.md' +sourcePath: product1/core/article1.md --- This is the core content of Article 1. @@ -31,7 +31,7 @@ deepBase: 1 exports[`Include toc Nested toc inclusions with mixed including modes 5`] = ` "--- -sourcePath: 'product2/core/_includes/inc.md' +sourcePath: product2/core/_includes/inc.md --- This is the core include. " @@ -39,7 +39,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 6`] = ` "--- -sourcePath: 'product2/overlay1/product/article1.md' +sourcePath: product2/overlay1/product/article1.md --- This is the overlay content of Article 1 for product 2. @@ -49,7 +49,7 @@ This is the overlay content of Article 1 for product 2. exports[`Include toc Nested toc inclusions with mixed including modes 7`] = ` "--- -sourcePath: 'product2/core/_includes/inc.md' +sourcePath: product2/core/_includes/inc.md --- This is the core include. " @@ -57,7 +57,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 8`] = ` "--- -sourcePath: 'product2/overlay2/product/article1.md' +sourcePath: product2/overlay2/product/article1.md --- This is the overlay number #2 of Article 1 content for product 2. @@ -67,7 +67,7 @@ This is the overlay number #2 of Article 1 content for product 2. exports[`Include toc Nested toc inclusions with mixed including modes 9`] = ` "--- -sourcePath: 'product2/core/_includes/inc.md' +sourcePath: product2/core/_includes/inc.md --- This is the core include. " @@ -75,7 +75,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 10`] = ` "--- -sourcePath: 'product2/core/article1.md' +sourcePath: product2/core/article1.md --- This is the core content of Article 1. @@ -160,9 +160,9 @@ exports[`Include toc Toc is included inline, not as a new section 3`] = ` exports[`Include toc Toc is included inline, not as a new section 4`] = ` "--- -title: 'File A' -description: 'YFM description' -sourcePath: 'folder/fileA.md' +title: File A +description: YFM description +sourcePath: folder/fileA.md --- # File A @@ -176,7 +176,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 5`] = ` "--- -sourcePath: 'folder/fileB.md' +sourcePath: folder/fileB.md --- # File B @@ -192,7 +192,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 6`] = ` "--- -sourcePath: 'folder/folder/fileC.md' +sourcePath: folder/folder/fileC.md --- # File C " @@ -205,8 +205,8 @@ exports[`Include toc Toc is included inline, not as a new section 7`] = ` exports[`Include toc Toc is included inline, not as a new section 8`] = ` "--- -title: 'File A' -description: 'YFM description' +title: File A +description: YFM description --- # File A @@ -233,7 +233,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 10`] = ` "--- -sourcePath: 'folder/folder/fileC.md' +sourcePath: folder/folder/fileC.md --- # File C " diff --git a/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap b/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap index a1b2e3da..2cd2818b 100644 --- a/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap +++ b/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap @@ -474,12 +474,12 @@ links: exports[`Allow load custom resources md2md with custom resources 4`] = ` "--- metadata: - - name: 'yfm' - content: 'builder' + - name: yfm + content: builder style: - - '_assets/style/test.css' + - _assets/style/test.css script: - - '_assets/script/test1.js' + - _assets/script/test1.js --- Lorem @@ -489,9 +489,9 @@ Lorem exports[`Allow load custom resources md2md with custom resources 5`] = ` "--- style: - - '_assets/style/test.css' + - _assets/style/test.css script: - - '_assets/script/test1.js' + - _assets/script/test1.js --- Lorem" `; diff --git a/tests/e2e/__snapshots__/metadata.spec.ts.snap b/tests/e2e/__snapshots__/metadata.spec.ts.snap index 524d985c..22e5d45f 100644 --- a/tests/e2e/__snapshots__/metadata.spec.ts.snap +++ b/tests/e2e/__snapshots__/metadata.spec.ts.snap @@ -207,12 +207,12 @@ links: exports[`Allow load custom resources md2md with metadata 3`] = ` "--- metadata: - - name: 'yfm' - content: 'builder in page' - - name: 'test-yfm' - content: 'inline test' - - name: 'yfm-config' - content: 'config test' + - name: yfm + content: builder in page + - name: test-yfm + content: inline test + - name: yfm-config + content: config test --- Lorem" @@ -221,12 +221,12 @@ Lorem" exports[`Allow load custom resources md2md with metadata 4`] = ` "--- metadata: - - name: 'yfm' - value: 'builder in config' - - name: 'test-yfm' - content: 'inline test' - - name: 'yfm-config' - content: 'config test' + - name: yfm + value: builder in config + - name: test-yfm + content: inline test + - name: yfm-config + content: config test --- Lorem" diff --git a/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap b/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap index 1c678a5c..db08d0ac 100644 --- a/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap +++ b/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap @@ -11,10 +11,10 @@ exports[`Front matter (metadata) transformations do not break when a property ke exports[`Front matter (metadata) transformations do not break when a property key contains Liquid-style variable substitutions 2`] = ` "--- -prop-{{key-name}}: 'This one has a substitution in a key name.' -{{key-name}}-prop: 'This one''s key starts with a substitution.' -{{key-name}}: 'This one''s key only consists of a substitution.' -{{ key-name }}: 'This one''s key employs a different whitespace style in a substitution.' +prop-{{key-name}}: This one has a substitution in a key name. +{{key-name}}-prop: This one's key starts with a substitution. +{{key-name}}: This one's key only consists of a substitution. +{{ key-name }}: This one's key employs a different whitespace style in a substitution. --- Blah. " @@ -34,13 +34,15 @@ exports[`Front matter (metadata) transformations do not break when a property va exports[`Front matter (metadata) transformations do not break when a property value contains Liquid-style variable substitutions 2`] = ` "--- -prop1: 'This is a metadata property with a {{substitution}} in it.' -prop2: 'This one contains {{multiple}} {{substitutions}}.' -prop3: 'This one has {{substitutions}} of {{ different }} {{ styles}}.' -prop4: 'This one has a {{substitution}} as well, but the string literal is single-quoted.' -prop5: 'This one has no quotes at {{all}}.' -prop6: '{{this}} starts with a substitution.' -prop7: '{{this}} one is a multiline {{property}}.' +prop1: This is a metadata property with a {{substitution}} in it. +prop2: This one contains {{multiple}} {{substitutions}}. +prop3: This one has {{substitutions}} of {{ different }} {{ styles}}. +prop4: >- + This one has a {{substitution}} as well, but the string literal is + single-quoted. +prop5: This one has no quotes at {{all}}. +prop6: {{this}} starts with a substitution. +prop7: {{this}} one is a multiline {{property}}. --- Blah. " @@ -48,10 +50,10 @@ Blah. exports[`Front matter (metadata) transformations emit valid metadata when a variable is substituted with an ampty string 1`] = ` "--- -prop1: '' -prop2: '' -prop3: '' -prop4: '' +prop1: +prop2: +prop3: +prop4: --- " `;