Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'unique-hash-ids' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Feb 11, 2022
2 parents a2b43f5 + dbafb9a commit 549e337
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 4 deletions.
134 changes: 134 additions & 0 deletions __tests__/__snapshots__/bin.js.snap
Expand Up @@ -190,6 +190,34 @@ exports[`--config 1`] = `
</div>
</li>
<li><a
href='#foobar-1'
class=\\" toggle-sibling\\">
Foobar
<span class='icon'>▸</span>
</a>
<div class='toggle-target display-none'>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>
<li><a
href='#foobarbar'
class='regular pre-open'>
#bar
</a></li>
</ul>
</div>
</li>
Expand Down Expand Up @@ -1375,6 +1403,112 @@ like a <a href=\\"#klass\\">klass</a>. This needs a <a href=\\"https://developer
</section>
</div>
</div>
</div>
</section>
<section class='p2 mb2 clearfix bg-white minishadow'>
<div class='clearfix'>
<h3 class='fl m0' id='foobar-1'>
Foobar
</h3>
</div>
<p>This is Foobar
must have a distinct id from Foo.bar</p>
<div class='pre p1 fill-light mt0'>new Foobar()</div>
<div class='py1 quiet mt1 prose-big'>Instance Members</div>
<div class=\\"clearfix\\">
<div class='border-bottom' id='foobarbar'>
<div class=\\"clearfix small pointer toggle-sibling\\">
<div class=\\"py1 contain\\">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>bar</span>
</div>
</div>
<div class=\\"clearfix display-none toggle-target\\">
<section class='p2 mb2 clearfix bg-white minishadow'>
<p>This is bar</p>
<div class='pre p1 fill-light mt0'>bar</div>
Expand Down
134 changes: 134 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Expand Up @@ -1499,6 +1499,34 @@ exports[`html nested.input.js 1`] = `



</div>

</li>


<li><a
href='#foobar-1'
class=\\" toggle-sibling\\">
Foobar
<span class='icon'>▸</span>
</a>

<div class='toggle-target display-none'>


<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>

<li><a
href='#foobarbar'
class='regular pre-open'>
#bar
</a></li>

</ul>



</div>

</li>
Expand Down Expand Up @@ -2662,6 +2690,112 @@ like a <a href=\\"#klass\\">klass</a>. This needs a <a href=\\"https://developer












</section>

</div>
</div>

</div>






</section>




<section class='p2 mb2 clearfix bg-white minishadow'>


<div class='clearfix'>

<h3 class='fl m0' id='foobar-1'>
Foobar
</h3>


</div>


<p>This is Foobar
must have a distinct id from Foo.bar</p>

<div class='pre p1 fill-light mt0'>new Foobar()</div>

























<div class='py1 quiet mt1 prose-big'>Instance Members</div>
<div class=\\"clearfix\\">

<div class='border-bottom' id='foobarbar'>
<div class=\\"clearfix small pointer toggle-sibling\\">
<div class=\\"py1 contain\\">
<a class='icon pin-right py1 dark-link caret-right'>▸</a>
<span class='code strong strong truncate'>bar</span>
</div>
</div>
<div class=\\"clearfix display-none toggle-target\\">
<section class='p2 mb2 clearfix bg-white minishadow'>



<p>This is bar</p>

<div class='pre p1 fill-light mt0'>bar</div>























Expand Down
11 changes: 11 additions & 0 deletions __tests__/fixture/html/nested.input.js
Expand Up @@ -145,6 +145,17 @@ class Foo {
get bar() {}
}

/**
* This is Foobar
* must have a distinct id from Foo.bar
*/
class Foobar {
/**
* This is bar
*/
get bar() { }
}

/**
* I am the container of stream types
*/
Expand Down
16 changes: 12 additions & 4 deletions src/default_theme/index.js
Expand Up @@ -35,12 +35,21 @@ function isFunction(section) {
);
}

const slugger = new GithubSlugger();
const slugs = {};

function getSlug(str) {
if (slugs[str] === undefined) {
slugs[str] = slugger.slug(str);
}
return slugs[str];
}

export default async function (comments, config) {
var linkerStack = new LinkerStack(config).namespaceResolver(
comments,
function (namespace) {
var slugger = new GithubSlugger();
return '#' + slugger.slug(namespace);
return '#' + getSlug(namespace);
}
);

Expand All @@ -51,8 +60,7 @@ export default async function (comments, config) {
var sharedImports = {
imports: {
slug(str) {
var slugger = new GithubSlugger();
return slugger.slug(str);
return getSlug(str);
},
shortSignature(section) {
var prefix = '';
Expand Down

0 comments on commit 549e337

Please sign in to comment.