Skip to content

@example: set default prettify lang based on file extension #1306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
RegExp exampleRE = new RegExp(r'{@example\s+([^}]+)}');
return rawdocs.replaceAllMapped(exampleRE, (match) {
var args = _getExampleArgs(match[1]);
var lang = args['lang'] ?? p.extension(args['src']);
var lang = args['lang'] ?? p.extension(args['src']).replaceFirst('.','');

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

Expand Down
3 changes: 3 additions & 0 deletions testing/test_package/examples/test-template.dart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
<h1>Hello <b>World</b>!</h1>
```
2 changes: 1 addition & 1 deletion testing/test_package/examples/test.dart.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```
<h1>Hello <b>World</b>!</h1>
var test = 1;
```
3 changes: 3 additions & 0 deletions testing/test_package/examples/test.html.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
<h1>Hello <b>World</b>!</h1>
```
8 changes: 7 additions & 1 deletion testing/test_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ class ConstantCat implements Cat {
/// {@example dog/food}
/// {@example dog/food.txt region=meat}
///
/// {@example test.dart region= lang=html}
/// {@example test.html}
///
/// {@example test.dart region=template lang=html}
///
/// {@example test.dart region=}
///
/// {@example test.dart region= lang=}
class Dog implements Cat, E {
String name;

Expand Down
6 changes: 6 additions & 0 deletions testing/test_package_docs/ex/Dog-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ <h5><a href="ex/ex-library.html">ex</a></h5>
<p>Some text with <strong>bold</strong> remarks.
A selection of dog flavors:</p><ul><li>beef</li><li>poultry</li></ul>
<pre class="language-html prettyprint"><code class="language-html">&lt;h1&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/h1&gt;
</code></pre>
<pre class="language-html prettyprint"><code class="language-html">&lt;h1&gt;Hello &lt;b&gt;World&lt;/b&gt;!&lt;/h1&gt;
</code></pre>
<pre class="language-dart prettyprint"><code class="language-dart">var test = 1;
</code></pre>
<pre class="prettyprint language-dart"><code>var test = 1;
</code></pre>
</section>

Expand Down