Skip to content

Commit b215f92

Browse 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

2 files changed

Lines changed: 15 additions & 55 deletions

File tree

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

Lines 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'),

‎tools/doc/html.js‎

Lines 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-
functionparseLists(input){
234+
// Preprocess stability blockquotes and YAML blocks.
235+
functionpreprocessElements(input){
237236
varstate=null;
238-
constsavedState=[];
239-
vardepth=0;
240237
constoutput=[];
241238
letheadingIndex=-1;
242239
letheading=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
}elseif(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)