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

Commit 97bc9dd

Browse files
authored
Improve rendering of api docs
1 parent 0c9f900 commit 97bc9dd

File tree

2 files changed

+140
-65
lines changed

2 files changed

+140
-65
lines changed

website/api/index.html

Lines changed: 136 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<head>
22
<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">
4+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/railscasts.min.css">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66

77
<style>
@@ -127,6 +127,16 @@
127127
.toc a {
128128
font-weight: normal;
129129
text-decoration-color: lightgrey;
130+
text-decoration: none;
131+
transition-property: color, text-decoration-color, padding;
132+
transition-duration: 0.15s;
133+
}
134+
135+
.toc a.highlighted {
136+
color: #0277BD;
137+
text-decoration-color: #002b36;
138+
padding-left: 6px;
139+
font-weight: bold;
130140
}
131141

132142
/* .toc::-webkit-scrollbar {
@@ -159,9 +169,16 @@
159169

160170
.reference .subsection-description {
161171
font-weight: 300;
162-
margin-bottom: 96px;
172+
margin-bottom: 80px;
163173
border-bottom: 1px solid rgb(96,125,139);
164174
margin-left: 8px;
175+
padding-bottom: 24px;
176+
font-size: 21px;
177+
}
178+
179+
.reference .subsection-description p {
180+
font-size: inherit;
181+
font-weight: inherit;
165182
}
166183

167184
.reference .symbol-marker {
@@ -172,6 +189,12 @@
172189
color: grey;
173190
}
174191

192+
.reference .symbol-name {
193+
text-decoration: none;
194+
color: #0277BD;
195+
margin-right: 0.33em;
196+
}
197+
175198
.documentation pre, .param-docs pre {
176199
background: #f4f4f4;
177200
}
@@ -182,35 +205,35 @@
182205
}
183206

184207
pre.hljs {
185-
margin: 0;
208+
margin: 24px;
209+
/* margin-left: 24px; */
186210
padding: 0;
187211
}
188212

189-
190-
191213
code, .param-name, .return-type {
192214
background: #f7f7f7;
193215
background: #f4f4f4;
194216
color: #37474f;
195-
padding: 2px 4px;
196-
font: 500 90%/2 Roboto Mono, monospace;
217+
/* padding: 2px 4px; */
218+
font-weight: 500;
219+
font-family: Roboto Mono, monospace;
197220
word-break: break-word;
198221
}
199222

200223
.documentation a, .returns a, .param-name a, .method-docs a, .param-docs a {
201-
background: #f4f4f4;
202-
padding: 4px 6px;
203-
font: 500 90%/2 Roboto Mono, monospace;
224+
/* background: #f4f4f4; */
225+
color: #0277BD;
226+
/* padding: 2px 2px; */
227+
font-weight: 500;
228+
font-family: Roboto Mono, monospace;
204229
}
205230

206-
.documentation {
207-
white-space: pre;
208-
}
231+
209232

210233
.reference .symbol {
211234
margin-left: 32px;
212235
margin-bottom: 96px;
213-
border-bottom: 1px dashed lightgrey;
236+
border-bottom: 1px solid #0277BD;
214237
padding-bottom: 16px;
215238
}
216239

@@ -222,9 +245,12 @@
222245
margin-bottom: 8px;
223246
}
224247

225-
.parameter-heading, .returns {
248+
.parameter-heading, .returns-header {
226249
margin-top: 8px;
227250
font-weight: 500;
251+
font-variant: small-caps;
252+
text-transform: lowercase;
253+
font-size: 16px;
228254
}
229255

230256
.method {
@@ -239,10 +265,6 @@
239265
padding: 4px 12px;
240266
}
241267

242-
.method-name {
243-
font-size: 20px;
244-
}
245-
246268
.method-docs {
247269
padding: 12px 0 0 16px;
248270
}
@@ -253,21 +275,92 @@
253275
}
254276

255277
.source-ref a {
256-
color: #346f91
257-
}
258-
259-
.mdl-chip__text {
260-
vertical-align: baseline !important;
278+
color:#0277BD;
261279
}
262280

263-
.class-chip {
264-
margin-left: 16px;
281+
.chip {
282+
background: #f4f4f4;
283+
display: inline-block;
284+
padding: 0 6px 0 6px;
285+
border-radius: 4px;
286+
font-weight: 500;
287+
font-size: 82%;
265288
}
266289

267290
</style>
291+
292+
<script>
293+
document.addEventListener('DOMContentLoaded', function(e) {
294+
// Find the symbol closest to the top of the page in the reference
295+
// section and highlight it in the TOC section.
296+
297+
var refSymbols = document.querySelectorAll('.symbol-name');
298+
var refArea = document.querySelector('.reference');
299+
var tocArea = document.querySelector('.toc');
300+
301+
var lastHighlightedTocElement;
302+
303+
function updateTocView() {
304+
var top = refArea && refArea.scrollTop
305+
306+
var found;
307+
var tocFound;
308+
309+
for (var i = 0; i < refSymbols.length; i++) {
310+
var symbol = refSymbols[i];
311+
var sTop = symbol.offsetTop;
312+
if (sTop > top) {
313+
found = symbol;
314+
break;
315+
}
316+
}
317+
318+
if (found) {
319+
tocFound = tocArea.querySelector(`[href="#${found.getAttribute('name')}"]`)
320+
321+
if (lastHighlightedTocElement) {
322+
lastHighlightedTocElement.classList.remove('highlighted');
323+
}
324+
tocFound.classList.add('highlighted');
325+
tocFound.scrollIntoView(false);
326+
lastHighlightedTocElement = tocFound;
327+
}
328+
}
329+
330+
refArea.addEventListener('scroll', updateTocView)
331+
refArea.addEventListener('resize', updateTocView)
332+
});
333+
</script>
268334
</head>
269335

270336
<body>
337+
<!-- Partials -->
338+
{{#*inline "paramList"}}
339+
<div class="parameter-list">
340+
<div class="parameter-heading">Parameters:</div>
341+
<ul>
342+
{{#parameters}}
343+
<li class="parameter">
344+
<span <span class="param-name">
345+
{{name}}:&nbsp;{{{markdownInner type}}}
346+
</span>
347+
<span class="param-docs">
348+
{{{markdownInner documentation}}}
349+
</span>
350+
{{#optional}}
351+
<span class="chip">
352+
Optional
353+
</span>
354+
{{/optional}}
355+
</li>
356+
{{/parameters}}
357+
</ul>
358+
</div>
359+
360+
{{/inline}}
361+
<!-- END Partials -->
362+
363+
271364
<div class="container">
272365
<nav>
273366
<a href="index.html">deeplearn.js</a>
@@ -307,33 +400,26 @@
307400
{{#symbols}}
308401
<div class="symbol">
309402
<h5>
310-
<span class='symbol-marker'>&fnof;</span>
311-
<a name="{{urlHash}}" href="#{{urlHash}}">{{displayName}}</a>{{paramStr}}
312-
{{#isClass}}
313-
<span class="class-chip mdl-chip">
314-
<span class="mdl-chip__text">Class</span>
315-
</span>
316-
{{/isClass}}
403+
{{#if isClass}}
404+
<span class="chip">Class</span>
405+
{{else}}
406+
<span class="symbol-marker">&fnof;</span>
407+
{{/if}}
408+
<a class="symbol-name" name="{{urlHash}}" href="#{{urlHash}}">{{displayName}}</a>{{paramStr}}
317409
</h5>
318410

319411
<div class="documentation">{{{markdown documentation}}}</div>
320412

321413
{{#isFunction}}
322-
<div class="parameter-heading mdl-typography--subhead">Parameters:</div>
323-
<ul>
324-
{{#parameters}}
325-
<li class="parameter">
326-
<span class="param-name">
327-
{{name}}: {{{markdownInner type}}}
328-
</span>
329-
<span class="param-docs">
330-
{{#optional}}(Optional){{/optional}} {{{markdownInner documentation}}}
331-
</span>
332-
</li>
333-
{{/parameters}}
334-
</ul>
335-
<div class="returns mdl-typography--subhead">
336-
Returns: <span class="return-type">{{{markdownInner returnType}}}</span>
414+
415+
<!-- Params -->
416+
{{> paramList }}
417+
418+
<div class="returns">
419+
<span class="returns-header">
420+
Returns:
421+
</span>
422+
<span class="return-type">{{{markdownInner returnType}}}</span>
337423
</div>
338424
{{/isFunction}} {{#isClass}}
339425
<h6>Methods:</h6>
@@ -345,19 +431,8 @@ <h6>Methods:</h6>
345431
<span class="method-docs">
346432
{{#optional}}(Optional){{/optional}} {{{markdownInner documentation}}}
347433

348-
<div class="parameter-heading mdl-typography--subhead">Parameters:</div>
349-
<ul>
350-
{{#parameters}}
351-
<li class="parameter">
352-
<span class="param-name">
353-
{{name}}: {{{markdownInner type}}}
354-
</span>
355-
<span class="param-docs">
356-
{{#optional}}(Optional){{/optional}} {{{markdownInner documentation}}}
357-
</span>
358-
</li>
359-
{{/parameters}}
360-
</ul>
434+
<!-- Params -->
435+
{{> paramList }}
361436
</span>
362437
</div>
363438
{{/methods}} {{/isClass}}

website/scripts/api-parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export function parse():
5050
subheadings: [
5151
{
5252
name: 'Creation',
53-
description: `Tensors are the core datastructure of deeplearn.js.
53+
description: `<p>Tensors are the core datastructure of deeplearn.js.
5454
They are a generalization of vectors and matrices to potentially
5555
higher dimensions.
56-
<br><br>
57-
We have utility functions for common cases like 1D, 2D, 3D
56+
</p>
57+
<p>We have utility functions for common cases like 1D, 2D, 3D
5858
and 4D tensors, as well a number of functions to iniatialize
59-
tensors in ways useful for machine learning`,
59+
tensors in ways useful for machine learning</p>`,
6060
pin: [
6161
'tensor', 'scalar', 'tensor1d', 'tensor2d', 'tensor3d', 'tensor4d'
6262
]

0 commit comments

Comments
 (0)