summaryrefslogtreecommitdiff
path: root/tools/doc
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-05-04 12:16:38 +0300
committerAnatoli Papirovski <apapirovski@mac.com>2018-05-07 10:43:43 +0200
commit974df9c2be11910d7aef381d73cb11a4bb547c20 (patch)
treec4ab67cba5ee539660064b7be2a2e9e1921577b1 /tools/doc
parent2a96ee284cc5aecec9b66d24bddb06acbcc72c98 (diff)
downloadandroid-node-v8-974df9c2be11910d7aef381d73cb11a4bb547c20.tar.gz
android-node-v8-974df9c2be11910d7aef381d73cb11a4bb547c20.tar.bz2
android-node-v8-974df9c2be11910d7aef381d73cb11a4bb547c20.zip
tools: remove redundant code in doc/html.js
This PR reduces code by 40 lines and docs size by ~7.5 KB. Only <div class="signature">...</div> wrappers are removed from docs, no other changes are found in results. PR-URL: https://github.com/nodejs/node/pull/20514 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'tools/doc')
-rw-r--r--tools/doc/html.js64
1 files changed, 12 insertions, 52 deletions
diff --git a/tools/doc/html.js b/tools/doc/html.js
index 439fc05701..1bb5fa630f 100644
--- a/tools/doc/html.js
+++ b/tools/doc/html.js
@@ -93,7 +93,7 @@ function render(opts, cb) {
filename = path.basename(filename, '.md');
parseText(lexed);
- lexed = parseLists(lexed);
+ lexed = preprocessElements(lexed);
// Generate the table of contents.
// This mutates the lexed contents in-place.
@@ -231,25 +231,28 @@ function parseText(lexed) {
});
}
-// Just update the list item text in-place.
-// Lists that come right after a heading are what we're after.
-function parseLists(input) {
+// Preprocess stability blockquotes and YAML blocks.
+function preprocessElements(input) {
var state = null;
- const savedState = [];
- var depth = 0;
const output = [];
let headingIndex = -1;
let heading = null;
output.links = input.links;
input.forEach(function(tok, index) {
+ if (tok.type === 'heading') {
+ headingIndex = index;
+ heading = tok;
+ }
+ if (tok.type === 'html' && common.isYAMLBlock(tok.text)) {
+ tok.text = parseYAML(tok.text);
+ }
if (tok.type === 'blockquote_start') {
- savedState.push(state);
state = 'MAYBE_STABILITY_BQ';
return;
}
if (tok.type === 'blockquote_end' && state === 'MAYBE_STABILITY_BQ') {
- state = savedState.pop();
+ state = null;
return;
}
if ((tok.type === 'paragraph' && state === 'MAYBE_STABILITY_BQ') ||
@@ -271,50 +274,7 @@ function parseLists(input) {
return;
} else if (state === 'MAYBE_STABILITY_BQ') {
output.push({ type: 'blockquote_start' });
- state = savedState.pop();
- }
- }
- if (state === null ||
- (state === 'AFTERHEADING' && tok.type === 'heading')) {
- if (tok.type === 'heading') {
- headingIndex = index;
- heading = tok;
- state = 'AFTERHEADING';
- }
- output.push(tok);
- return;
- }
- if (state === 'AFTERHEADING') {
- if (tok.type === 'list_start') {
- state = 'LIST';
- if (depth === 0) {
- output.push({ type: 'html', text: '<div class="signature">' });
- }
- depth++;
- output.push(tok);
- return;
- }
- if (tok.type === 'html' && common.isYAMLBlock(tok.text)) {
- tok.text = parseYAML(tok.text);
- }
- state = null;
- output.push(tok);
- return;
- }
- if (state === 'LIST') {
- if (tok.type === 'list_start') {
- depth++;
- output.push(tok);
- return;
- }
- if (tok.type === 'list_end') {
- depth--;
- output.push(tok);
- if (depth === 0) {
- state = null;
- output.push({ type: 'html', text: '</div>' });
- }
- return;
+ state = null;
}
}
output.push(tok);