[add] sync markup from puffer

This commit is contained in:
hkau 2024-03-30 12:18:40 -04:00
parent bd837904f0
commit 947f0a0006
2 changed files with 27 additions and 63 deletions

View File

@ -64,6 +64,16 @@ pub fn render(input: &str) -> String {
"<div class=\"mdnote note-$2\"><b class=\"mdnote-title\">$3</b></div>\n",
);
// markdown images (normal)
out = regex_replace(
&out,
r"!\[(.*?)\]\((.*?)\)",
"<img alt=\"$1\" title=\"$1\" src=\"$2\" />",
);
// markdown links
out = regex_replace(&out, r"\[(.*?)\]\((.*?)\)", "<a href=\"$2\">$1</a>");
// some bbcode stuff
out = regex_replace(&out, r"\[b\](.*?)\[/b\]", "<strong>$1</strong>"); // bold
out = regex_replace(&out, r"\[i\](.*?)\[/i\]", "<em>$1</em>"); // italic
@ -148,6 +158,9 @@ pub fn render(input: &str) -> String {
out = regex_replace(&out, "(<link.*>)", "");
out = regex_replace(&out, "(<meta.*>)", "");
// auto paragraph
out = regex_replace_dmnl(&out, "^(.*?)\n{2,}", "<p>\n$1\n</p>");
// return
out
}

View File

@ -2,9 +2,9 @@ export function user_settings(
metadata: { [key: string]: any },
name: string,
field: HTMLElement,
_type: "user" | "board" | undefined
_type: "user" | undefined
): void {
if (_type === undefined) _type = "board";
if (_type === undefined) _type = "user";
const update_form = document.getElementById(
"update-form"
@ -86,40 +86,21 @@ export function user_settings(
update_form.addEventListener("submit", async (e) => {
e.preventDefault();
if (_type === "user") {
// user
const res = await fetch(`/api/auth/users/${name}/update`, {
method: "POST",
body: JSON.stringify(metadata),
headers: {
"Content-Type": "application/json",
},
});
// user
const res = await fetch(`/api/auth/users/${name}/update`, {
method: "POST",
body: JSON.stringify(metadata),
headers: {
"Content-Type": "application/json",
},
});
const json = await res.json();
const json = await res.json();
if (json.success === false) {
return alert(json.message);
} else {
window.location.reload();
}
if (json.success === false) {
return alert(json.message);
} else {
// board
const res = await fetch(`/api/board/${name}/update`, {
method: "POST",
body: JSON.stringify(metadata),
headers: {
"Content-Type": "application/json",
},
});
const json = await res.json();
if (json.success === false) {
return alert(json.message);
} else {
window.location.reload();
}
window.location.reload();
}
});
@ -132,36 +113,6 @@ export function user_settings(
options = build_options(metadata, current_property);
render_user_settings_fields(field, options, option_render);
});
// handle delete
if (_type == "board") {
const delete_button = document.getElementById("delete-board");
delete_button!.addEventListener("click", async () => {
const _confirm = confirm(
"Are you sure you would like to delete this board? This cannot be undone."
);
if (_confirm === false) return;
// board
const res = await fetch(`/api/board/${name}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
const json = await res.json();
if (json.success === false) {
return alert(json.message);
} else {
alert("Board deleted");
window.location.href = "/";
}
});
}
}
function build_options(