mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-08 14:04:31 +08:00
Improve markdown links (#315)
* Make sure link/button clicks don't trigger cell focus * Open external links in new browser tab
This commit is contained in:
parent
fcf53c4bf2
commit
7b89e1ec83
2 changed files with 14 additions and 6 deletions
|
@ -20,6 +20,18 @@ marked.setOptions({
|
|||
},
|
||||
});
|
||||
|
||||
// Modify external links, so that they open in a new tab.
|
||||
// See https://github.com/cure53/DOMPurify/tree/main/demos#hook-to-open-all-links-in-a-new-window-link
|
||||
DOMPurify.addHook("afterSanitizeAttributes", (node) => {
|
||||
if (
|
||||
node.tagName.toLowerCase() === "a" &&
|
||||
node.host !== window.location.host
|
||||
) {
|
||||
node.setAttribute("target", "_blank");
|
||||
node.setAttribute("rel", "noreferrer noopener");
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Renders markdown content in the given container.
|
||||
*/
|
||||
|
|
|
@ -329,12 +329,8 @@ function handleDocumentKeyDown(hook, event) {
|
|||
* (e.g. if the user starts selecting some text within the editor)
|
||||
*/
|
||||
function handleDocumentMouseDown(hook, event) {
|
||||
// If click targets cell actions, keep the focus as is
|
||||
if (
|
||||
event.target.closest(
|
||||
`[data-element="actions"], [data-element="insert-buttons"]`
|
||||
)
|
||||
) {
|
||||
// If click targets a clickable element that awaits mouse up, keep the focus as is
|
||||
if (event.target.closest(`a, button`)) {
|
||||
// If the pencil icon is clicked, enter insert mode
|
||||
if (event.target.closest(`[data-element="enable-insert-mode-button"]`)) {
|
||||
setInsertMode(hook, true);
|
||||
|
|
Loading…
Add table
Reference in a new issue