From 2b450b66fee4906e746f6e04a6d07a72ff2faf64 Mon Sep 17 00:00:00 2001 From: grm Date: Sat, 12 Sep 2026 12:26:17 +0300 Subject: Insert images straight from the Markdown editor A shared editor partial adds an "Insert image" file picker plus paste and drag-and-drop on the textarea; a few lines of inline JS upload the file to the existing images endpoint (which now answers JSON when asked) and put the Markdown at the caret. Without JS the same file rides along with the form and is appended to the text on save, so nothing depends on scripting. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/web/templates/dashboard/page_form.html | 7 ++-- internal/web/templates/dashboard/post_form.html | 7 ++-- internal/web/templates/partials/editor.html | 44 +++++++++++++++++++++++++ internal/web/templates/partials/mdhelp.html | 2 +- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 internal/web/templates/partials/editor.html (limited to 'internal/web/templates') diff --git a/internal/web/templates/dashboard/page_form.html b/internal/web/templates/dashboard/page_form.html index 38aac71..2692449 100644 --- a/internal/web/templates/dashboard/page_form.html +++ b/internal/web/templates/dashboard/page_form.html @@ -2,13 +2,13 @@ {{define "content"}}

{{if .Data.page.ID}}Edit page{{else}}New page{{end}}

-
+ - + + {{template "editor" (dict "name" "intro" "value" .Data.page.IntroMD "rows" 8 "tall" false "upload" (print "/b/" .Blog.Subdomain "/images/upload") "csrf" .CSRF)}}

@@ -17,5 +17,4 @@

-{{template "mdhelp"}} {{end}} diff --git a/internal/web/templates/dashboard/post_form.html b/internal/web/templates/dashboard/post_form.html index 7e6f00f..8b4a593 100644 --- a/internal/web/templates/dashboard/post_form.html +++ b/internal/web/templates/dashboard/post_form.html @@ -2,7 +2,7 @@ {{define "content"}}

{{if .Data.post.ID}}Edit post{{else}}New post{{end}}

-
+
@@ -12,8 +12,8 @@
- + + {{template "editor" (dict "name" "body" "value" .Data.post.BodyMD "rows" 24 "tall" true "upload" (print "/b/" .Blog.Subdomain "/images/upload") "csrf" .CSRF)}}

@@ -22,5 +22,4 @@

-{{template "mdhelp"}} {{end}} diff --git a/internal/web/templates/partials/editor.html b/internal/web/templates/partials/editor.html new file mode 100644 index 0000000..8e0acaf --- /dev/null +++ b/internal/web/templates/partials/editor.html @@ -0,0 +1,44 @@ +{{define "editor"}} +
+ + + …or paste / drop an image into the text. + +
+{{template "mdhelp"}} +{{end}} diff --git a/internal/web/templates/partials/mdhelp.html b/internal/web/templates/partials/mdhelp.html index 4623c07..3584025 100644 --- a/internal/web/templates/partials/mdhelp.html +++ b/internal/web/templates/partials/mdhelp.html @@ -2,7 +2,7 @@ Formatting cheat-sheet - +
# Heading, ## Smaller heading**bold**, *italic*
[link text](https://example.org)![description](/media/…) — or use Insert image
[link text](https://example.org)![description](/media/…) — Insert image writes this for you
- list item / 1. numbered> quote, `code`, --- for a line

Blank line = new paragraph. Press Enter once for a line break.

-- cgit v1.2.3