Skip to content

Commit

Permalink
Fix line break rendering
Browse files Browse the repository at this point in the history
The old version of react-syntax-highlighter would ignore newline
characters. This version renders them in the DOM instead. I had to
update a component to remove newline characters from the ends of
line strings so they would render as expected.
  • Loading branch information
jportner committed Dec 8, 2020
1 parent a9608b7 commit 2be72fa
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ function getStackframeLines(stackframe: StackframeWithLineContext) {
const line = stackframe.line.context;
const preLines = stackframe.context?.pre || [];
const postLines = stackframe.context?.post || [];
return [...preLines, line, ...postLines];
return [...preLines, line, ...postLines].map(
(x) => (x.endsWith('\n') ? x.slice(0, -1) : x) || ' '
);
}

function getStartLineNumber(stackframe: StackframeWithLineContext) {
Expand Down Expand Up @@ -138,7 +140,7 @@ export function Context({ stackframe, codeLanguage, isLibraryFrame }: Props) {
CodeTag={Code}
customStyle={{ padding: null, overflowX: null }}
>
{line || '\n'}
{line}
</SyntaxHighlighter>
))}
</LineContainer>
Expand Down

0 comments on commit 2be72fa

Please sign in to comment.