Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b215f92

Browse filesBrowse files
vsemozhetbytMylesBorins
authored andcommitted
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: #20514 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 2a54965 commit b215f92
Copy full SHA for b215f92

File tree

Expand file treeCollapse file tree

2 files changed

+15
-55
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-55
lines changed
Open diff view settings
Collapse file

‎test/doctool/test-doctool-html.js‎

Copy file name to clipboardExpand all lines: test/doctool/test-doctool-html.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const testData = [
2929
file: fixtures.path('order_of_end_tags_5873.md'),
3030
html: '<h3>ClassMethod: Buffer.from(array) <span> ' +
3131
'<a class="mark" href="#foo_class_method_buffer_from_array" ' +
32-
'id="foo_class_method_buffer_from_array">#</a> </span> </h3><div' +
33-
'class="signature"><ul><li><code>array</code><a ' +
32+
'id="foo_class_method_buffer_from_array">#</a> </span> </h3>' +
33+
'<ul><li><code>array</code><a ' +
3434
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
3535
'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>' +
36-
'</ul></div>'
36+
'</ul>'
3737
},
3838
{
3939
file: fixtures.path('doc_with_yaml.md'),
Collapse file

‎tools/doc/html.js‎

Copy file name to clipboardExpand all lines: tools/doc/html.js
+12-52Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function render(opts, cb) {
9393
filename = path.basename(filename, '.md');
9494

9595
parseText(lexed);
96-
lexed = parseLists(lexed);
96+
lexed = preprocessElements(lexed);
9797

9898
// Generate the table of contents.
9999
// This mutates the lexed contents in-place.
@@ -231,25 +231,28 @@ function parseText(lexed) {
231231
});
232232
}
233233

234-
// Just update the list item text in-place.
235-
// Lists that come right after a heading are what we're after.
236-
function parseLists(input) {
234+
// Preprocess stability blockquotes and YAML blocks.
235+
function preprocessElements(input) {
237236
var state = null;
238-
const savedState = [];
239-
var depth = 0;
240237
const output = [];
241238
let headingIndex = -1;
242239
let heading = null;
243240

244241
output.links = input.links;
245242
input.forEach(function(tok, index) {
243+
if (tok.type === 'heading') {
244+
headingIndex = index;
245+
heading = tok;
246+
}
247+
if (tok.type === 'html' && common.isYAMLBlock(tok.text)) {
248+
tok.text = parseYAML(tok.text);
249+
}
246250
if (tok.type === 'blockquote_start') {
247-
savedState.push(state);
248251
state = 'MAYBE_STABILITY_BQ';
249252
return;
250253
}
251254
if (tok.type === 'blockquote_end' && state === 'MAYBE_STABILITY_BQ') {
252-
state = savedState.pop();
255+
state = null;
253256
return;
254257
}
255258
if ((tok.type === 'paragraph' && state === 'MAYBE_STABILITY_BQ') ||
@@ -271,50 +274,7 @@ function parseLists(input) {
271274
return;
272275
} else if (state === 'MAYBE_STABILITY_BQ') {
273276
output.push({ type: 'blockquote_start' });
274-
state = savedState.pop();
275-
}
276-
}
277-
if (state === null ||
278-
(state === 'AFTERHEADING' && tok.type === 'heading')) {
279-
if (tok.type === 'heading') {
280-
headingIndex = index;
281-
heading = tok;
282-
state = 'AFTERHEADING';
283-
}
284-
output.push(tok);
285-
return;
286-
}
287-
if (state === 'AFTERHEADING') {
288-
if (tok.type === 'list_start') {
289-
state = 'LIST';
290-
if (depth === 0) {
291-
output.push({ type: 'html', text: '<div class="signature">' });
292-
}
293-
depth++;
294-
output.push(tok);
295-
return;
296-
}
297-
if (tok.type === 'html' && common.isYAMLBlock(tok.text)) {
298-
tok.text = parseYAML(tok.text);
299-
}
300-
state = null;
301-
output.push(tok);
302-
return;
303-
}
304-
if (state === 'LIST') {
305-
if (tok.type === 'list_start') {
306-
depth++;
307-
output.push(tok);
308-
return;
309-
}
310-
if (tok.type === 'list_end') {
311-
depth--;
312-
output.push(tok);
313-
if (depth === 0) {
314-
state = null;
315-
output.push({ type: 'html', text: '</div>' });
316-
}
317-
return;
277+
state = null;
318278
}
319279
}
320280
output.push(tok);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.