Skip to content

Commit 961bfc3

Browse files
samuelgoodellperrygovier
authored andcommitted
chore(docs): add anchor links to documentation sub-sections (ionic-team#12386)
* chore(docs): add anchor links to documentation sub-sections * chore(docs): make entire section headings clickable as anchors
1 parent 5b9fe5e commit 961bfc3

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

scripts/docs/processors/jekyll.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ module.exports = function jekyll(renderDocsProcessor) {
2929
if (docs[i].href) {
3030
docs[i].href = doc.href.replace('content/', '');
3131
}
32+
if (docs[i].description) {
33+
docs[i].description = docs[i].description.replace(/(\#\#\#).+/g, (section) => {
34+
const title = section.replace(/^(\#+\s?)/, '');
35+
const segment = title.replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase();
36+
37+
return `\n<h3><a class="anchor" name="${segment}" href="#${segment}">${title}</a></h3>\n`;
38+
});
39+
}
3240
});
3341

3442
docs.push({

scripts/docs/templates/common.template.html

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,15 @@ <h3><code><$ doc.decorators[0].argumentInfo[0].selector $></code></h3>
242242

243243
<!-- @usage tag -->
244244
<@ if doc.usage @>
245-
<h2><a class="anchor" name="usage" href="#usage"></a>Usage</h2>
245+
<h2><a class="anchor" name="usage" href="#usage">Usage</a></h2>
246246
<@ block usage @>
247247
<$ doc.usage | marked $>
248248
<@ endblock @>
249249
<@ endif @>
250250

251251
<!-- @property tags -->
252252
<@ if doc.properties @>
253-
<h2><a class="anchor" name="attributes" href="#attributes"></a>Attributes:</h2>
253+
<h2><a class="anchor" name="attributes" href="#attributes">Attributes</a></h2>
254254
<table class="table" style="margin:0;">
255255
<thead>
256256
<tr>
@@ -293,10 +293,10 @@ <h2><a class="anchor" name="attributes" href="#attributes"></a>Attributes:</h2>
293293

294294

295295
<@- if doc.statics.length -@>
296-
<h2><a class="anchor" name="static-members" href="#static-members"></a>Static Members</h2>
296+
<h2><a class="anchor" name="static-members" href="#static-members">Static Members</a></h2>
297297
<@- for method in doc.statics @><@ if not method.internal @>
298298
<div id="<$ method.name $>"></div>
299-
<h3><a class="anchor" name="<$ method.name $>" href="#<$ method.name $>"></a><$ functionSyntax(method) $></h3>
299+
<h3><a class="anchor" name="<$ method.name $>" href="#<$ method.name $>"><$ functionSyntax(method) $></a></h3>
300300

301301
<$ method.description $>
302302

@@ -327,14 +327,15 @@ <h4> Method's `this`
327327
<!-- instance methods on the class -->
328328
<@- if doc.members and doc.members.length @>
329329

330-
<h2><a class="anchor" name="instance-members" href="#instance-members"></a>Instance Members</h2>
330+
<h2><a class="anchor" name="instance-members" href="#instance-members">Instance Members</a></h2>
331331
<@- for method in doc.members @>
332332

333333
<div id="<$ method.name $>"></div>
334334

335335
<h3>
336-
<a class="anchor" name="<$ method.name $>" href="#<$ method.name $>"></a>
336+
<a class="anchor" name="<$ method.name $>" href="#<$ method.name $>">
337337
<$ functionSyntax(method) $>
338+
</a>
338339
</h3>
339340

340341
<$ method.description $>
@@ -366,34 +367,34 @@ <h4> Method's `this`
366367

367368
<@- if doc.inputs and doc.inputs.length @>
368369
<!-- input methods on the class -->
369-
<h2><a class="anchor" name="input-properties" href="#input-properties"></a>Input Properties</h2>
370+
<h2><a class="anchor" name="input-properties" href="#input-properties">Input Properties</a></h2>
370371
<$ inputTable(doc.inputs) $>
371372
<@- endif -@>
372373

373374
<@- if doc.outputs and doc.outputs.length @>
374375
<!-- output events on the class -->
375-
<h2><a class="anchor" name="output-events" href="#output-events"></a>Output Events</h2>
376+
<h2><a class="anchor" name="output-events" href="#output-events">Output Events</a></h2>
376377
<$ outputTable(doc.outputs) $>
377378
<@- endif -@>
378379

379380

380381
<@ block advanced @>
381382
<@- if doc.advanced -@>
382-
<h2><a class="anchor" name="advanced" href="#advanced"></a>Advanced</h2>
383+
<h2><a class="anchor" name="advanced" href="#advanced">Advanced</a></h2>
383384
<$ doc.advanced | marked $>
384385
<@- endif -@>
385386
<@ endblock @>
386387

387388
<@ if doc.sassVariables @>
388-
<h2 id="sass-variable-header"><a class="anchor" name="sass-variables" href="#sass-variables"></a>Sass Variables</h2>
389+
<h2 id="sass-variable-header"><a class="anchor" name="sass-variables" href="#sass-variables">Sass Variables</a></h2>
389390
<$ sassTable(doc.sassVariables) $>
390391
<@ endif @>
391392

392393

393394
<!-- related link -->
394395
<@- if doc.see @>
395396

396-
<h2><a class="anchor" name="related" href="#related"></a>Related</h2>
397+
<h2><a class="anchor" name="related" href="#related">Related</a></h2>
397398
<@ for s in doc.see @>
398399
<$ s | safe $> <@- if not loop.last @>,<@- endif -@>
399400
<@- endfor -@>

0 commit comments

Comments
 (0)