mirror of
https://github.com/zoldar/jenot.git
synced 2026-01-03 06:22:55 +00:00
Add autolink support
This commit is contained in:
parent
77a9f148cf
commit
ca0f954b14
2 changed files with 16 additions and 4 deletions
|
|
@ -13,7 +13,17 @@ export function html(strings, ...values) {
|
|||
return stringToHTML(String.raw({ raw: strings }));
|
||||
}
|
||||
|
||||
// Taken from https://stackoverflow.com/a/8943487
|
||||
const urlRegex =
|
||||
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
|
||||
|
||||
function linkify(text) {
|
||||
return text.replace(urlRegex, function (url) {
|
||||
return '<a href="' + url + '" target="_blank">' + url + "</a>";
|
||||
});
|
||||
}
|
||||
|
||||
export function renderText(text) {
|
||||
const content = text.replace(/(?:\r\n|\r|\n)/g, "<br>") + "<br>";
|
||||
const content = linkify(text).replace(/(?:\r\n|\r|\n)/g, "<br>") + "<br>";
|
||||
return stringToHTML(content, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,9 +253,11 @@ function renderNote(note) {
|
|||
}
|
||||
|
||||
container.addEventListener("click", async (e) => {
|
||||
const note = await Notes.get(container.id);
|
||||
editNote.load(structuredClone(note));
|
||||
editNoteDialog.showModal();
|
||||
if (e.target.tagName !== "A") {
|
||||
const note = await Notes.get(container.id);
|
||||
editNote.load(structuredClone(note));
|
||||
editNoteDialog.showModal();
|
||||
}
|
||||
});
|
||||
|
||||
return container;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue