File tree Expand file tree Collapse file tree 6 files changed +27
-34
lines changed Expand file tree Collapse file tree 6 files changed +27
-34
lines changed Original file line number Diff line number Diff line change 23
23
</Filename >
24
24
<div class =" container-general" >
25
25
<!-- Do not add newlines in <pre>, as they'll appear in the rendered HTML. -->
26
- <pre ><CodeBlock ><span
26
+ <pre ><CodeBlock ><template
27
27
v-for =" (line , index ) in syntaxHighlightedLines "
28
- :class = " ['code-line-container',{ highlighted: isHighlighted(index) }] "
28
+ >< span
29
29
:key =" index"
30
+ :class =" ['code-line-container',{ highlighted: isHighlighted(index) }]"
30
31
><span
31
- v-show =" showLineNumbers" class =" code-number"
32
+ v-if =" showLineNumbers"
33
+ class =" code-number"
32
34
:data-line-number =" lineNumberFor(index)"
33
- />
34
- < span
35
- class = " code- line"
36
- v-html = " line"
37
- /></ span ></CodeBlock ></pre >
35
+ />< span
36
+ class = " code-line "
37
+ v-html = " line"
38
+ /></ span > <!-- This new line must stay -->
39
+ </ template ></CodeBlock ></pre >
38
40
</div >
39
41
</div >
40
42
</template >
@@ -128,10 +130,13 @@ export default {
128
130
@import ' docc-render/styles/_core.scss' ;
129
131
130
132
.code-line-container {
131
- display : flex ;
133
+ display : inline-block ;
134
+ width : 100% ;
135
+ box-sizing : border-box ;
132
136
}
133
137
134
138
.code-number {
139
+ display : inline-block ;
135
140
padding : $code-number-padding ;
136
141
text-align : right ;
137
142
min-width : 2em ;
@@ -167,18 +172,11 @@ pre {
167
172
}
168
173
169
174
code {
170
- display : flex ;
171
- flex-direction : column ;
172
175
white-space : pre ;
173
176
word-wrap : normal ;
174
177
flex-grow : 9999 ;
175
178
}
176
179
177
- .code-line-container {
178
- flex-shrink : 0 ;
179
- padding-right : 14px ;
180
- }
181
-
182
180
.code-listing ,
183
181
.container-general {
184
182
display : flex ;
Original file line number Diff line number Diff line change @@ -47,8 +47,6 @@ $docs-code-listing-border-width: 1px !default;
47
47
48
48
pre {
49
49
padding : var (--code-block-style-elements-padding );
50
- // setting it to 0 prevents browsers from adding extra right spacing, when having scrollbar
51
- padding-right : 0 ;
52
50
53
51
> code {
54
52
@include font-styles (documentation- code- listing);
Original file line number Diff line number Diff line change @@ -178,7 +178,7 @@ export default {
178
178
this .shouldDisplayHideLabel
179
179
? this .$t (' verbs.hide' )
180
180
: this .$t (' verbs.show' )
181
- } ` ;
181
+ } ` ;
182
182
},
183
183
},
184
184
methods: {
@@ -227,6 +227,11 @@ $duration: 0.2s;
227
227
228
228
/deep / .code-listing {
229
229
color : var (--text , var (--color-code-plain ));
230
+
231
+ .code-line-container {
232
+ // add extra padding, so we have extra space on right when scrolling is needed
233
+ padding-right : 14px ;
234
+ }
230
235
}
231
236
232
237
/deep / pre {
Original file line number Diff line number Diff line change 1
1
/**
2
2
* This source file is part of the Swift.org open source project
3
3
*
4
- * Copyright (c) 2021 Apple Inc. and the Swift project authors
4
+ * Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
5
5
* Licensed under Apache License v2.0 with Runtime Library Exception
6
6
*
7
7
* See https://swift.org/LICENSE.txt for license information
@@ -192,7 +192,7 @@ function duplicateMultilineNode(element) {
192
192
193
193
// wrap each new line with the current element's class
194
194
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` , '' ) ;
196
196
197
197
// return a list of newly wrapped HTML elements
198
198
return htmlToElements ( result . trim ( ) ) ;
Original file line number Diff line number Diff line change @@ -55,9 +55,8 @@ describe('CodeListing', () => {
55
55
expect ( listing . attributes ( 'data-syntax' ) ) . toBe ( 'swift' ) ;
56
56
57
57
const codeLineContainer = listing . find ( 'span.code-line-container' ) ;
58
- const codeNumber = codeLineContainer . find ( '.code-number' ) ;
59
- // Code Number content should be empty to not get copied during user select
60
- expect ( codeNumber . text ( ) ) . toBe ( '' ) ;
58
+ // Code Number content should not be rendered, if not needed
59
+ expect ( codeLineContainer . find ( '.code-number' ) . exists ( ) ) . toBe ( false ) ;
61
60
62
61
const codeLine = codeLineContainer . find ( '.code-line' ) ;
63
62
expect ( codeLine . text ( ) ) . toBe ( 'hello' ) ;
@@ -88,7 +87,6 @@ describe('CodeListing', () => {
88
87
const shouldBeHighlighted = highlights . map ( h => h . line ) . includes ( index + 1 ) ;
89
88
90
89
const codeNumber = codeLineContainer . find ( '.code-number' ) ;
91
- // expect(codeNumber.text()).toBe(`${index + 1}`);
92
90
93
91
expect ( codeNumber . attributes ( 'data-line-number' ) ) . toBe ( `${ index + 1 } ` ) ;
94
92
Original file line number Diff line number Diff line change @@ -107,17 +107,11 @@ describe("syntax-highlight", () => {
107
107
expect ( sanitizedCode ) . toMatchInlineSnapshot ( `
108
108
<span class="syntax-keyword">let</span> multiline = <span class="syntax-string">""</span><span class="syntax-string">"</span>
109
109
<span class="syntax-string">Needs</span>
110
- <span class="syntax-string">
111
-
112
- </span>
110
+ <span class="syntax-string"></span>
113
111
<span class="syntax-string">Spaces</span>
114
- <span class="syntax-string">
115
-
116
- </span>
112
+ <span class="syntax-string"></span>
117
113
<span class="syntax-string">Between</span>
118
- <span class="syntax-string">
119
-
120
- </span>
114
+ <span class="syntax-string"></span>
121
115
<span class="syntax-string">Lines</span>
122
116
<span class="syntax-string">"</span><span class="syntax-string">""</span>
123
117
` ) ;
You can’t perform that action at this time.
0 commit comments