Skip to content

Commit 6f8b7a8

Browse files
Derek Lewiscodebytere
Derek Lewis
authored andcommittedJul 8, 2020
doc,tools: properly syntax highlight API ref docs
Prior to this commit, all <pre> tags were being highlighted as JavaScript. This has been corrected to syntax highlight all languages appearing in the API reference docs. This was accomplished by using highlight.js instead of SHJS for the frontend lib. * remove SHJS JavaScript code * add highlight.js bundle * fix script tags to reflect replacement * migrate CSS to use highlight.js classes * add appropriate documentation * ensure api_assets README.md stays interal Fixes: #33363 PR-URL: #33442 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
1 parent 383c5b3 commit 6f8b7a8

11 files changed

+104
-585
lines changed
 

‎LICENSE

+33
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,39 @@ The externally maintained libraries used by Node.js are:
14711471
THE POSSIBILITY OF SUCH DAMAGE.
14721472
"""
14731473

1474+
- highlight.js, located at doc/api_assets/highlight.pack.js, is licensed as follows:
1475+
"""
1476+
BSD 3-Clause License
1477+
1478+
Copyright (c) 2006, Ivan Sagalaev.
1479+
All rights reserved.
1480+
1481+
Redistribution and use in source and binary forms, with or without
1482+
modification, are permitted provided that the following conditions are met:
1483+
1484+
* Redistributions of source code must retain the above copyright notice, this
1485+
list of conditions and the following disclaimer.
1486+
1487+
* Redistributions in binary form must reproduce the above copyright notice,
1488+
this list of conditions and the following disclaimer in the documentation
1489+
and/or other materials provided with the distribution.
1490+
1491+
* Neither the name of the copyright holder nor the names of its
1492+
contributors may be used to endorse or promote products derived from
1493+
this software without specific prior written permission.
1494+
1495+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1496+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1497+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1498+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1499+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1500+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1501+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1502+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1503+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1504+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1505+
"""
1506+
14741507
- node-heapdump, located at src/heap_utils.cc, is licensed as follows:
14751508
"""
14761509
ISC License

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ out/doc/api/assets:
733733

734734
# If it's not a source tarball, we need to copy assets from doc/api_assets
735735
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets
736-
@cp $< $@
736+
@cp $< $@ ; $(RM) out/doc/api/assets/README.md
737737

738738

739739
run-npm-ci = $(PWD)/$(NPM) ci

‎doc/api_assets/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# API Reference Document Assets
2+
3+
## highlight.pack.js
4+
5+
_Generated by [highlightjs.org/download][] on 2020-05-16._
6+
7+
Grammars included in the custom bundle:
8+
9+
* Bash
10+
* C
11+
* C++
12+
* CoffeeScript
13+
* JavaScript
14+
* JSON
15+
* Markdown
16+
* Plaintext
17+
* Shell Session
18+
19+
## hljs.css
20+
21+
The syntax theme for code snippets in API reference documents.
22+
23+
## style.css
24+
25+
The main stylesheet for API reference documents.
26+
27+
[highlightjs.org/download]: https://highlightjs.org/download/

‎doc/api_assets/highlight.pack.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎doc/api_assets/hljs.css

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.hljs {
2+
font-weight: normal;
3+
font-style: normal;
4+
}
5+
6+
.hljs-symbol {
7+
color: #333;
8+
}
9+
10+
.hljs-keyword {
11+
color: #338;
12+
}
13+
14+
.hljs-string,
15+
.hljs-regexp,
16+
.hljs-number {
17+
color: #E54305;
18+
}
19+
20+
.hljs-doctag {
21+
color: #040404;
22+
}
23+
24+
.hljs-doctag .hljs-type,
25+
.hljs-doctag .hljs-variable,
26+
.hljs-comment {
27+
color: #666;
28+
font-weight: lighter;
29+
}

‎doc/api_assets/sh.css

-25
This file was deleted.

‎doc/api_assets/sh_javascript.min.js

-1
This file was deleted.

‎doc/api_assets/sh_main.js

-553
This file was deleted.

‎doc/guides/doc-style-guide.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* When documenting APIs, update the YAML comment associated with the API as
3131
appropriate. This is especially true when introducing or deprecating an API.
3232
* For code blocks:
33-
* Use language aware fences. ("```js")
33+
* Use [language aware fences][]. (<code>```js</code>)
3434
* Code need not be complete. Treat code blocks as an illustration or aid to
3535
your point, not as complete running programs. If a complete running program
3636
is necessary, include it as an asset in `assets/code-examples` and link to
@@ -68,6 +68,7 @@
6868

6969
See also API documentation structure overview in [doctools README][].
7070

71+
[language aware fences]: https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md
7172
[Javascript type]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Data_structures_and_types
7273
[serial commas]: https://en.wikipedia.org/wiki/Serial_comma
7374
[plugin]: https://editorconfig.org/#download

‎doc/template.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<title>__SECTION__ | Node.js __VERSION__ Documentation</title>
77
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
88
<link rel="stylesheet" href="assets/style.css">
9-
<link rel="stylesheet" href="assets/sh.css">
9+
<link rel="stylesheet" href="assets/hljs.css">
1010
<link rel="canonical" href="https://nodejs.org/api/__FILENAME__.html">
1111
</head>
1212
<body class="alt apidoc" id="api-section-__FILENAME__">
@@ -51,8 +51,7 @@ <h2>Table of Contents</h2>
5151
</div>
5252
</div>
5353
</div>
54-
<script src="assets/sh_main.js"></script>
55-
<script src="assets/sh_javascript.min.js"></script>
56-
<script>highlight(undefined, undefined, 'pre');</script>
54+
<script src="assets/highlight.pack.js"></script>
55+
<script>document.addEventListener('DOMContentLoaded', () => { hljs.initHighlightingOnLoad(); });</script>
5756
</body>
5857
</html>

‎tools/license-builder.sh

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ addlicense "brotli" "deps/brotli" "$(cat ${rootdir}/deps/brotli/LICENSE)"
103103

104104
addlicense "HdrHistogram" "deps/histogram" "$(cat ${rootdir}/deps/histogram/LICENSE.txt)"
105105

106+
addlicense "highlight.js" "doc/api_assets/highlight.pack.js" \
107+
"$(curl -sL https://raw.githubusercontent.com/highlightjs/highlight.js/63f367c46f2eeb6f9b7a3545e325eeeb917f9942/LICENSE)"
108+
106109
addlicense "node-heapdump" "src/heap_utils.cc" \
107110
"$(curl -sL https://raw.githubusercontent.com/bnoordhuis/node-heapdump/0ca52441e46241ffbea56a389e2856ec01c48c97/LICENSE)"
108111

0 commit comments

Comments
 (0)
Please sign in to comment.