diff --git a/ServerOptions.go b/ServerOptions.go index ea5261a..0c322a8 100644 --- a/ServerOptions.go +++ b/ServerOptions.go @@ -22,6 +22,7 @@ type ServerOptions struct { DeclareRSSLanguage string DeclareRSSEmail string ContentedServer string + ContentedBBCodeTag string } func DefaultOptions() *ServerOptions { @@ -43,5 +44,6 @@ func DefaultOptions() *ServerOptions { DeclareRSSLanguage: "en-GB", DeclareRSSEmail: `nobody@example.com`, ContentedServer: "", + ContentedBBCodeTag: "", } } diff --git a/WikiServer.go b/WikiServer.go index c36d35f..b58df7f 100644 --- a/WikiServer.go +++ b/WikiServer.go @@ -76,6 +76,10 @@ func NewWikiServer(opts *ServerOptions) (*WikiServer, error) { return &ws, nil } +func (this *WikiServer) GetBBCodeRenderer() *BBCodeRenderer { + return NewBBCodeRenderer(this.opts.ExpectBaseURL, this.opts.ContentedServer, this.opts.ContentedBBCodeTag) +} + func (this *WikiServer) Close() { this.db.Close() } diff --git a/bbcode.go b/bbcode.go index e7f1dc8..cb1fea1 100644 --- a/bbcode.go +++ b/bbcode.go @@ -2,6 +2,7 @@ package yatwiki import ( "encoding/json" + "html" "html/template" "net/url" "regexp" @@ -13,13 +14,17 @@ type BBCodeRenderer struct { baseUrl string CodePresent bool DynamicContentWarning string + ContentedURL string + ContentedTag string } -func NewBBCodeRenderer(baseUrl string) *BBCodeRenderer { +func NewBBCodeRenderer(baseUrl, ContentedURL, ContentedTag string) *BBCodeRenderer { return &BBCodeRenderer{ baseUrl: baseUrl, CodePresent: false, DynamicContentWarning: `⚠ run dynamic content`, + ContentedURL: ContentedURL, + ContentedTag: ContentedTag, } } @@ -61,6 +66,15 @@ func (this *BBCodeRenderer) bbcode(data string) string { }}, } + if len(this.ContentedTag) > 0 { + s_to_r = append(s_to_r, + pregReplaceRule{regexp.MustCompile(`(?si)\[` + regexp.QuoteMeta(this.ContentedTag) + `\](.*?)\[/` + regexp.QuoteMeta(this.ContentedTag) + `\]`), + ``, + nil, + }, + ) + } + for _, prr := range s_to_r { for prr.match.MatchString(data) { // repeat until all recursive replacements are consumed diff --git a/rArchive.go b/rArchive.go index c3a26e6..783575b 100644 --- a/rArchive.go +++ b/rArchive.go @@ -25,7 +25,7 @@ func (this *WikiServer) routeArchive(w http.ResponseWriter, r *http.Request, rev pto.CurrentPageName = a.Title pto.CurrentPageIsArticle = true - bcr := NewBBCodeRenderer(this.opts.ExpectBaseURL) + bcr := this.GetBBCodeRenderer() pto.Content = template.HTML( `