Skip to content

Commit 3b4cd0c

Browse files
authored
Generate anchors for headers in markdown (#1749)
* Fix anchors * dartfmt * verify id in unit test * Empty revision to trigger cla/google retry
1 parent 5974085 commit 3b4cd0c

File tree

9 files changed

+36
-20
lines changed

9 files changed

+36
-20
lines changed

lib/src/markdown_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ final HtmlEscape htmlEscape = const HtmlEscape(HtmlEscapeMode.element);
144144
final List<md.InlineSyntax> _markdown_syntaxes = [
145145
new _InlineCodeSyntax(),
146146
new _AutolinkWithoutScheme()
147-
]..addAll(md.ExtensionSet.gitHubFlavored.inlineSyntaxes);
147+
]..addAll(md.ExtensionSet.gitHubWeb.inlineSyntaxes);
148148

149149
final List<md.BlockSyntax> _markdown_block_syntaxes = []
150-
..addAll(md.ExtensionSet.gitHubFlavored.blockSyntaxes);
150+
..addAll(md.ExtensionSet.gitHubWeb.blockSyntaxes);
151151

152152
// Remove these schemas from the display text for hyperlinks.
153153
final RegExp _hide_schemes = new RegExp('^(http|https)://');

test/compare_output_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ Uri get _currentFileUri =>
2323

2424
String get _testPackageDocsPath {
2525
if (Platform.version.split(' ').first.contains('-')) {
26-
return pathLib.fromUri(_currentFileUri.resolve('../testing/test_package_docs_dev'));
26+
return pathLib
27+
.fromUri(_currentFileUri.resolve('../testing/test_package_docs_dev'));
2728
} else {
28-
return pathLib.fromUri(_currentFileUri.resolve('../testing/test_package_docs'));
29+
return pathLib
30+
.fromUri(_currentFileUri.resolve('../testing/test_package_docs'));
2931
}
3032
}
3133

test/model_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void main() {
250250

251251
test('documentation can be rendered as HTML', () {
252252
expect(packageGraph.defaultPackage.documentationAsHtml,
253-
contains('<h1>Best Package</h1>'));
253+
contains('<h1 id="best-package">Best Package</h1>'));
254254
});
255255

256256
test('sdk name', () {

testing/test_package/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Best Package
22

3+
* [Examples](#examples)
4+
* [Another Section](#another-section)
5+
36
This is an amazing package.
47

8+
9+
## Examples
10+
511
For example, it:
612

713
* Is very fast
@@ -56,6 +62,8 @@ var f = function(a, b) {
5662
};
5763
```
5864

65+
## Another Section
66+
5967
It sometimes generates warnings in commentRefs like this: [unknownThingy.FromSomewhere]
6068

6169
Be sure to check out other awesome packages on [pub][].

testing/test_package_docs/fake/fake-library.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ <h5><span class="package-name">test_package</span> <span class="package-kind">pa
6161
<h1>fake library</h1>
6262

6363
<section class="desc markdown">
64-
<h1>WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a></h1>
64+
<h1 id="wow-fake-package-is-__best__-packagepkg">WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a></h1>
6565
<p>If you don't have this package yet, get it.
6666
Don't ask questions.</p>
6767
<p>Testing code <code>true</code> and <code>false</code></p>
6868
<p>Testing string escaping: <code>var s = 'I am a string'</code></p>
6969
<p>My favorite class is <a href="fake/Cool-class.html">Cool</a>.</p>
70-
<h2>I am an h2</h2>
70+
<h2 id="i-am-an-h2">I am an h2</h2>
7171
<p>hello there</p>
72-
<h3>I am an h3</h3>
72+
<h3 id="i-am-an-h3">I am an h3</h3>
7373
<p>hello there</p>
74-
<h4>I am an h4</h4>
74+
<h4 id="i-am-an-h4">I am an h4</h4>
7575
<p>hello there</p>
76-
<h5>I am an h5</h5>
76+
<h5 id="i-am-an-h5">I am an h5</h5>
7777
<p>hello</p>
7878
<p><em>Why should you get this package?</em></p><ul><li>We told you so.</li><li>Everyone is doing it.</li><li>It smells nice.</li></ul>
7979
<pre class="language-dart"><code>class Foo {

testing/test_package_docs/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ <h5><span class="package-name">test_package</span> <span class="package-kind">pa
5656

5757
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
5858
<section class="desc markdown">
59-
<h1>Best Package</h1>
59+
<h1 id="best-package">Best Package</h1><ul><li><a href="#examples">Examples</a></li><li><a href="#another-section">Another Section</a></li></ul>
6060
<p>This is an amazing package.</p>
61+
<h2 id="examples">Examples</h2>
6162
<p>For example, it:</p><ul><li>Is very fast</li><li>Has zero bugs</li><li>Is free</li></ul>
6263
<p>It also has some awesome code</p>
6364
<pre class="language-dart"><code class="language-dart">void main() {
@@ -96,6 +97,7 @@ <h1>Best Package</h1>
9697
return a + b;
9798
};
9899
</code></pre>
100+
<h2 id="another-section">Another Section</h2>
99101
<p>It sometimes generates warnings in commentRefs like this: <code>unknownThingy.FromSomewhere</code></p>
100102
<p>Be sure to check out other awesome packages on <a href="https://pub.dartlang.org">pub</a>.</p>
101103
</section>

testing/test_package_docs_dev/fake/fake-library.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ <h5><span class="package-name">test_package</span> <span class="package-kind">pa
6161
<h1>fake library</h1>
6262

6363
<section class="desc markdown">
64-
<h1>WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a></h1>
64+
<h1 id="wow-fake-package-is-__best__-packagepkg">WOW FAKE PACKAGE IS <strong>BEST</strong> <a href="http://example.org">PACKAGE</a></h1>
6565
<p>If you don't have this package yet, get it.
6666
Don't ask questions.</p>
6767
<p>Testing code <code>true</code> and <code>false</code></p>
6868
<p>Testing string escaping: <code>var s = 'I am a string'</code></p>
6969
<p>My favorite class is <a href="fake/Cool-class.html">Cool</a>.</p>
70-
<h2>I am an h2</h2>
70+
<h2 id="i-am-an-h2">I am an h2</h2>
7171
<p>hello there</p>
72-
<h3>I am an h3</h3>
72+
<h3 id="i-am-an-h3">I am an h3</h3>
7373
<p>hello there</p>
74-
<h4>I am an h4</h4>
74+
<h4 id="i-am-an-h4">I am an h4</h4>
7575
<p>hello there</p>
76-
<h5>I am an h5</h5>
76+
<h5 id="i-am-an-h5">I am an h5</h5>
7777
<p>hello</p>
7878
<p><em>Why should you get this package?</em></p><ul><li>We told you so.</li><li>Everyone is doing it.</li><li>It smells nice.</li></ul>
7979
<pre class="language-dart"><code>class Foo {

testing/test_package_docs_dev/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ <h5><span class="package-name">test_package</span> <span class="package-kind">pa
5656

5757
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
5858
<section class="desc markdown">
59-
<h1>Best Package</h1>
59+
<h1 id="best-package">Best Package</h1><ul><li><a href="#examples">Examples</a></li><li><a href="#another-section">Another Section</a></li></ul>
6060
<p>This is an amazing package.</p>
61+
<h2 id="examples">Examples</h2>
6162
<p>For example, it:</p><ul><li>Is very fast</li><li>Has zero bugs</li><li>Is free</li></ul>
6263
<p>It also has some awesome code</p>
6364
<pre class="language-dart"><code class="language-dart">void main() {
@@ -96,6 +97,7 @@ <h1>Best Package</h1>
9697
return a + b;
9798
};
9899
</code></pre>
100+
<h2 id="another-section">Another Section</h2>
99101
<p>It sometimes generates warnings in commentRefs like this: <code>unknownThingy.FromSomewhere</code></p>
100102
<p>Be sure to check out other awesome packages on <a href="https://pub.dartlang.org">pub</a>.</p>
101103
</section>

tool/grind.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,9 +879,11 @@ testDartdocFlutterPlugin() async {
879879
@Task('update test_package_docs')
880880
updateTestPackageDocs() async {
881881
var launcher = new SubprocessLauncher('update-test-package-docs');
882-
var testPackageDocs =
883-
new Directory(pathLib.join('testing',
884-
Platform.version.split(' ').first.contains('-') ? 'test_package_docs_dev' :'test_package_docs'));
882+
var testPackageDocs = new Directory(pathLib.join(
883+
'testing',
884+
Platform.version.split(' ').first.contains('-')
885+
? 'test_package_docs_dev'
886+
: 'test_package_docs'));
885887
var testPackage = new Directory(pathLib.join('testing', 'test_package'));
886888
await launcher.runStreamed(sdkBin('pub'), ['get'],
887889
workingDirectory: testPackage.path);

0 commit comments

Comments
 (0)