From 035b174af92fe201a1f61322ee6fc9d831f3ef6d Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Tue, 3 Feb 2026 14:00:14 -0300 Subject: [PATCH] fix: Adds support for superscript and subscript on Super pdf exports --- .../Lexical/Utils/PDFExport/PDFExport.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport/PDFExport.tsx b/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport/PDFExport.tsx index 4a6b78ab97b..3bc69be0dd7 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport/PDFExport.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/PDFExport/PDFExport.tsx @@ -33,6 +33,9 @@ import { getFontFamiliesFromLexicalNode, } from './FontConfig' +const PDF_SUPERSUBSCRIPT_FONT_SIZE = 9 +const PDF_HEADING_SUPERSUBSCRIPT_SCALE = 0.75 + const styles = StyleSheet.create({ page: { paddingVertical: 35, @@ -200,6 +203,8 @@ const getPDFDataNodeFromLexicalNode = ( const isBold = node.hasFormat('bold') const isItalic = node.hasFormat('italic') const isHighlight = node.hasFormat('highlight') + const isSuperscript = node.hasFormat('superscript') + const isSubscript = node.hasFormat('subscript') let fontFamily: FontFamily[] | FontFamily = FALLBACK_FONT_FAMILY if (isInlineCode && isCodeNodeText) { @@ -212,6 +217,15 @@ const getPDFDataNodeFromLexicalNode = ( } } + const baseFontSize = isInlineCode || isCodeNodeText ? 11 : undefined + const headingFontSize = $isHeadingNode(parent) ? getFontSizeForHeading(parent) : undefined + const fontSize = + isSuperscript || isSubscript + ? headingFontSize + ? Math.max(PDF_SUPERSUBSCRIPT_FONT_SIZE, Math.round(headingFontSize * PDF_HEADING_SUPERSUBSCRIPT_SCALE)) + : PDF_SUPERSUBSCRIPT_FONT_SIZE + : baseFontSize + return { type: 'Text', children: node.getTextContent(), @@ -226,8 +240,9 @@ const getPDFDataNodeFromLexicalNode = ( ? 'line-through' : undefined, backgroundColor: isInlineCode ? '#f1f1f1' : isHighlight ? 'rgb(255,255,0)' : undefined, - fontSize: isInlineCode || isCodeNodeText ? 11 : undefined, + fontSize, textAlign: $isElementNode(parent) ? getNodeTextAlignment(parent) : 'left', + verticalAlign: isSuperscript ? 'super' : isSubscript ? 'sub' : undefined, }, } }