From 78b836bef5ac2fa1b9c6ccb54814a82998c669cd Mon Sep 17 00:00:00 2001 From: deadvey Date: Fri, 11 Jul 2025 02:58:13 +0100 Subject: [PATCH] markdown support --- README.md | 2 +- app.js | 87 ++++++++++++++++++++++++++++++---------------------- hitcount.txt | 2 +- 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 920c60f..4c7b9e5 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ In action on my website: [deadvey.com](https://deadvey.com)
* edit/delete posts * probably insecure as hell * hitcount +* Markdown syntax in posts # planned features * atom * federation * sign up -* Markdown syntax in posts * All strings (including in edit and post page) customisable diff --git a/app.js b/app.js index 8e41170..7aab9b8 100755 --- a/app.js +++ b/app.js @@ -53,7 +53,7 @@ function replace_format_indicators(input_string, post_index=0, tag_name="tag") { .replaceAll("%%", "%") .replaceAll("%A", (post_object["tags"])) .replaceAll("%B", (hyperlink_tags(post_object["tags"]))) - .replaceAll("%C", post_object["content"].replaceAll("\n","
")) + .replaceAll("%C", markdown_to_html(post_object["content"])) .replaceAll("%D", unix_time_to_date_format(post_object["pubdate"])) .replaceAll("%E", unix_time_to_date_format(post_object["editdate"])) .replaceAll("%F", users.users[post_object["userID"]]['prettyname']) @@ -65,7 +65,7 @@ function replace_format_indicators(input_string, post_index=0, tag_name="tag") { .replaceAll("%O", `/edit/${post_index}`) .replaceAll("%R", "/rss") .replaceAll("%S", config.seperator) - .replaceAll("%T", post_object["title"]) + .replaceAll("%T", markdown_to_html(post_object["title"])) .replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`) .replaceAll("%Y", config.site_name) .replaceAll("%W", config.site_description) @@ -89,6 +89,22 @@ function escape_input(input) { return output } +// Markdown supported: +// *text* = bold +// _text_ = italic +// [page](url) = hyperlink +// ```code``` = code +function markdown_to_html(input) { + // FIXME backticks before these should negate stuff + let output = input + .replaceAll(/\[(.*)\]\((https:\/\/|http:\/\/)(.*)\)/g, "$1") + .replaceAll(/\*(.*)\*/g,"$1") + .replaceAll(/_(.*)_/g,"$1") + .replaceAll(/```(.*)```/gms,"$1") + .replaceAll("\n","
") + return output +} + app.get(config.rss_path, (req,res) => { if (config.rss == false) { res.send("Sorry, RSS is disabled!") @@ -142,40 +158,6 @@ app.get("/", (req,res) => { } res.send(`
${posts_div}
`); }); - -app.get("/post", (req,res) => { - res.send(`
-
-
-
-
-
- -
`); -}); -app.get("/edit/:post_id", (req,res) => { - const post_id = req.params.post_id - const post = posts.posts[post_id] - const user = users.users[post['userID']] - res.send(` -
- - -
-
- -
-
-
- -
`); -}); - - app.get("/user/:username", (req, res) => { header_div = config.user_page_header header_div = replace_format_indicators(header_div) @@ -208,6 +190,39 @@ app.get("/tag/:tag", (req,res) => { res.send(`
${page_content}
`); }); +app.get("/post", (req,res) => { + res.send(`
+
+
+
+
+
+ + * Markdown supported: *bold*, _italic_, (link)[url] and \`\`\`code block\`\`\` +
`); +}); +app.get("/edit/:post_id", (req,res) => { + const post_id = req.params.post_id + const post = posts.posts[post_id] + const user = users.users[post['userID']] + res.send(` +
+ + +
+
+ +
+
+
+ +
`); +}); + app.post("/submit_edit", (req,res) => { const password = crypto.createHash('sha512').update(req.body.password).digest('hex'); const postID = req.body.postID diff --git a/hitcount.txt b/hitcount.txt index 7d37386..4e9e288 100644 --- a/hitcount.txt +++ b/hitcount.txt @@ -1 +1 @@ -45 \ No newline at end of file +63 \ No newline at end of file