Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cf77b82

Browse files
devoncarewcommit-bot@chromium.org
authored andcommitted
[analyzer] handle youtube and animation dartdoc directives
Change-Id: I5bcad74803da2466c8a50160823c586f57e00ec1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99711 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Devon Carew <devoncarew@google.com>
1 parent 6384f62 commit cf77b82

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

pkg/analysis_server/lib/src/computer/computer_hover.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class DartUnitHoverComputer {
107107

108108
static String computeDocumentation(
109109
DartdocDirectiveInfo dartdocInfo, Element element) {
110-
// TODO(dantup) We're reusing this in parameter information - move it somewhere shared?
110+
// TODO(dantup) We're reusing this in parameter information - move it
111+
// somewhere shared?
111112
if (element is FieldFormalParameterElement) {
112113
element = (element as FieldFormalParameterElement).field;
113114
}

pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class DartdocDirectiveInfo {
1818
r'[ ]*{@template\s+(.+?)}([\s\S]+?){@endtemplate}[ ]*\n?',
1919
multiLine: true);
2020

21+
/// A regular expression used to match a youtube or animation directive.
22+
///
23+
/// These are in the form:
24+
/// `{@youtube 560 315 https://www.youtube.com/watch?v=2uaoEDOgk_I}`.
25+
static final videoRegExp =
26+
new RegExp(r'{@(youtube|animation)\s+[^}]+\s+[^}]+\s+([^}]+)}');
27+
2128
/// A table mapping the names of templates to the unprocessed bodies of the
2229
/// templates.
2330
final Map<String, String> templateMap = {};
@@ -45,8 +52,12 @@ class DartdocDirectiveInfo {
4552
}
4653
}
4754

48-
/// Process the given Dartdoc [comment], replacing any macro directives with
49-
/// the body of the corresponding template.
55+
/// Process the given Dartdoc [comment], replacing any known dartdoc
56+
/// directives with the associated content.
57+
///
58+
/// Macro directives are replaced with the body of the corresponding template.
59+
///
60+
/// Youtube and animation directives are replaced with markdown hyperlinks.
5061
String processDartdoc(String comment) {
5162
List<String> lines = _stripDelimiters(comment);
5263
for (int i = lines.length - 1; i >= 0; i--) {
@@ -58,6 +69,20 @@ class DartdocDirectiveInfo {
5869
if (value != null) {
5970
lines[i] = value;
6071
}
72+
continue;
73+
}
74+
75+
match = videoRegExp.firstMatch(line);
76+
if (match != null) {
77+
String uri = match.group(2);
78+
if (uri != null && uri.isNotEmpty) {
79+
String label = uri;
80+
if (label.startsWith('https://')) {
81+
label = label.substring('https://'.length);
82+
}
83+
lines[i] = '[$label]($uri)';
84+
}
85+
continue;
6186
}
6287
}
6388
return lines.join('\n');

pkg/analyzer/test/src/dartdoc/dartdoc_directive_info_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,30 @@ After macro.''');
8181
expect(result, '''
8282
Comment without a macro.''');
8383
}
84+
85+
test_processDartdoc_youtube_directive() {
86+
String result = info.processDartdoc('''
87+
/// {@youtube 560 315 https://www.youtube.com/watch?v=2uaoEDOgk_I}
88+
''');
89+
expect(result, '''
90+
[www.youtube.com/watch?v=2uaoEDOgk_I](https://www.youtube.com/watch?v=2uaoEDOgk_I)''');
91+
}
92+
93+
test_processDartdoc_youtube_malformed() {
94+
String result = info.processDartdoc('''
95+
/// {@youtube 560x315 https://www.youtube.com/watch?v=2uaoEDOgk_I}
96+
''');
97+
expect(result,
98+
'{@youtube 560x315 https://www.youtube.com/watch?v=2uaoEDOgk_I}');
99+
}
100+
101+
test_processDartdoc_animation_directive() {
102+
String result = info.processDartdoc('''
103+
/// {@animation 464 192 https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4}
104+
''');
105+
expect(
106+
result,
107+
'[flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4]'
108+
'(https://flutter.github.io/assets-for-api-docs/assets/animation/curve_bounce_in.mp4)');
109+
}
84110
}

0 commit comments

Comments
 (0)