Skip to content

Commit c9b9f13

Browse files
committed
fix the display of long constants
1 parent 3b94e7c commit c9b9f13

File tree

9 files changed

+38
-25
lines changed

9 files changed

+38
-25
lines changed

lib/resources/styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ dl dt.callable .name {
305305
color: #4674a2;
306306
}
307307

308+
/* make sure constant values don't overflow */
309+
.signature code {
310+
white-space: nowrap;
311+
overflow-x: hidden;
312+
text-overflow: ellipsis;
313+
display: block;
314+
}
315+
308316
.optional {
309317
font-style: italic;
310318
}

lib/src/markdown_processor.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,33 +180,29 @@ class Documentation {
180180
for (var s in asHtmlDocument.querySelectorAll('script')) {
181181
s.remove();
182182
}
183-
for (var e in asHtmlDocument.querySelectorAll('pre')) {
184-
if (e.children.isNotEmpty &&
185-
e.children.length != 1 &&
186-
e.children.first.localName != 'code') {
183+
for (var pre in asHtmlDocument.querySelectorAll('pre')) {
184+
if (pre.children.isNotEmpty &&
185+
pre.children.length != 1 &&
186+
pre.children.first.localName != 'code') {
187187
continue;
188188
}
189189

190-
// TODO(kevmoo): This should be applied to <code>, not <pre>
191-
// Waiting on pkg/markdown v0.10
192-
// See https://github.com/dart-lang/markdown/commit/a7bf3dd
193-
e.classes.add('prettyprint');
194-
195-
// Only "assume" the user intended dart if there are no other classes
196-
// present.
197-
if (e.classes.length == 1) {
198-
e.classes.add('language-dart');
190+
if (pre.children.isNotEmpty && pre.children.first.localName == 'code') {
191+
var code = pre.children.first;
192+
pre.classes.addAll(code.classes.where((name) => name.startsWith('language-')));
199193
}
200-
}
201-
var asHtml = asHtmlDocument.body.innerHtml;
202194

203-
// Fixes issue with line ending differences between mac and windows.
204-
if (asHtml != null) asHtml = asHtml.trim();
195+
bool specifiesLanguage = pre.classes.isNotEmpty;
196+
pre.classes.add('prettyprint');
197+
// Assume the user intended Dart if there are no other classes present.
198+
if (!specifiesLanguage) pre.classes.add('language-dart');
199+
}
205200

201+
// `trim` fixes issue with line ending differences between mac and windows.
202+
var asHtml = asHtmlDocument.body.innerHtml?.trim();
206203
var asOneLiner = asHtmlDocument.body.children.isEmpty
207204
? ''
208205
: asHtmlDocument.body.children.first.innerHtml;
209-
210206
return new Documentation._(markdown, asHtml, asOneLiner);
211207
}
212208
}

testing/test_package/lib/fake.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const String UP = 'up';
105105

106106
const String NAME_SINGLEUNDERSCORE = 'yay bug hunting';
107107

108-
const String NAME_WITH_TWO_UNDERSCORES = 'episode seven better be good';
108+
const String NAME_WITH_TWO_UNDERSCORES = 'episode seven better be good; episode seven better be good; episode seven better be good; episode seven better be good';
109109

110110
/// Testing [NAME_WITH_TWO_UNDERSCORES] should not be italicized.
111111
///

testing/test_package_docs/code_in_comments/code_in_comments-library.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ <h5><a href="index.html">test_package</a></h5>
8383
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
8484

8585
<section class="desc markdown">
86-
<pre class="prettyprint language-dart"><code class="language-dart">void main() {
86+
<pre class="language-dart prettyprint"><code class="language-dart">void main() {
8787
// in Dart!
8888
}
8989
</code></pre>
90-
<pre class="prettyprint language-dart"><code class="language-yaml">and_yaml:
90+
<pre class="language-yaml prettyprint"><code class="language-yaml">and_yaml:
9191
- value
9292
- "value"
9393
- 3.14

testing/test_package_docs/fake/NAME_WITH_TWO_UNDERSCORES-constant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
146146

147147
<section class="multi-line-signature">
148148
<span class="name ">NAME_WITH_TWO_UNDERSCORES</span> =
149-
<span class="constant-value">&#39;episode seven better be good&#39;</span>
149+
<span class="constant-value">&#39;episode seven better be good; episode seven better be good; episode seven better be good; episode seven better be good&#39;</span>
150150
</section>
151151

152152

testing/test_package_docs/fake/fake-library.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ <h2>Constants</h2>
184184
<dd>
185185

186186
<div>
187-
<span class="signature"><code>&#39;episode seven better be good&#39;</code></span>
187+
<span class="signature"><code>&#39;episode seven better be good; episode seven better be good; episode seven better be good; episode seven better be good&#39;</code></span>
188188
</div>
189189
</dd>
190190
<dt id="PI" class="constant">

testing/test_package_docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ <h1>Best Package</h1>
8484
<p>This is an amazing package.</p>
8585
<p>For example, it:</p><ul><li>Is very fast</li><li>Has zero bugs</li><li>Is free</li></ul>
8686
<p>It also has some awesome code</p>
87-
<pre class="prettyprint language-dart"><code class="language-dart">void main() {
87+
<pre class="language-dart prettyprint"><code class="language-dart">void main() {
8888
// in Dart!
8989
}
9090
</code></pre>
91-
<pre class="prettyprint language-dart"><code class="language-yaml">and_yaml:
91+
<pre class="language-yaml prettyprint"><code class="language-yaml">and_yaml:
9292
- value
9393
- "value"
9494
- 3.14

testing/test_package_docs/static-assets/styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ dl dt.callable .name {
305305
color: #4674a2;
306306
}
307307

308+
/* make sure constant values don't overflow */
309+
.signature code {
310+
white-space: nowrap;
311+
overflow-x: hidden;
312+
text-overflow: ellipsis;
313+
display: block;
314+
}
315+
308316
.optional {
309317
font-style: italic;
310318
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ analyzer: { exclude: ['**'] } }

0 commit comments

Comments
 (0)