Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 8207632

Browse files
authored
Update API Docs
* add syntax highlighting to code samples. * style subsection descriptions * add dl library to page * fix markdown rendering of table in norm docs.
1 parent d52d023 commit 8207632

File tree

6 files changed

+97
-29
lines changed

6 files changed

+97
-29
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"cross-spawn": "~5.1.0",
2323
"fetch-mock": "~5.13.1",
2424
"handlebars": "~4.0.11",
25+
"highlight.js": "9.12.0",
2526
"http-server": "~0.10.0",
2627
"jasmine-core": "~2.6.4",
2728
"karma": "~1.7.0",

src/ops/norm.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ export class Ops {
3232
* @param x The input array.
3333
* @param ord Optional. Order of the norm. Supported norm types are
3434
* following:
35-
* ```
36-
* ord norm for matrices norm for vectors
37-
* -------------------------------------------------------
38-
* 'euclidean' Frobenius norm 2-norm
39-
* fro Frobenius norm
40-
* Infinity max(sum(abs(x), axis=1)) max(abs(x))
41-
* -Infinity min(sum(abs(x), axis=1)) min(abs(x))
42-
* 1 max(sum(abs(x), axis=0)) sum(abs(x))
43-
* 2 - sum(abs(x)^2)^1/2*
44-
* ```
35+
*
36+
* | ord | norm for matrices | norm for vectors
37+
* |------------|---------------------------|---------------------
38+
* |'euclidean' |Frobenius norm |2-norm
39+
* |'fro' |Frobenius norm |
40+
* |Infinity |max(sum(abs(x), axis=1)) |max(abs(x))
41+
* |-Infinity |min(sum(abs(x), axis=1)) |min(abs(x))
42+
* |1 |max(sum(abs(x), axis=0)) |sum(abs(x))
43+
* |2 | |sum(abs(x)^2)^1/2*
44+
*
4545
*
4646
* @param axis Optional. If axis is null (the default), the input is
4747
* considered a vector and a single vector norm is computed over the entire

website/api/index.html

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<head>
2-
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">
2+
<script src="https://cdn.jsdelivr.net/npm/deeplearn@latest"></script>
33
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.cyan-teal.min.css" />
4+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/solarized-dark.min.css">
45
<meta name="viewport" content="width=device-width, initial-scale=1.0">
56

67
<style>
@@ -15,6 +16,26 @@
1516
color: inherit;
1617
}
1718

19+
table {
20+
text-align: left;
21+
font-family: "Roboto Mono", monospace;
22+
}
23+
24+
thead {
25+
background-color: #dedede;
26+
}
27+
28+
th {
29+
text-align: left;
30+
padding: 4px;
31+
}
32+
33+
td {
34+
text-align: left;
35+
padding: 8px;
36+
padding-right: 16px;
37+
}
38+
1839
.container {
1940
display: flex;
2041
flex-direction: column;
@@ -131,22 +152,48 @@
131152
}
132153

133154
.reference .subsection-title {
134-
font-weight: 200;
135-
margin-bottom: 80px;
155+
font-weight: 300;
156+
margin-bottom: 16px;
157+
/* border-bottom: 1px solid rgb(96,125,139); */
158+
}
159+
160+
.reference .subsection-description {
161+
font-weight: 300;
162+
margin-bottom: 96px;
136163
border-bottom: 1px solid rgb(96,125,139);
164+
margin-left: 8px;
165+
}
166+
167+
.reference .symbol-marker {
168+
display: inline-block;
169+
margin-right: 12px;
170+
font-style: italic;
171+
font-size: 90%;
172+
color: grey;
137173
}
138174

139175
.documentation pre, .param-docs pre {
140176
background: #f4f4f4;
141177
}
142178

179+
code.hljs {
180+
border-radius: 5px;
181+
padding-left: 16px;
182+
}
183+
184+
pre.hljs {
185+
margin: 0;
186+
padding: 0;
187+
}
188+
189+
190+
143191
code, .param-name, .return-type {
192+
background: #f7f7f7;
144193
background: #f4f4f4;
145194
color: #37474f;
146195
padding: 2px 4px;
147196
font: 500 90%/2 Roboto Mono, monospace;
148-
}
149-
code {
150197
word-break: break-word;
151198
}
152199

@@ -162,9 +209,9 @@
162209

163210
.reference .symbol {
164211
margin-left: 32px;
165-
margin-bottom: 80px;
212+
margin-bottom: 96px;
166213
border-bottom: 1px dashed lightgrey;
167-
padding-bottom: 50px;
214+
padding-bottom: 16px;
168215
}
169216

170217
.reference .symbol .documentation p {
@@ -256,10 +303,11 @@
256303
{{#subheadings}}
257304
<div class="subsection">
258305
<div class="subsection-title mdl-typography--display-3">{{../name}} &nbsp;/&nbsp; {{name}}</div>
259-
<div class="subheading-description">{{description}}</div>
306+
<div class="subsection-description mdl-typography--headline">{{{description}}}</div>
260307
{{#symbols}}
261308
<div class="symbol">
262-
<h5>#
309+
<h5>
310+
<span class='symbol-marker'>&fnof;</span>
263311
<a name="{{urlHash}}" href="#{{urlHash}}">{{displayName}}</a>{{paramStr}}
264312
{{#isClass}}
265313
<span class="class-chip mdl-chip">

website/scripts/api-parser.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ export function parse():
4646
const docHeadings: DocHeading[] = [
4747
{
4848
name: 'Tensors',
49-
description: `Tensors are the core datastructure of deeplearn.js. ` +
50-
`They are a generalization of vectors and matrices to potentially ` +
51-
`higher dimensions.`,
49+
description: '',
5250
subheadings: [
5351
{
5452
name: 'Creation',
55-
description: `This section describes how to construct tensors.`,
53+
description: `Tensors are the core datastructure of deeplearn.js.
54+
They are a generalization of vectors and matrices to potentially
55+
higher dimensions.
56+
<br><br>
57+
We have utility functions for common cases like 1D, 2D, 3D
58+
and 4D tensors, as well a number of functions to iniatialize
59+
tensors in ways useful for machine learning`,
5660
pin: [
5761
'tensor', 'scalar', 'tensor1d', 'tensor2d', 'tensor3d', 'tensor4d'
5862
]

website/scripts/make-api.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import * as fs from 'fs';
2424
import * as HandleBars from 'handlebars';
25+
import * as hljs from 'highlight.js';
2526
import * as MarkdownIt from 'markdown-it';
2627
import * as minimist from 'minimist';
2728
import * as mkdirp from 'mkdirp';
@@ -70,19 +71,33 @@ const symbols: util.SymbolAndUrl[] = [
7071
];
7172
util.linkSymbols(docs, symbols, TOPLEVEL_NAMESPACE, docLinkAliases);
7273

73-
const md = new MarkdownIt();
74+
const md = new MarkdownIt({
75+
highlight(str, lang) {
76+
if (lang === 'js' && hljs.getLanguage(lang)) {
77+
const highlighted = hljs.highlight(lang, str).value;
78+
return '<pre class="hljs"><code class="hljs language-js">' + highlighted +
79+
'</code></pre>\n';
80+
}
81+
82+
return ''; // use external default escaping
83+
}
84+
});
7485

7586
// Add some helper functions
7687
HandleBars.registerHelper('markdown', attr => {
77-
return md.render(attr);
88+
if (attr) {
89+
return md.render(attr);
90+
}
7891
});
7992

8093
// Renders a string to markdown but removes the outer <p> tag
8194
HandleBars.registerHelper('markdownInner', attr => {
82-
const asMd =
83-
md.render(attr.trim()).replace(/<p>/, '').replace(/(<\/p>\s*)$/, '');
95+
if (attr) {
96+
const asMd =
97+
md.render(attr.trim()).replace(/<p>/, '').replace(/(<\/p>\s*)$/, '');
8498

85-
return asMd;
99+
return asMd;
100+
}
86101
});
87102

88103
// Write the HTML.

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ he@^1.1.1:
16181618
version "1.1.1"
16191619
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
16201620

1621-
highlight.js@^9.0.0:
1621+
highlight.js@9.12.0, highlight.js@^9.0.0:
16221622
version "9.12.0"
16231623
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e"
16241624

0 commit comments

Comments
 (0)