Skip to content

Commit c9bb363

Browse files
chalindevoncarew
authored andcommitted
@example: set default prettify lang based on file extension (#1306)
(This completes this subfeature implementation.)
1 parent f6b9624 commit c9bb363

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
lines changed

lib/src/model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
17551755
RegExp exampleRE = new RegExp(r'{@example\s+([^}]+)}');
17561756
return rawdocs.replaceAllMapped(exampleRE, (match) {
17571757
var args = _getExampleArgs(match[1]);
1758-
var lang = args['lang'] ?? p.extension(args['src']);
1758+
var lang = args['lang'] ?? p.extension(args['src']).replaceFirst('.','');
17591759

17601760
var replacement = match[0]; // default to fully matched string.
17611761

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```
2+
<h1>Hello <b>World</b>!</h1>
3+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
```
2-
<h1>Hello <b>World</b>!</h1>
2+
var test = 1;
33
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```
2+
<h1>Hello <b>World</b>!</h1>
3+
```

testing/test_package/lib/example.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ class ConstantCat implements Cat {
210210
/// {@example dog/food}
211211
/// {@example dog/food.txt region=meat}
212212
///
213-
/// {@example test.dart region= lang=html}
213+
/// {@example test.html}
214+
///
215+
/// {@example test.dart region=template lang=html}
216+
///
217+
/// {@example test.dart region=}
218+
///
219+
/// {@example test.dart region= lang=}
214220
class Dog implements Cat, E {
215221
String name;
216222

testing/test_package_docs/ex/Dog-class.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
142142
<p>Some text with <strong>bold</strong> remarks.
143143
A selection of dog flavors:</p><ul><li>beef</li><li>poultry</li></ul>
144144
<pre class="language-html prettyprint"><code class="language-html">&lt;h1&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/h1&gt;
145+
</code></pre>
146+
<pre class="language-html prettyprint"><code class="language-html">&lt;h1&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/h1&gt;
147+
</code></pre>
148+
<pre class="language-dart prettyprint"><code class="language-dart">var test = 1;
149+
</code></pre>
150+
<pre class="prettyprint language-dart"><code>var test = 1;
145151
</code></pre>
146152
</section>
147153

0 commit comments

Comments
 (0)