Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add useLegacyConditions option, disable forceQuotes in yaml #829

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface YfmConfig {
*/
changelogs?: string | boolean;
analytics?: DocAnalytics;
useLegacyConditions: boolean;
}

export interface YfmArgv extends YfmConfig {
Expand Down
3 changes: 2 additions & 1 deletion src/resolvers/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ function YamlFileTransformer(content: string, transformOptions: FileTransformOpt
}

export function liquidMd2Html(input: string, vars: Record<string, unknown>, path: string) {
const {conditionsInCode} = ArgvService.getConfig();
const {conditionsInCode, useLegacyConditions} = ArgvService.getConfig();

return liquid(input, vars, path, {
conditionsInCode,
withSourceMap: true,
useLegacyConditions,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/resolvers/md2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ function copyFile(targetPath: string, targetDestPath: string, options?: PluginOp
}

export function liquidMd2Md(input: string, vars: Record<string, unknown>, path: string) {
const {applyPresets, resolveConditions, conditionsInCode} = ArgvService.getConfig();
const {applyPresets, resolveConditions, conditionsInCode, useLegacyConditions} =
ArgvService.getConfig();

return liquid(input, vars, path, {
conditions: resolveConditions,
substitutions: applyPresets,
conditionsInCode,
withSourceMap: true,
keepNotVar: true,
useLegacyConditions,
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/services/metadata/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
3 changes: 2 additions & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function liquidFields(
}

export function liquidField(input: string, vars: Record<string, unknown>, path: string) {
const {applyPresets, resolveConditions} = ArgvService.getConfig();
const {applyPresets, resolveConditions, useLegacyConditions} = ArgvService.getConfig();

if (!applyPresets && !resolveConditions) {
return input;
Expand All @@ -173,6 +173,7 @@ export function liquidField(input: string, vars: Record<string, unknown>, path:
conditions: resolveConditions,
keepNotVar: true,
withSourceMap: false,
useLegacyConditions,
});
}

Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/__snapshots__/include-toc.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -31,15 +31,15 @@ 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.
"
`;

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.

Expand All @@ -49,15 +49,15 @@ 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.
"
`;

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.

Expand All @@ -67,15 +67,15 @@ 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.
"
`;

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.

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
"
Expand All @@ -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

Expand All @@ -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
"
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
`;
Expand Down
24 changes: 12 additions & 12 deletions tests/e2e/__snapshots__/metadata.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"
Expand All @@ -34,24 +34,26 @@ 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.
"
`;

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:
---
"
`;
Loading