add new ContentedBBCodeTag option for contented 1.2.0++ thumbnails
This commit is contained in:
parent
fdb854e6c7
commit
c830c2b4dd
@ -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: "",
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
16
bbcode.go
16
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) + `\]`),
|
||||
`<a href="` + html.EscapeString(this.ContentedURL) + `p/${1}"><img class="imgur" alt="" src="` + html.EscapeString(this.ContentedURL) + `thumb/s/${1}" ></a>`,
|
||||
nil,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
for _, prr := range s_to_r {
|
||||
|
||||
for prr.match.MatchString(data) { // repeat until all recursive replacements are consumed
|
||||
|
@ -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(
|
||||
`<div class="info">`+
|
||||
`You are viewing specific revision of this page, last modified `+
|
||||
|
@ -1,13 +1,15 @@
|
||||
package yatwiki
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (this *WikiServer) routeFormatting(w http.ResponseWriter, r *http.Request) {
|
||||
pto := DefaultPageTemplateOptions(this.opts)
|
||||
pto.CurrentPageName = "Formatting help"
|
||||
pto.Content = `
|
||||
|
||||
content := `
|
||||
<h2>Formatting help</h2><br><br>
|
||||
<ul>
|
||||
<li>[h]header[/h]</li>
|
||||
@ -21,9 +23,20 @@ func (this *WikiServer) routeFormatting(w http.ResponseWriter, r *http.Request)
|
||||
<li>[article=page name]title[/article] or [rev=id]title[/rev]</li>
|
||||
<li>[img]image-url[/img]</li>
|
||||
<li>[imgur]asdf.jpg[/imgur]</li>
|
||||
`
|
||||
if len(this.opts.ContentedBBCodeTag) > 0 {
|
||||
content += `
|
||||
<li>[` + this.opts.ContentedBBCodeTag + `]abc[/` + this.opts.ContentedBBCodeTag + `]</li>
|
||||
`
|
||||
}
|
||||
|
||||
content += `
|
||||
<li>[code]fixed width[/code]</li>
|
||||
<li>[section=header]content[/section]</li>
|
||||
<li>[html]raw html[/html]</li>
|
||||
</ul>`
|
||||
|
||||
pto.Content = template.HTML(content)
|
||||
|
||||
this.servePageResponse(w, r, pto)
|
||||
}
|
||||
|
2
rView.go
2
rView.go
@ -30,7 +30,7 @@ func (this *WikiServer) routeView(w http.ResponseWriter, r *http.Request, articl
|
||||
pto.CurrentPageName = articleTitle
|
||||
pto.CurrentPageIsArticle = true
|
||||
|
||||
bcr := NewBBCodeRenderer(this.opts.ExpectBaseURL)
|
||||
bcr := this.GetBBCodeRenderer()
|
||||
pto.Content = bcr.RenderHTML(string(a.Body))
|
||||
pto.LoadCodeResources = bcr.CodePresent
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user