From e9f1a3c6775c8c3ae38d1c3d75af8a0649f2042b Mon Sep 17 00:00:00 2001 From: Azareal Date: Tue, 9 Apr 2019 15:33:39 +1000 Subject: [PATCH] Added support for

,

, and

to the core post parser. Changed a span to a div in Tempra Simple and Shadow so that nested divs will work properly. Added four parser tests. --- common/parser.go | 6 ++++++ parser_test.go | 4 ++++ templates/topic.html | 2 +- templates/topic_posts.html | 2 +- themes/cosora/public/main.css | 13 ++++++++++++- themes/nox/public/main.css | 17 +++++++++++++++++ themes/shadow/public/main.css | 16 +++++++++++++++- themes/tempra_simple/public/main.css | 27 ++++++++++++++++++++++++--- 8 files changed, 80 insertions(+), 7 deletions(-) diff --git a/common/parser.go b/common/parser.go index 2e978e6b..ad66a8d1 100644 --- a/common/parser.go +++ b/common/parser.go @@ -219,6 +219,7 @@ func PreparseMessage(msg string) string { 'u': []string{""}, 'b': []string{"", "lockquote"}, 'i': []string{""}, + 'h': []string{"1", "2", "3"}, //'p': []string{""}, 'g': []string{""}, // Quick and dirty fix for Grammarly } @@ -267,6 +268,11 @@ func PreparseMessage(msg string) string { &TagToAction{"lockquote", buildLitMatch("blockquote"), 0, false}, }, 'i': []*TagToAction{&TagToAction{"", buildLitMatch("em"), 0, false}}, + 'h': []*TagToAction{ + &TagToAction{"1", buildLitMatch("h2"), 0, false}, + &TagToAction{"2", buildLitMatch("h3"), 0, false}, + &TagToAction{"3", buildLitMatch("h4"), 0, false}, + }, //'p': []*TagToAction{&TagToAction{"", buildLitMatch2("\n\n", ""), 0, false}}, 'g': []*TagToAction{ &TagToAction{"", func(act *TagToAction, open bool, i int, runes []rune) (int, string) { diff --git a/parser_test.go b/parser_test.go index 79a715c1..b79fe7a6 100644 --- a/parser_test.go +++ b/parser_test.go @@ -47,6 +47,7 @@ func TestPreparser(t *testing.T) { msgList.Add("", "") msgList.Add("hi", "hi") + msgList.Add("h", "h") msgList.Add("hi", "hi") msgList.Add("hi", "hi") msgList.Add("hi", "hi") @@ -75,6 +76,9 @@ func TestPreparser(t *testing.T) { msgList.Add("", "") msgList.Add("", "") msgList.Add("", "") + msgList.Add("

t

", "

t

") + msgList.Add("

t

", "

t

") + msgList.Add("

t

", "

t

") msgList.Add("<>", "<></>") msgList.Add("<>", "</><>") msgList.Add("<>", "<>") diff --git a/templates/topic.html b/templates/topic.html index 07dcb8f8..e92361c0 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -54,7 +54,7 @@
- {{.Topic.ContentHTML}} +
{{.Topic.ContentHTML}}
{{if .CurrentUser.Loggedin}}{{end}} diff --git a/templates/topic_posts.html b/templates/topic_posts.html index 3d149495..be23e817 100644 --- a/templates/topic_posts.html +++ b/templates/topic_posts.html @@ -7,7 +7,7 @@ {{else}}
{{/** TODO: We might end up with
s in the inline editor, fix this **/}} - {{.ContentHtml}} +
{{.ContentHtml}}
{{if $.CurrentUser.Loggedin}}
{{.Content}}
{{end}} diff --git a/themes/cosora/public/main.css b/themes/cosora/public/main.css index 46c4bdec..0073b578 100644 --- a/themes/cosora/public/main.css +++ b/themes/cosora/public/main.css @@ -255,7 +255,7 @@ ul { .colstack_head h1 { font-size: 18px; } -h1, h2, h3 { +h1, h2, h3, h4, h5 { -webkit-margin-before: 0; -webkit-margin-after: 0; margin-block-start: 0; @@ -1067,6 +1067,17 @@ blockquote:first-child { .post_item .user_content { margin-bottom: 10px; } +.user_content h2, .user_content h3 { + margin-bottom: 12px; + font-weight: normal; +} +.user_content h4 { + margin-bottom: 8px; + font-weight: normal; +} +.user_content strong h2, .user_content strong h3, .user_content strong h4 { + font-weight: bold; +} .button_container { margin-top: auto; display: flex; diff --git a/themes/nox/public/main.css b/themes/nox/public/main.css index 3f72287e..a30f4fb1 100644 --- a/themes/nox/public/main.css +++ b/themes/nox/public/main.css @@ -841,6 +841,23 @@ blockquote:first-child { .user_content { word-break: break-word; } +.user_content h2 { + font-size: 20px; +} +.user_content h3 { + font-size: 19px; +} +.user_content h2, .user_content h3 { + margin-top: 3px; + margin-bottom: 12px; + margin-left: 0px; +} +.user_content h2 + br, .user_content h3 + br { + display: none; +} +.user_content strong h2, .user_content strong h3 { + font-weight: bold; +} .user_content.in_edit { padding: 0px; background: none; diff --git a/themes/shadow/public/main.css b/themes/shadow/public/main.css index 504438cd..ca497f5d 100644 --- a/themes/shadow/public/main.css +++ b/themes/shadow/public/main.css @@ -183,7 +183,7 @@ a { font-size: 16px; display: inline; } -h1, h2, h3 { +h1, h2, h3, h4, h5 { -webkit-margin-before: 0; -webkit-margin-after: 0; margin-block-start: 0; @@ -266,6 +266,20 @@ h1, h2, h3 { .user_content { word-break: break-word; } +.user_content h2 { + font-size: 18px; +} +.user_content h2, .user_content h3 { + margin-bottom: 12px; + display: block; +} +.user_content h4 { + margin-bottom: 8px; + display: block; +} +.user_content strong h2, .user_content strong h3, .user_content strong h4 { + font-weight: bold; +} .controls { width: 100%; diff --git a/themes/tempra_simple/public/main.css b/themes/tempra_simple/public/main.css index b7f5b627..41b895f8 100644 --- a/themes/tempra_simple/public/main.css +++ b/themes/tempra_simple/public/main.css @@ -152,7 +152,7 @@ li a { #back { display: flex; } -#main { +#back, #main { width: 100%; } main > *:last-child { @@ -257,13 +257,15 @@ main > *:last-child { } .rowhead h1, .colstack_head h1, .rowhead h2, .colstack_head h2 { + font-size: 16px; + margin-left: 4px; +} +h1, h2, h3, h4, h5 { -webkit-margin-before: 0; -webkit-margin-after: 0; margin-block-start: 0; margin-block-end: 0; font-weight: normal; - font-size: 16px; - margin-left: 4px; } .rowitem { @@ -669,6 +671,25 @@ button.username { opacity: 0.9; } +.user_content h2 { + font-size: 19px; +} +.user_content h3 { + font-size: 18px; +} +.user_content h4 { + font-size: 17px; +} +.user_content h2, .user_content h3 { + margin-bottom: 12px; +} +.user_content h4 { + margin-bottom: 8px; +} +.user_content strong h2, .user_content strong h3, .user_content strong h4 { + font-weight: bold; +} + .user_tag { float: right; color: #505050;