Skip to content

tweak code fonts #798

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

Closed
wants to merge 3 commits into from
Closed
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
9 changes: 4 additions & 5 deletions lib/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Documentation {
String tempHtml = renderMarkdownToHtml(raw, element);
_asHtmlDocument = parse(tempHtml);
_asHtmlDocument.querySelectorAll('script').forEach((s) => s.remove());
_asHtmlDocument.querySelectorAll('code').forEach((e) {
_asHtmlDocument.querySelectorAll('pre').forEach((e) {
e.classes.addAll(['prettyprint', 'lang-dart']);
});
_asHtml = _asHtmlDocument.body.innerHtml;
Expand Down Expand Up @@ -98,9 +98,6 @@ class _InlineCodeSyntax extends md.InlineSyntax {
@override
bool onMatch(md.InlineParser parser, Match match) {
var element = new md.Element.text('code', htmlEscape(match[1]));
var c = element.attributes.putIfAbsent("class", () => "");
c = (c.isEmpty ? "" : " ") + "prettyprint";
element.attributes["class"] = c;
parser.addNode(element);
return true;
}
Expand All @@ -124,7 +121,9 @@ NodeList<CommentReference> _getCommentRefs(ModelElement modelElement) {
if (modelElement.element.node is AnnotatedNode) {
if ((modelElement.element.node as AnnotatedNode).documentationComment !=
null) {
return (modelElement.element.node as AnnotatedNode).documentationComment.references;
return (modelElement.element.node as AnnotatedNode)
.documentationComment
.references;
}
} else if (modelElement.element is LibraryElement) {
// handle anonymous libraries
Expand Down
7 changes: 2 additions & 5 deletions lib/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ a, a:hover {
color: #1976D2;
}

pre {
pre.prettyprint {
font-family: 'Source Code Pro', monospace;
color: black;
border-radius: 4px;
Expand All @@ -146,11 +146,8 @@ pre code {
code {
font-family: 'Source Code Pro', monospace;
/* overriding bootstrap */
font-size: 15px;
color: inherit;
border-radius: 0;
padding: 0;
background-color: inherit;
background-color: #f7f7f7;
}

@media(max-width: 768px) {
Expand Down
37 changes: 14 additions & 23 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,11 @@ void main() {
});

test('codeifies a class from the SDK', () {
expect(docsAsHtml,
contains('<code class="prettyprint lang-dart">String</code>'));
expect(docsAsHtml, contains('<code>String</code>'));
});

test('codeifies a reference to its parameter', () {
expect(docsAsHtml,
contains('<code class="prettyprint lang-dart">value</code>'));
expect(docsAsHtml, contains('<code>value</code>'));
});

test('links to a reference to its class', () {
Expand Down Expand Up @@ -292,9 +290,7 @@ void main() {
// track when the behavior changes
test('codeifies a prefixed top-level variable an imported lib', () {
expect(
docsAsHtml,
contains(
'<code class="prettyprint lang-dart">css.theOnlyThingInTheLibrary</code>'));
docsAsHtml, contains('<code>css.theOnlyThingInTheLibrary</code>'));
});

test('links to a name with a single underscore', () {
Expand Down Expand Up @@ -325,7 +321,7 @@ void main() {
expect(
add.oneLineDoc,
equals(
'Adds <code class="prettyprint lang-dart">value</code> to the end of this list,\nextending the length by one.'));
'Adds <code>value</code> to the end of this list,\nextending the length by one.'));
});

test(
Expand All @@ -336,17 +332,17 @@ void main() {
expect(
add.documentationAsHtml,
startsWith(
'<p>Adds <code class="prettyprint lang-dart">value</code> to the end of this list,\nextending the length by one.'));
'<p>Adds <code>value</code> to the end of this list,\nextending the length by one.'));
});

test('incorrect doc references are still wrapped in code blocks', () {
expect(incorrectReference.documentationAsHtml,
'<p>This should <code class="prettyprint lang-dart">not work</code>.</p>');
'<p>This should <code>not work</code>.</p>');
});

test('no references', () {
expect(Apple.documentationAsHtml,
'<p>Sample class <code class="prettyprint lang-dart">String</code></p>');
expect(
Apple.documentationAsHtml, '<p>Sample class <code>String</code></p>');
});

test('single ref to class', () {
Expand All @@ -358,7 +354,7 @@ void main() {
expect(
thisIsAsync.documentationAsHtml,
equals(
'<p>An async function. It should look like I return a <code class="prettyprint lang-dart">Future</code>.</p>'));
'<p>An async function. It should look like I return a <code>Future</code>.</p>'));
});

test('references are correct in exported libraries', () {
Expand All @@ -368,10 +364,7 @@ void main() {
expect(resolved, isNotNull);
expect(resolved,
contains('<a href="two_exports/BaseClass-class.html">BaseClass</a>'));
expect(
resolved,
contains(
'linking over to <code class="prettyprint lang-dart">Apple</code>.'));
expect(resolved, contains('linking over to <code>Apple</code>.'));
});

test('references to class and constructors', () {
Expand Down Expand Up @@ -403,16 +396,14 @@ void main() {
expect(
testingCodeSyntaxInOneLiners.oneLineDoc,
equals(
'These are code syntaxes: <code class="prettyprint lang-dart">true</code> and <code class="prettyprint lang-dart">false</code>'));
'These are code syntaxes: <code>true</code> and <code>false</code>'));
});

test('doc comments to parameters are marked as code', () {
Method localMethod = subForDocComments.instanceMethods
.firstWhere((m) => m.name == 'localMethod');
expect(localMethod.documentationAsHtml,
contains('<code class="prettyprint lang-dart">foo</code>'));
expect(localMethod.documentationAsHtml,
contains('<code class="prettyprint lang-dart">bar</code>'));
expect(localMethod.documentationAsHtml, contains('<code>foo</code>'));
expect(localMethod.documentationAsHtml, contains('<code>bar</code>'));
});
});

Expand Down Expand Up @@ -668,7 +659,7 @@ void main() {
expect(
thisIsAsync.documentationAsHtml,
equals(
'<p>An async function. It should look like I return a <code class="prettyprint lang-dart">Future</code>.</p>'));
'<p>An async function. It should look like I return a <code>Future</code>.</p>'));
});

test('docs do not lose brackets in code blocks', () {
Expand Down