template readonly, make it plain html for fast
parent
20c1b738a6
commit
553df97240
|
|
@ -12,7 +12,10 @@ require (
|
|||
local/simpleserve v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require github.com/go-stack/stack v1.8.0 // indirect
|
||||
require (
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/gomarkdown/markdown v0.0.0-20220114203417-14399d5448c4 // indirect
|
||||
)
|
||||
|
||||
replace local/args => ../../../../args
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
|
|||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomarkdown/markdown v0.0.0-20210208175418-bda154fe17d8/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
|
||||
github.com/gomarkdown/markdown v0.0.0-20220114203417-14399d5448c4 h1:6GlsnS3GQYfrJZTJEUsheoyLE6kLXQJDvQKIKxgL/9Q=
|
||||
github.com/gomarkdown/markdown v0.0.0-20220114203417-14399d5448c4/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
|
|
|
|||
|
|
@ -3,20 +3,18 @@
|
|||
<html>
|
||||
<header>
|
||||
<title>{{ .This.Title }}</title>
|
||||
{{ template "_import" }}
|
||||
{{ template "_import" }}
|
||||
</header>
|
||||
<body class="fullscreen tb_fullscreen lr_fullscreen" style="position: absolute">
|
||||
<div class="rows" style="height: inherit;">
|
||||
{{ template "_searchbar" }}
|
||||
{{ template "_searchbar" }}
|
||||
<div class="columns thic_flex tb_buffer" style="height: calc(100% - 4rem);">
|
||||
{{ template "_filetree" . }}
|
||||
{{ template "_filetree" . }}
|
||||
<div class="thic_flex lr_fullscreen" style="margin-left: 1em; width: 5px;">
|
||||
{{ if .This.ReadOnly }}
|
||||
<div id="readonly"></div>
|
||||
{{ .This.Content }}
|
||||
</script>
|
||||
{{ template "_readonly" . }}
|
||||
{{ else }}
|
||||
{{ template "_editor" . }}
|
||||
{{ template "_editor" . }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
{{ define "_readonly" }}
|
||||
<div class="fullscreen tb_fullscreen">
|
||||
<article id="article">
|
||||
</article>
|
||||
<script>
|
||||
document.getElementById("article").innerHTML = {{ .This.Content }}
|
||||
</script>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{{ define "_readonly" }}
|
||||
<div class="fullscreen tb_fullscreen">
|
||||
<article id="article"></article>
|
||||
<script>
|
||||
document.getElementById("article").innerHTML = {{ .This.Content }}
|
||||
</script>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
@ -18,6 +18,10 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
|
@ -269,6 +273,9 @@ func (server *Server) uiFilesHandler(w http.ResponseWriter, r *http.Request) err
|
|||
if err != nil {
|
||||
leaf.Meta.Title = "My New File"
|
||||
}
|
||||
if leaf.Meta.ReadOnly {
|
||||
leaf.Content = Gomarkdown([]byte(leaf.Content))
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
"This": map[string]interface{}{
|
||||
"Title": leaf.Meta.Title,
|
||||
|
|
@ -503,3 +510,30 @@ func (server *Server) _apiV0SearchHandler(query string) ([][2]string, error) {
|
|||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func Gomarkdown(b []byte) string {
|
||||
renderer := html.NewRenderer(html.RendererOptions{
|
||||
Flags: html.CommonFlags | html.TOC,
|
||||
})
|
||||
ext := parser.NoExtensions
|
||||
for _, extension := range []parser.Extensions{
|
||||
parser.NoIntraEmphasis,
|
||||
parser.Tables,
|
||||
parser.FencedCode,
|
||||
parser.Autolink,
|
||||
parser.Strikethrough,
|
||||
parser.SpaceHeadings,
|
||||
parser.HeadingIDs,
|
||||
parser.BackslashLineBreak,
|
||||
parser.DefinitionLists,
|
||||
parser.MathJax,
|
||||
parser.Titleblock,
|
||||
parser.AutoHeadingIDs,
|
||||
parser.Includes,
|
||||
} {
|
||||
ext |= extension
|
||||
}
|
||||
parser := parser.NewWithExtensions(ext)
|
||||
content := markdown.ToHTML(b, parser, renderer)
|
||||
return string(content) + "\n"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue