First implementation of web based editor to HTML pipeline
This commit is contained in:
		
							
								
								
									
										18
									
								
								cmd/articles/markdown.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								cmd/articles/markdown.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| package articles | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"fmt" | ||||
|  | ||||
| 	"github.com/yuin/goldmark" | ||||
| ) | ||||
|  | ||||
| func ConvertToHTML(markdown string) (string, error) { | ||||
| 	var buf bytes.Buffer | ||||
|  | ||||
| 	if err := goldmark.Convert([]byte(markdown), &buf); err != nil { | ||||
| 		return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err) | ||||
| 	} | ||||
|  | ||||
| 	return buf.String(), nil | ||||
| } | ||||
							
								
								
									
										23
									
								
								cmd/handlers/editor.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								cmd/handlers/editor.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| package handlers | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"streifling.com/jason/cpolis/cmd/articles" | ||||
| ) | ||||
|  | ||||
| func HandleFinishedEdit() http.HandlerFunc { | ||||
| 	return func(w http.ResponseWriter, r *http.Request) { | ||||
| 		md := r.PostFormValue("editor-textarea") | ||||
|  | ||||
| 		html, err := articles.ConvertToHTML(md) | ||||
| 		if err != nil { | ||||
| 			http.Error(w, err.Error(), http.StatusInternalServerError) | ||||
| 			log.Panicln(err) | ||||
| 		} | ||||
|  | ||||
| 		fmt.Println(html) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @@ -1,3 +1,5 @@ | ||||
| module streifling.com/jason/cpolis | ||||
|  | ||||
| go 1.22.0 | ||||
|  | ||||
| require github.com/yuin/goldmark v1.7.0 | ||||
|   | ||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= | ||||
| github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= | ||||
							
								
								
									
										18
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								main.go
									
									
									
									
									
								
							| @@ -1,8 +1,22 @@ | ||||
| package main | ||||
|  | ||||
| import "net/http" | ||||
| import ( | ||||
| 	"html/template" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
|  | ||||
| 	"streifling.com/jason/cpolis/cmd/handlers" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	mux := http.NewServeMux() | ||||
| 	http.ListenAndServe(":8080", mux) | ||||
|  | ||||
| 	mux.Handle("/web/static/", http.StripPrefix("/web/static/", http.FileServer(http.Dir("web/static/")))) | ||||
| 	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||||
| 		template.Must(template.ParseFiles("web/templates/index.html", "web/templates/editor.html")).Execute(w, nil) | ||||
| 	}) | ||||
|  | ||||
| 	mux.HandleFunc("POST /finished-edit/", handlers.HandleFinishedEdit()) | ||||
|  | ||||
| 	log.Fatalln(http.ListenAndServe(":8080", mux)) | ||||
| } | ||||
|   | ||||
							
								
								
									
										0
									
								
								web/static/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								web/static/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								web/static/js/htmx.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								web/static/js/htmx.min.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										6
									
								
								web/templates/editor.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								web/templates/editor.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| {{define "page-content"}} | ||||
| <form> | ||||
|     <textarea name="editor-textarea"></textarea> | ||||
|     <input type="submit" value="Senden" hx-post="/finished-edit/"> | ||||
| </form> | ||||
| {{end}} | ||||
							
								
								
									
										21
									
								
								web/templates/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								web/templates/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| <!DOCTYPE html> | ||||
| <html lang="de"> | ||||
|  | ||||
| <head> | ||||
|     <meta charset="UTF-8"> | ||||
|     <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||
|     <title>Orient Editor</title> | ||||
|     <link href="web/static/css/style.css" rel="stylesheet"> | ||||
| </head> | ||||
|  | ||||
| <body> | ||||
|     <h1>Orient Editor</h1> | ||||
|  | ||||
|     <div id="page-content"> | ||||
|         {{template "page-content" .}} | ||||
|     </div> | ||||
|  | ||||
|     <script src="web/static/js/htmx.min.js"></script> | ||||
| </body> | ||||
|  | ||||
| </html> | ||||
		Reference in New Issue
	
	Block a user