Skip to content

Commit 60c093b

Browse files
jcollins-gdevoncarew
authored andcommitted
Strip scheme (#1294)
* Add _AutolinkWithoutScheme * Update test docs for new behavior of fake library * Local pubspec change * Update version to 0.9.9 and regen docs * dartfmt for markdown_processor.dart * fix merge conflict notes that got left behind * Adjust offset in crossdart test... doesn't seem to work * clean up pubspec.yaml * Dynamically compute offset for crossdartify test * regenerate docs * pubspec.lock minimally updated
1 parent 77d1264 commit 60c093b

File tree

9 files changed

+43
-7
lines changed

9 files changed

+43
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.9+1
2+
* Add support for stripping schema from display text for urls defined with
3+
brackets (#1147)
4+
15
## 0.9.9
26
* resolve non-imported symbols in comments (#1153) - thanks @astashov!
37
* support `@example` insertion of .md file fragments (#1105) - thanks @chalin!

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export 'src/package_meta.dart';
4040

4141
const String name = 'dartdoc';
4242
// Update when pubspec version changes.
43-
const String version = '0.9.9';
43+
const String version = '0.9.9+1';
4444

4545
final String defaultOutDir = path.join('doc', 'api');
4646

lib/src/markdown_processor.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ final nonHTMLRegexp = new RegExp("</?(?!(${validHtmlTags.join("|")})[> ])\\w+[>
3636
// We don't emit warnings currently: #572.
3737
const List<String> _oneLinerSkipTags = const ["code", "pre"];
3838

39-
final List<md.InlineSyntax> _markdown_syntaxes = [new _InlineCodeSyntax()];
39+
final List<md.InlineSyntax> _markdown_syntaxes = [
40+
new _InlineCodeSyntax(),
41+
new _AutolinkWithoutScheme()
42+
];
43+
44+
// Remove these schemas from the display text for hyperlinks.
45+
final RegExp _hide_schemes = new RegExp('^(http|https)://');
4046

4147
class MatchingLinkResult {
4248
final ModelElement element;
@@ -307,3 +313,16 @@ class _InlineCodeSyntax extends md.InlineSyntax {
307313
return true;
308314
}
309315
}
316+
317+
class _AutolinkWithoutScheme extends md.AutolinkSyntax {
318+
@override
319+
bool onMatch(md.InlineParser parser, Match match) {
320+
var url = match[1];
321+
var text = md.escapeHtml(url).replaceFirst(_hide_schemes, '');
322+
var anchor = new md.Element.text('a', text);
323+
anchor.attributes['href'] = url;
324+
parser.addNode(anchor);
325+
326+
return true;
327+
}
328+
}

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ packages:
120120
name: markdown
121121
url: "https://pub.dartlang.org"
122122
source: hosted
123-
version: "0.11.1"
123+
version: "0.11.2"
124124
matcher:
125125
description:
126126
name: matcher

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dartdoc
22
# Also update the `version` field in lib/dartdoc.dart.
3-
version: 0.9.9
3+
version: 0.9.9+1
44
author: Dart Team <[email protected]>
55
description: A documentation generator for Dart.
66
homepage: https://github.com/dart-lang/dartdoc
@@ -15,7 +15,7 @@ dependencies:
1515
# least version 3.0.3 to work around an issue with 3.0.2.
1616
http_parser: '>=3.0.3 <4.0.0'
1717
logging: '>=0.9.0 <0.12.0'
18-
markdown: ^0.11.1
18+
markdown: ^0.11.2
1919
mustache4dart: ^1.0.9
2020
package_config: '>=0.1.5 <2.0.0'
2121
path: ^1.3.0

test/model_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,20 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
10101010
test('method source code crossdartifies correctly', () {
10111011
convertToMap.clearSourceCodeCache();
10121012
var fakePath = "testing/test_package/lib/fake.dart";
1013+
var offset = new File(fakePath)
1014+
.readAsStringSync()
1015+
.indexOf('Map<X, Y> convertToMap');
1016+
expect(offset, isNonNegative,
1017+
reason: "Can't find convertToMap function in ${fakePath}");
10131018
if (Platform.isWindows) fakePath = fakePath.replaceAll('/', r'\\');
10141019
new File(p.join(Directory.current.path, "crossdart.json"))
10151020
.writeAsStringSync("""
10161021
{"$fakePath":
1017-
{"references":[{"offset":1069,"end":1072,"remotePath":"http://www.example.com/fake.dart"}]}}
1022+
{"references":[{"offset":${offset},"end":${offset+3},"remotePath":"http://www.example.com/fake.dart"}]}}
10181023
""");
10191024

10201025
initializeConfig(addCrossdart: true, inputDir: Directory.current);
1026+
10211027
expect(convertToMap.sourceCode,
10221028
"<a class='crossdart-link' href='http://www.example.com/fake.dart'>Map</a>&lt;X, Y&gt; convertToMap() =&gt; null;");
10231029
});

testing/test_package/lib/fake.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
/// }
3838
/// ```
3939
///
40+
/// Here are some hyperlinks with angle brackets:
41+
///
42+
/// * <https://myfakepackage.com/withapath>
43+
/// * <ftp://ftp.myfakepackage.com/donthidemyschema>
44+
/// * <http://myfakepackage.com/buthidethisone>
45+
///
4046
/// [pkg]: http://example.org
4147
library fake;
4248

testing/test_package_docs/fake/fake-library.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ <h5>I am an h5</h5>
111111
long line is very long long line is very long long line is very long line long line long line
112112
}
113113
</code></pre>
114+
<p>Here are some hyperlinks with angle brackets:</p><ul><li><a href="https://myfakepackage.com/withapath">myfakepackage.com/withapath</a></li><li><a href="ftp://ftp.myfakepackage.com/donthidemyschema">ftp://ftp.myfakepackage.com/donthidemyschema</a></li><li><a href="http://myfakepackage.com/buthidethisone">myfakepackage.com/buthidethisone</a></li></ul>
114115
</section>
115116

116117
<section class="summary offset-anchor" id="constants">

testing/test_package_docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<meta name="generator" content="made with love by dartdoc 0.9.9">
7+
<meta name="generator" content="made with love by dartdoc 0.9.9+1">
88
<meta name="description" content="test_package API docs, for the Dart programming language.">
99
<title>test_package - Dart API docs</title>
1010

0 commit comments

Comments
 (0)