Skip to content

Commit fd84f36

Browse files
committed
f
1 parent 8263439 commit fd84f36

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

theme/toc.js.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class MDBookSidebarScrollbox extends HTMLElement {
1010
connectedCallback() {
1111
// Modify TOC to support external links
1212
var toc = '{{#toc}}{{/toc}}';
13-
toc = toc.replace(/<div>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/div>/g, '<a class="external-link" href="$2">$1</a>')
13+
// Handle both old mdbook (<div>) and new mdbook 0.5 (<span>) formats
14+
// External links open in new tab with external link icon
15+
toc = toc.replace(/<(div|span)>([^$<>]*)\$\$external:([^$<>]*)\$\$<\/(div|span)>/g, '<a class="external-link" href="$3" target="_blank" rel="noopener noreferrer">$2 ↗</a>')
1416
this.innerHTML = toc
1517
// Set the current, active page, and reveal it if it's hidden
1618
let current_page = document.location.href.toString();

0 commit comments

Comments
 (0)