Skip to content

Commit

Permalink
fix: footnote detection whose links contain a URL before the fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
goblindegook committed Aug 14, 2019
1 parent 83c5dd4 commit 2e24293
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function findFootnoteLinks(
pattern: RegExp,
scope = ''
): readonly HTMLAnchorElement[] {
return queryAll<HTMLAnchorElement>(document, scope + ' a[href^="#"]').filter(
return queryAll<HTMLAnchorElement>(document, scope + ' a[href*="#"]').filter(
link => (link.href + link.rel).match(pattern)
)
}
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/filename.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<article>
<p>
This paragraph is footnoted.
<sup id="fnref:1"><a href="index.html#fn:1">[1]</a></sup>
</p>
<aside class="footnotes">
<hr />
<ol>
<li id="fn:1">
<p>
This is the document's only footnote.
<a href="index.html#fnref:1" class="reversefootnote">&#160;&#8617;</a>
</p>
</li>
</ol>
</aside>
</article>
7 changes: 7 additions & 0 deletions test/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ test('sets ARIA attributes on button', () => {
expect(button).toHaveAttribute('aria-expanded', 'false')
expect(button).toHaveAttribute('aria-label', 'Footnote 1')
})

test('sets up footnotes with a URL before the fragment', () => {
setDocumentBody('filename.html')
littlefoot()
expect(queryAll('.littlefoot-footnote__host')).toHaveLength(1)
expect(getAllButtons()).toHaveLength(1)
})

0 comments on commit 2e24293

Please sign in to comment.