mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-03 21:46:22 -07:00
Add hash tag block
This commit is contained in:
parent
774885d0fd
commit
54a6f25476
7 changed files with 62 additions and 3 deletions
|
@ -31,3 +31,7 @@ div#staffmenu, div#watchermenu {
|
|||
background: black;
|
||||
border: 1px solid vars.$txtcol;
|
||||
}
|
||||
|
||||
.hashtag {
|
||||
background: #ffffff1a
|
||||
}
|
|
@ -1,2 +1,4 @@
|
|||
$namecol: #117743;
|
||||
$headercol: #AF0A0F;
|
||||
$headercol: #AF0A0F;
|
||||
$hideblock: #0000001a;
|
||||
$hashtagbg: #0000001a;
|
|
@ -1,4 +1,5 @@
|
|||
@use 'animations';
|
||||
@use 'colors';
|
||||
|
||||
#boardmenu-bottom {
|
||||
margin-top: 16px;
|
||||
|
@ -224,7 +225,7 @@ div.inlinepostprev {
|
|||
|
||||
.hideblock {
|
||||
border: 1px solid black;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
background: colors.$hideblock;
|
||||
}
|
||||
|
||||
.hideblock.open {
|
||||
|
@ -246,4 +247,13 @@ div.inlinepostprev {
|
|||
.dice-roll {
|
||||
border: 1px dashed #aaa;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hashtag {
|
||||
border: 1px solid #000;
|
||||
border-radius: 4px;
|
||||
margin: 2px;
|
||||
padding: 4px;
|
||||
display: inline-block;
|
||||
background: colors.$hashtagbg;
|
||||
}
|
|
@ -30,6 +30,10 @@ div#staffmenu, div#watchermenu {
|
|||
border: 1px solid #ACACAC;
|
||||
}
|
||||
|
||||
.hashtag {
|
||||
background: rgba(255, 255, 255, 0.1019607843);
|
||||
}
|
||||
|
||||
body {
|
||||
background: #1d1f21;
|
||||
color: #ACACAC;
|
||||
|
|
|
@ -242,7 +242,7 @@ div.inlinepostprev {
|
|||
|
||||
.hideblock {
|
||||
border: 1px solid black;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
background: rgba(0, 0, 0, 0.1019607843);
|
||||
}
|
||||
|
||||
.hideblock.open {
|
||||
|
@ -266,6 +266,15 @@ div.inlinepostprev {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hashtag {
|
||||
border: 1px solid #000;
|
||||
border-radius: 4px;
|
||||
margin: 2px;
|
||||
padding: 4px;
|
||||
display: inline-block;
|
||||
background: rgba(0, 0, 0, 0.1019607843);
|
||||
}
|
||||
|
||||
div.section-block {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ var (
|
|||
urlRE = regexp.MustCompile(`https?://(\S+)`)
|
||||
unsetBBcodeTags = []string{"center", "color", "img", "quote", "size"}
|
||||
diceRollRE = regexp.MustCompile(`\[(\d*)d(\d+)(?:([+-])(\d+))?\]`)
|
||||
hashTagRE = regexp.MustCompile(`\[#(.+)\]`)
|
||||
)
|
||||
|
||||
// InitPosting prepares the formatter and the temp post pruner
|
||||
|
@ -130,6 +131,9 @@ func FormatMessage(message string, boardDir string) (template.HTML, error) {
|
|||
if isGreentext {
|
||||
line += "</span>"
|
||||
}
|
||||
line = hashTagRE.ReplaceAllStringFunc(line, func(tag string) string {
|
||||
return fmt.Sprintf(`<span class="hashtag">%s</span>`, tag[1:len(tag)-1])
|
||||
})
|
||||
postLines[i] = line
|
||||
}
|
||||
return template.HTML(strings.Join(postLines, "<br />")), nil // skipcq: GSC-G203
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package posting
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
|
@ -210,3 +211,28 @@ func TestDiceRoll(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHashTags(t *testing.T) {
|
||||
config.SetVersion(versionStr)
|
||||
msgfmtr.Init()
|
||||
msg := `[#tag]
|
||||
[#t a g]
|
||||
[ #tag]
|
||||
[#tag ]
|
||||
[# tag]
|
||||
>greentext [#tag]
|
||||
[#js<script>alert("lol")</script>injection]`
|
||||
msgHTML, err := FormatMessage(msg, "test")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.Equal(t, template.HTML(
|
||||
`<span class="hashtag">#tag</span><br />`+
|
||||
`<span class="hashtag">#t a g</span><br />`+
|
||||
`[ #tag]<br />`+
|
||||
`<span class="hashtag">#tag </span><br />`+
|
||||
`<span class="hashtag"># tag</span><br />`+
|
||||
`<span class="greentext">>greentext <span class="hashtag">#tag</span></span><br />`+
|
||||
`<span class="hashtag">#js<script>alert("lol")</script>injection</span>`,
|
||||
), msgHTML)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue