Add quotes and a half-assed code tag
This commit is contained in:
parent
6e7a398dee
commit
2f37e07100
Binary file not shown.
|
@ -1,9 +1,9 @@
|
||||||
package parsing
|
package parsing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"git.handmade.network/hmn/hmn/src/hmnurl"
|
||||||
"github.com/frustra/bbcode"
|
"github.com/frustra/bbcode"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
gast "github.com/yuin/goldmark/ast"
|
gast "github.com/yuin/goldmark/ast"
|
||||||
|
@ -27,6 +27,7 @@ func init() {
|
||||||
type attr struct {
|
type attr struct {
|
||||||
Name, Value string
|
Name, Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
addSimpleTag := func(name, tag string, notext bool, attrs ...attr) {
|
addSimpleTag := func(name, tag string, notext bool, attrs ...attr) {
|
||||||
var tagFunc bbcode.TagCompilerFunc = func(bn *bbcode.BBCodeNode) (*bbcode.HTMLTag, bool) {
|
var tagFunc bbcode.TagCompilerFunc = func(bn *bbcode.BBCodeNode) (*bbcode.HTMLTag, bool) {
|
||||||
if notext {
|
if notext {
|
||||||
|
@ -34,8 +35,6 @@ func init() {
|
||||||
for _, child := range bn.Children {
|
for _, child := range bn.Children {
|
||||||
if child.ID != bbcode.TEXT {
|
if child.ID != bbcode.TEXT {
|
||||||
newChildren = append(newChildren, child)
|
newChildren = append(newChildren, child)
|
||||||
} else {
|
|
||||||
fmt.Printf("%+v", child)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bn.Children = newChildren
|
bn.Children = newChildren
|
||||||
|
@ -51,6 +50,10 @@ func init() {
|
||||||
previewBBCodeCompiler.SetTag(name, tagFunc)
|
previewBBCodeCompiler.SetTag(name, tagFunc)
|
||||||
realBBCodeCompiler.SetTag(name, tagFunc)
|
realBBCodeCompiler.SetTag(name, tagFunc)
|
||||||
}
|
}
|
||||||
|
addTag := func(name string, f bbcode.TagCompilerFunc) {
|
||||||
|
previewBBCodeCompiler.SetTag(name, f)
|
||||||
|
realBBCodeCompiler.SetTag(name, f)
|
||||||
|
}
|
||||||
|
|
||||||
previewBBCodeCompiler.SetTag("youtube", makeYoutubeBBCodeFunc(true))
|
previewBBCodeCompiler.SetTag("youtube", makeYoutubeBBCodeFunc(true))
|
||||||
realBBCodeCompiler.SetTag("youtube", makeYoutubeBBCodeFunc(false))
|
realBBCodeCompiler.SetTag("youtube", makeYoutubeBBCodeFunc(false))
|
||||||
|
@ -67,6 +70,52 @@ func init() {
|
||||||
addSimpleTag("tr", "tr", true)
|
addSimpleTag("tr", "tr", true)
|
||||||
addSimpleTag("th", "th", false)
|
addSimpleTag("th", "th", false)
|
||||||
addSimpleTag("td", "td", false)
|
addSimpleTag("td", "td", false)
|
||||||
|
|
||||||
|
addTag("quote", func(bn *bbcode.BBCodeNode) (*bbcode.HTMLTag, bool) {
|
||||||
|
cite := bn.GetOpeningTag().Value
|
||||||
|
if cite == "" {
|
||||||
|
out := bbcode.NewHTMLTag("")
|
||||||
|
out.Name = "blockquote"
|
||||||
|
return out, true
|
||||||
|
} else {
|
||||||
|
out := bbcode.NewHTMLTag("")
|
||||||
|
out.Name = "blockquote"
|
||||||
|
out.Attrs["cite"] = cite
|
||||||
|
|
||||||
|
a := bbcode.NewHTMLTag("")
|
||||||
|
a.Name = "a"
|
||||||
|
a.Attrs = map[string]string{
|
||||||
|
"href": hmnurl.BuildMember(cite),
|
||||||
|
"class": "quotewho",
|
||||||
|
}
|
||||||
|
a.AppendChild(bbcode.NewHTMLTag(cite))
|
||||||
|
|
||||||
|
br := bbcode.NewHTMLTag("")
|
||||||
|
br.Name = "br"
|
||||||
|
|
||||||
|
out.AppendChild(a)
|
||||||
|
out.AppendChild(br)
|
||||||
|
|
||||||
|
return out, true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
addTag("code", func(bn *bbcode.BBCodeNode) (*bbcode.HTMLTag, bool) {
|
||||||
|
lang := ""
|
||||||
|
if tagvalue := bn.GetOpeningTag().Value; tagvalue != "" {
|
||||||
|
lang = tagvalue
|
||||||
|
} else if arglang, ok := bn.GetOpeningTag().Args["language"]; ok {
|
||||||
|
lang = arglang
|
||||||
|
}
|
||||||
|
|
||||||
|
out := bbcode.NewHTMLTag("")
|
||||||
|
out.Name = "pre"
|
||||||
|
|
||||||
|
// TODO: After figuring out code for Markdown, put it here too.
|
||||||
|
_ = lang
|
||||||
|
|
||||||
|
return out, true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeYoutubeBBCodeFunc(preview bool) bbcode.TagCompilerFunc {
|
func makeYoutubeBBCodeFunc(preview bool) bbcode.TagCompilerFunc {
|
||||||
|
@ -206,7 +255,6 @@ func (s bbcodeParser) Parse(parent gast.Node, block text.Reader, pc parser.Conte
|
||||||
|
|
||||||
unparsedBBCode := restOfSource[:endIndex]
|
unparsedBBCode := restOfSource[:endIndex]
|
||||||
block.Advance(len(unparsedBBCode))
|
block.Advance(len(unparsedBBCode))
|
||||||
fmt.Println("parse this", string(unparsedBBCode))
|
|
||||||
|
|
||||||
compiler := realBBCodeCompiler
|
compiler := realBBCodeCompiler
|
||||||
if s.Preview {
|
if s.Preview {
|
||||||
|
|
Loading…
Reference in New Issue