From ef03fe605848bc11e4ccb84dc0f7a10cc0252809 Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 25 Nov 2024 18:07:20 +0100 Subject: [PATCH] Allow newlines in strings by special casing "\n" --- src/app/components/generator/McdocRenderer.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index cad58505..ed5ec250 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -135,7 +135,7 @@ const SPECIAL_UNSET = '__unset__' function StringHead({ type, optional, node, ctx }: Props) { const { locale } = useLocale() - const value = JsonStringNode.is(node) ? node.value : undefined + const value = (JsonStringNode.is(node) ? node.value : undefined)?.replaceAll('\n', '\\n') const idAttribute = type.attributes?.find(a => a.name === 'id')?.value const idRegistry = idAttribute?.kind === 'literal' && idAttribute.value.kind === 'string' @@ -149,6 +149,7 @@ function StringHead({ type, optional, node, ctx }: Props) { const isSelect = idRegistry && isSelectRegistry(idRegistry) const onChangeValue = useCallback((newValue: string) => { + newValue = newValue.replaceAll('\\n', '\n') if (value === newValue) { return }