Skip to content

Commit 6bb163f

Browse files
committed
Update live-view.js
1 parent bc940b1 commit 6bb163f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

live-view/live-view.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,11 @@ async function renderLiveViewMarkdown(file) {
11251125
if (isMobile) frameDoc.body.classList.add('mobile');
11261126
setAttr(frameDoc.body, 'dir', 'auto');
11271127

1128-
frameDoc.body.querySelectorAll('a[href]').forEach(link => {
1128+
frameDoc.body.querySelectorAll('a[href]:not([target="_blank"])').forEach(link => {
11291129

1130-
if (!getAttr(link, 'href').startsWith('#')) {
1130+
const href = getAttr(link, 'href');
1131+
1132+
if (!href.startsWith('#')) {
11311133

11321134
link.title = isMac ? '⌘ + click to open link' : 'Ctrl + click to open link';
11331135

@@ -1137,16 +1139,27 @@ async function renderLiveViewMarkdown(file) {
11371139

11381140
if (event.ctrlKey || event.metaKey) {
11391141

1140-
window.open(getAttr(link, 'href'), '_blank');
1142+
window.open(href, '_blank');
11411143

11421144
} else {
11431145

1144-
showMessage(getAttr(link, 'href'));
1146+
showMessage(href);
11451147

11461148
}
11471149

11481150
};
11491151

1152+
} else {
1153+
1154+
link.onclick = (e) => {
1155+
1156+
e.preventDefault();
1157+
1158+
const target = document.querySelector(href);
1159+
target.scrollIntoView();
1160+
1161+
};
1162+
11501163
}
11511164

11521165
});

0 commit comments

Comments
 (0)