diff --git a/public/examples/quotes.yml b/public/examples/quotes.yml new file mode 100644 index 0000000..05af855 --- /dev/null +++ b/public/examples/quotes.yml @@ -0,0 +1,17 @@ +collections: + - name: "example" + label: "Example Case" + folder: "src/content/examples" + fields: + - name: "control_field" + label: "control string" + widget: "hidden" + - name: "single_quote_field" + label: "string containing ' quote" + widget: "hidden" + - name: "double_quote_field" + label: 'string containing " quote' + widget: "hidden" + - name: "tick_quote_field" + label: "string containing ` quote" + widget: "hidden" \ No newline at end of file diff --git a/src/utils/transform.utils.ts b/src/utils/transform.utils.ts index 2b74fe7..a0104df 100644 --- a/src/utils/transform.utils.ts +++ b/src/utils/transform.utils.ts @@ -61,10 +61,11 @@ export function applyDescription(field: Decap.CmsField, result: TransformResult) // derive potential description const description = field.hint ?? field.label ?? field.name; if (description === undefined) return result; + const safeDescription = description.replace(/'/g, "\\'"); // set a description return { - compiled: `${result.compiled}.describe('${description}')`, + compiled: `${result.compiled}.describe('${safeDescription}')`, dependencies: ['z', ...result.dependencies], }; }