Skip to content

Commit 7ebd6fa

Browse files
committed
Fix extra empty line issue on tutorial
1 parent 50a8807 commit 7ebd6fa

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/utils/syntax-highlight.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* This source file is part of the Swift.org open source project
33
*
4-
* Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
* Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
55
* Licensed under Apache License v2.0 with Runtime Library Exception
66
*
77
* See https://swift.org/LICENSE.txt for license information
@@ -192,7 +192,7 @@ function duplicateMultilineNode(element) {
192192

193193
// wrap each new line with the current element's class
194194
const result = getLines(element.innerHTML)
195-
.reduce((all, lineText) => `${all}<span class="${className}">${lineText || '\n\n'}</span>\n`, '');
195+
.reduce((all, lineText) => `${all}<span class="${className}">${lineText || ''}</span>\n`, '');
196196

197197
// return a list of newly wrapped HTML elements
198198
return htmlToElements(result.trim());

tests/unit/utils/syntax-highlight.spec.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,11 @@ describe("syntax-highlight", () => {
107107
expect(sanitizedCode).toMatchInlineSnapshot(`
108108
<span class="syntax-keyword">let</span> multiline = <span class="syntax-string">""</span><span class="syntax-string">"</span>
109109
<span class="syntax-string">Needs</span>
110-
<span class="syntax-string">
111-
112-
</span>
110+
<span class="syntax-string"></span>
113111
<span class="syntax-string">Spaces</span>
114-
<span class="syntax-string">
115-
116-
</span>
112+
<span class="syntax-string"></span>
117113
<span class="syntax-string">Between</span>
118-
<span class="syntax-string">
119-
120-
</span>
114+
<span class="syntax-string"></span>
121115
<span class="syntax-string">Lines</span>
122116
<span class="syntax-string">"</span><span class="syntax-string">""</span>
123117
`);

0 commit comments

Comments
 (0)