Skip to content

Commit 2be72fa

Browse files
committed
Fix line break rendering
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.
1 parent a9608b7 commit 2be72fa

File tree

1 file changed

+4
-2
lines changed
  • x-pack/plugins/apm/public/components/shared/Stacktrace

1 file changed

+4
-2
lines changed

x-pack/plugins/apm/public/components/shared/Stacktrace/Context.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ function getStackframeLines(stackframe: StackframeWithLineContext) {
9898
const line = stackframe.line.context;
9999
const preLines = stackframe.context?.pre || [];
100100
const postLines = stackframe.context?.post || [];
101-
return [...preLines, line, ...postLines];
101+
return [...preLines, line, ...postLines].map(
102+
(x) => (x.endsWith('\n') ? x.slice(0, -1) : x) || ' '
103+
);
102104
}
103105

104106
function getStartLineNumber(stackframe: StackframeWithLineContext) {
@@ -138,7 +140,7 @@ export function Context({ stackframe, codeLanguage, isLibraryFrame }: Props) {
138140
CodeTag={Code}
139141
customStyle={{ padding: null, overflowX: null }}
140142
>
141-
{line || '\n'}
143+
{line}
142144
</SyntaxHighlighter>
143145
))}
144146
</LineContainer>

0 commit comments

Comments
 (0)