Skip to content

Commit

Permalink
always generate unique hash ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev authored and anthony-redFox committed Apr 14, 2022
1 parent d8ac5e9 commit 4048e97
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,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 @@ -2379,6 +2407,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 4048e97

Please sign in to comment.