Skip to content

Commit

Permalink
add markdown help
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfaerman committed Jan 30, 2024
1 parent 25b8dd4 commit 77e33b9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 20 deletions.
16 changes: 12 additions & 4 deletions internal/handlers/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ func init() {
}

func (h Markdown) Routes(r chi.Router) {
r.Use(middleware.HTMXOnly)
web.CSRFExempt("/-/tools/markdown-render/*")
r.Post(named.Route("markdown-preview", "/-/tools/markdown-render/{name}"), h.Preview)
r.Post(named.Route("markdown-editor", "/-/tools/markdown-editor/{name}"), h.Editor)
r.Get(named.Route("markdown-help", "/-/docs/markdown"), h.Help)

r.Group(func(r chi.Router) {
r.Use(middleware.HTMXOnly)
web.CSRFExempt("/-/tools/markdown-render/*")
r.Post(named.Route("markdown-preview", "/-/tools/markdown-render/{name}"), h.Preview)
r.Post(named.Route("markdown-editor", "/-/tools/markdown-editor/{name}"), h.Editor)
})
}

func (h Markdown) Preview(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -70,3 +74,7 @@ func (h Markdown) Editor(w http.ResponseWriter, r *http.Request) {

views.InputTextArea(field, attrs).Render(r.Context(), w)
}

func (h Markdown) Help(w http.ResponseWriter, r *http.Request) {
(views.Docs{}).Markdown().Render(r.Context(), w)
}
10 changes: 10 additions & 0 deletions internal/views/help.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package views

type Docs struct{}

templ (Docs) Markdown() {
@Page() {
<h1>Writing Markdown</h1>
<p>This page is a work in progress</p>
}
}
70 changes: 70 additions & 0 deletions internal/views/help_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/views/input.templ
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ templ InputTextArea(name string, attrs InputAttrs) {
</button>
<span class="divider"></span>
}
<a href="#" class="button" title="Markdown Supported">
<a href={ templ.URL(named.URLFor("markdown-help")) } class="button" title="Markdown Supported">
@IconBrand("markdown")
</a>
</div>
Expand Down
39 changes: 24 additions & 15 deletions internal/views/input_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77e33b9

Please sign in to comment.