name from recursive resolved plaintext
parent
952e04815a
commit
785215bd3c
|
|
@ -105,7 +105,7 @@ const defaultWrapper = `
|
||||||
body > form > textarea {
|
body > form > textarea {
|
||||||
margin-top: 2.5em;
|
margin-top: 2.5em;
|
||||||
}
|
}
|
||||||
body > h2:nth-child(2) {
|
rendered > h2:nth-child(2) {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
padding: .25em;
|
padding: .25em;
|
||||||
|
|
@ -113,6 +113,35 @@ const defaultWrapper = `
|
||||||
background: #3b242b;
|
background: #3b242b;
|
||||||
top: 0;
|
top: 0;
|
||||||
}
|
}
|
||||||
|
h1, h2, h3, h4, h5, h6, h7, h8 {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.comment {
|
||||||
|
display: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
position: absolute;
|
||||||
|
right: 100%;
|
||||||
|
padding-right: 1em;
|
||||||
|
width: 10em;
|
||||||
|
top: 0;
|
||||||
|
text-align: right;
|
||||||
|
font-size: 12pt;
|
||||||
|
}
|
||||||
|
h1:hover > .comment,
|
||||||
|
h2:hover > .comment,
|
||||||
|
h3:hover > .comment,
|
||||||
|
h4:hover > .comment,
|
||||||
|
h5:hover > .comment,
|
||||||
|
h6:hover > .comment,
|
||||||
|
h7:hover > .comment,
|
||||||
|
h8:hover > .comment,
|
||||||
|
.comment:focus,
|
||||||
|
.comment:focus-within {
|
||||||
|
display: inline-flex;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</header>
|
</header>
|
||||||
<body height="100%">
|
<body height="100%">
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/notes-server/filetree"
|
"local/notes-server/filetree"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
|
"github.com/gomarkdown/markdown/ast"
|
||||||
"github.com/gomarkdown/markdown/html"
|
"github.com/gomarkdown/markdown/html"
|
||||||
"github.com/gomarkdown/markdown/parser"
|
"github.com/gomarkdown/markdown/parser"
|
||||||
)
|
)
|
||||||
|
|
@ -17,9 +22,39 @@ func (n *Notes) File(urlPath string) (string, error) {
|
||||||
}
|
}
|
||||||
b, _ := ioutil.ReadFile(p.Local)
|
b, _ := ioutil.ReadFile(p.Local)
|
||||||
renderer := html.NewRenderer(html.RendererOptions{
|
renderer := html.NewRenderer(html.RendererOptions{
|
||||||
Flags: html.CommonFlags | html.TOC,
|
Flags: html.CommonFlags | html.TOC,
|
||||||
|
RenderNodeHook: n.commentFormer(),
|
||||||
})
|
})
|
||||||
parser := parser.NewWithExtensions(parser.CommonExtensions | parser.HeadingIDs | parser.AutoHeadingIDs | parser.Titleblock)
|
parser := parser.NewWithExtensions(parser.CommonExtensions | parser.HeadingIDs | parser.AutoHeadingIDs | parser.Titleblock)
|
||||||
content := markdown.ToHTML(b, parser, renderer)
|
content := markdown.ToHTML(b, parser, renderer)
|
||||||
return string(content) + "\n", nil
|
return string(content) + "\n", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Notes) commentFormer() html.RenderNodeFunc {
|
||||||
|
header_n := 0
|
||||||
|
return func(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
|
||||||
|
if heading, ok := node.(*ast.Heading); ok {
|
||||||
|
if !entering {
|
||||||
|
literal := ""
|
||||||
|
ast.WalkFunc(heading, func(n ast.Node, e bool) ast.WalkStatus {
|
||||||
|
if leaf := n.AsLeaf(); e && leaf != nil {
|
||||||
|
if literal != "" {
|
||||||
|
literal += ".*"
|
||||||
|
}
|
||||||
|
literal += string(leaf.Literal)
|
||||||
|
}
|
||||||
|
return ast.GoToNext
|
||||||
|
})
|
||||||
|
level := heading.Level
|
||||||
|
id := base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf(`^[ \t]*%s\s*%s(].*)?\s*$`, strings.Repeat("#", level), literal)))
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<form method="POST" target="/comment" name="%s" class="comment">
|
||||||
|
<input autocomplete="off" name="content" type="text"/>
|
||||||
|
<input type="submit"/>
|
||||||
|
</form>
|
||||||
|
`, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ast.GoToNext, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue