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:
Jonatan Kłosko 2021-06-03 16:31:41 +02:00 committed by GitHub
parent fcf53c4bf2
commit 7b89e1ec83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -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.
*/

View file

@ -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);