improve text file attachment blocks
This commit is contained in:
parent
ef97d7fb31
commit
8be3f79abb
|
@ -15,6 +15,7 @@ import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: Use the template system?
|
||||||
// TODO: Somehow localise these?
|
// TODO: Somehow localise these?
|
||||||
var SpaceGap = []byte(" ")
|
var SpaceGap = []byte(" ")
|
||||||
var httpProtBytes = []byte("http://")
|
var httpProtBytes = []byte("http://")
|
||||||
|
@ -44,9 +45,13 @@ var attachOpen = []byte("<a class='attach'href=\"")
|
||||||
var attachClose = []byte("\"download>Attachment</a>")
|
var attachClose = []byte("\"download>Attachment</a>")
|
||||||
var sidParam = []byte("?sid=")
|
var sidParam = []byte("?sid=")
|
||||||
var stypeParam = []byte("&stype=")
|
var stypeParam = []byte("&stype=")
|
||||||
var textOpen = []byte("<a class='attach'href=\"")
|
/*var textShortOpen = []byte("<a class='attach'href=\"")
|
||||||
var textOpen2 = []byte("\">View</a> / <a class='attach'href=\"")
|
var textShortOpen2 = []byte("\">View</a> / <a class='attach'href=\"")
|
||||||
var textClose = []byte("\"download>Download</a>")
|
var textShortClose = []byte("\"download>Download</a>")*/
|
||||||
|
var textOpen = []byte("<div class='attach_box'><div class='attach_info'>")
|
||||||
|
var textOpen2 = []byte("</div><div class='attach_opts'><a class='attach'href=\"")
|
||||||
|
var textOpen3 = []byte("\">View</a> / <a class='attach'href=\"")
|
||||||
|
var textClose = []byte("\"download>Download</a></div></div>")
|
||||||
var urlPattern = `(?s)([ {1}])((http|https|ftp|mailto)*)(:{??)\/\/([\.a-zA-Z\/]+)([ {1}])`
|
var urlPattern = `(?s)([ {1}])((http|https|ftp|mailto)*)(:{??)\/\/([\.a-zA-Z\/]+)([ {1}])`
|
||||||
var urlReg *regexp.Regexp
|
var urlReg *regexp.Regexp
|
||||||
|
|
||||||
|
@ -140,6 +145,7 @@ func tryStepBackward(i, step int, runes []rune) (int, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Preparse Markdown and normalize it into HTML?
|
// TODO: Preparse Markdown and normalize it into HTML?
|
||||||
|
// TODO: Use a string builder
|
||||||
func PreparseMessage(msg string) string {
|
func PreparseMessage(msg string) string {
|
||||||
// TODO: Kick this check down a level into SanitiseBody?
|
// TODO: Kick this check down a level into SanitiseBody?
|
||||||
if !utf8.ValidString(msg) {
|
if !utf8.ValidString(msg) {
|
||||||
|
@ -717,7 +723,7 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
|
||||||
addImage(media.URL)
|
addImage(media.URL)
|
||||||
continue
|
continue
|
||||||
case AText:
|
case AText:
|
||||||
sb.Write(textOpen)
|
/*sb.Write(textOpen)
|
||||||
sb.WriteString(media.URL)
|
sb.WriteString(media.URL)
|
||||||
sb.Write(sidParam)
|
sb.Write(sidParam)
|
||||||
sid := strconv.Itoa(sectionID)
|
sid := strconv.Itoa(sectionID)
|
||||||
|
@ -733,6 +739,25 @@ func ParseMessage(msg string, sectionID int, sectionType string, settings *Parse
|
||||||
sb.Write(textClose)
|
sb.Write(textClose)
|
||||||
i += urlLen
|
i += urlLen
|
||||||
lastItem = i
|
lastItem = i
|
||||||
|
continue*/
|
||||||
|
sb.Write(textOpen)
|
||||||
|
sb.WriteString(media.URL)
|
||||||
|
sb.Write(textOpen2)
|
||||||
|
sb.WriteString(media.URL)
|
||||||
|
sb.Write(sidParam)
|
||||||
|
sid := strconv.Itoa(sectionID)
|
||||||
|
sb.WriteString(sid)
|
||||||
|
sb.Write(stypeParam)
|
||||||
|
sb.WriteString(sectionType)
|
||||||
|
sb.Write(textOpen3)
|
||||||
|
sb.WriteString(media.URL)
|
||||||
|
sb.Write(sidParam)
|
||||||
|
sb.WriteString(sid)
|
||||||
|
sb.Write(stypeParam)
|
||||||
|
sb.WriteString(sectionType)
|
||||||
|
sb.Write(textClose)
|
||||||
|
i += urlLen
|
||||||
|
lastItem = i
|
||||||
continue
|
continue
|
||||||
case AOther:
|
case AOther:
|
||||||
sb.Write(attachOpen)
|
sb.Write(attachOpen)
|
||||||
|
|
|
@ -252,7 +252,8 @@ func TestParser(t *testing.T) {
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png?sid=1", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
l.Add("//"+u+"/attachs/sha256hash.png?stype=forums", "<a href=\""+fs+"/attachs/sha256hash.png?sid=1&stype=forums\"><img src='"+fs+"/attachs/sha256hash.png?sid=1&stype=forums'class='postImage'></a>")
|
||||||
|
|
||||||
l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "<a class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&stype=forums\"download>Attachment</a>")
|
//l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "<a class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&stype=forums\"download>Attachment</a>")
|
||||||
|
l.Add("//"+u+"/attachs/sha256hash.txt?sid=1&stype=forums", "<div class='attach_box'><div class='attach_info'>"+fs+"/attachs/sha256hash.txt</div><div class='attach_opts'><a class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&stype=forums\">View</a> / <a class='attach'href=\""+fs+"/attachs/sha256hash.txt?sid=1&stype=forums\"download>Download</a></div></div>")
|
||||||
|
|
||||||
l.Add("//example.com/image.png", "<a href=\"//example.com/image.png\"><img src='//example.com/image.png'class='postImage'></a>")
|
l.Add("//example.com/image.png", "<a href=\"//example.com/image.png\"><img src='//example.com/image.png'class='postImage'></a>")
|
||||||
l.Add("https://example.com/image.png", "<a href=\"https://example.com/image.png\"><img src='https://example.com/image.png'class='postImage'></a>")
|
l.Add("https://example.com/image.png", "<a href=\"https://example.com/image.png\"><img src='https://example.com/image.png'class='postImage'></a>")
|
||||||
|
|
|
@ -932,6 +932,11 @@ red {
|
||||||
.hide_spoil img {
|
.hide_spoil img {
|
||||||
content: " ";
|
content: " ";
|
||||||
}
|
}
|
||||||
|
.attach_box {
|
||||||
|
background-color: #5a5555;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
.update_buttons {
|
.update_buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: #444444;
|
background-color: #444444;
|
||||||
|
|
Loading…
Reference in New Issue