From df8f390848d7a8e03193d64e460142e00ed95031 Mon Sep 17 00:00:00 2001 From: Jacob <64662184+aarthificial@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:22:56 +0200 Subject: [PATCH] fix: display newlines in Code correctly (#38) Temporarily fixes the problem with newlines not being taken into account when rendering the Code component. If a newline is placed inside a JSX context, PrismJS generates a token of type "plain-text" instead of a simple string. In the future, newlines inside any token type should be accounted for. --- src/components/code/Code.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/code/Code.tsx b/src/components/code/Code.tsx index edcfcc7c..60bf9a87 100644 --- a/src/components/code/Code.tsx +++ b/src/components/code/Code.tsx @@ -288,7 +288,11 @@ export class Code extends Text { context.fillText(line, x * letterWidth, (y + 0.5) * lineHeight); x += line.length; } - } else if (typeof token.content === 'string') { + } else if ( + typeof token.content === 'string' && + // FIXME Handle newlines no matter the token type + token.type !== 'plain-text' + ) { if (!(token.type in colors)) { console.warn(`Unstyled token type:`, token.type); }