feat: aplicação inicial — gerenciador de notas web estilo Mousepad
- Backend Go: API REST, auth por token (Bearer + cookie HttpOnly), storage em disco com revisões content-addressed (estilo Git: hash, autor, data, diff, restauração) - Editor txt/md/html com preview, tags #tag, categorias, painel de histórico - Preferências: números de linha, marcador de coluna (padrão 80), quebra de linha, fonte/tamanho, 4 temas e colorização de sintaxe (overlay no textarea) - Frontend vanilla embutido via go:embed; Dockerfile multi-stage + docker-compose
This commit is contained in:
commit
9bc5de4c56
22 files changed
+4239
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const maxBody = 4 << 20 // folga sobre o limite de conteúdo da store (2 MiB)
|
||||
|
||||
type renderInput struct {
|
||||
Content string `json:"content"`
|
||||
Format string `json:"format"`
|
||||
}
|
||||
|
||||
// handleRender converte Markdown em HTML seguro (raw HTML do markdown é
|
||||
// escapado pelo goldmark; a nota em si é sempre renderizada via innerHTML).
|
||||
func (s *Server) handleRender(w http.ResponseWriter, r *http.Request) {
|
||||
var in renderInput
|
||||
if err := decodeJSON(r, &in, maxBody); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "corpo JSON inválido")
|
||||
return
|
||||
}
|
||||
switch in.Format {
|
||||
case "html":
|
||||
// O preview de HTML usa iframe com sandbox no cliente; não renderiza aqui.
|
||||
writeError(w, http.StatusBadRequest, "formato html usa preview em iframe")
|
||||
return
|
||||
}
|
||||
var buf strings.Builder
|
||||
if err := s.md.Convert([]byte(in.Content), &buf); err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "falha ao renderizar markdown")
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{"html": buf.String()})
|
||||
}
|
||||
Reference in new issue
Block a user