Added support for <h1>, <h2>, and <h3> 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.
This commit is contained in:
Azareal 2019-04-09 15:33:39 +10:00
parent 0bb46c9d67
commit e9f1a3c677
8 changed files with 80 additions and 7 deletions

View File

@ -219,6 +219,7 @@ func PreparseMessage(msg string) string {
'u': []string{""}, 'u': []string{""},
'b': []string{"", "lockquote"}, 'b': []string{"", "lockquote"},
'i': []string{""}, 'i': []string{""},
'h': []string{"1", "2", "3"},
//'p': []string{""}, //'p': []string{""},
'g': []string{""}, // Quick and dirty fix for Grammarly 'g': []string{""}, // Quick and dirty fix for Grammarly
} }
@ -267,6 +268,11 @@ func PreparseMessage(msg string) string {
&TagToAction{"lockquote", buildLitMatch("blockquote"), 0, false}, &TagToAction{"lockquote", buildLitMatch("blockquote"), 0, false},
}, },
'i': []*TagToAction{&TagToAction{"", buildLitMatch("em"), 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}}, //'p': []*TagToAction{&TagToAction{"", buildLitMatch2("\n\n", ""), 0, false}},
'g': []*TagToAction{ 'g': []*TagToAction{
&TagToAction{"", func(act *TagToAction, open bool, i int, runes []rune) (int, string) { &TagToAction{"", func(act *TagToAction, open bool, i int, runes []rune) (int, string) {

View File

@ -47,6 +47,7 @@ func TestPreparser(t *testing.T) {
msgList.Add("<b></b>", "<strong></strong>") msgList.Add("<b></b>", "<strong></strong>")
msgList.Add("<b>hi</b>", "<strong>hi</strong>") msgList.Add("<b>hi</b>", "<strong>hi</strong>")
msgList.Add("<b>h</b>", "<strong>h</strong>")
msgList.Add("<s>hi</s>", "<del>hi</del>") msgList.Add("<s>hi</s>", "<del>hi</del>")
msgList.Add("<del>hi</del>", "<del>hi</del>") msgList.Add("<del>hi</del>", "<del>hi</del>")
msgList.Add("<u>hi</u>", "<u>hi</u>") msgList.Add("<u>hi</u>", "<u>hi</u>")
@ -75,6 +76,9 @@ func TestPreparser(t *testing.T) {
msgList.Add("<span ></span>", "") msgList.Add("<span ></span>", "")
msgList.Add("<span><span></span></span>", "") msgList.Add("<span><span></span></span>", "")
msgList.Add("<span><b></b></span>", "<strong></strong>") msgList.Add("<span><b></b></span>", "<strong></strong>")
msgList.Add("<h1>t</h1>", "<h2>t</h2>")
msgList.Add("<h2>t</h2>", "<h3>t</h3>")
msgList.Add("<h3>t</h3>", "<h4>t</h4>")
msgList.Add("<></>", "&lt;&gt;&lt;/&gt;") msgList.Add("<></>", "&lt;&gt;&lt;/&gt;")
msgList.Add("</><>", "&lt;/&gt;&lt;&gt;") msgList.Add("</><>", "&lt;/&gt;&lt;&gt;")
msgList.Add("<>", "&lt;&gt;") msgList.Add("<>", "&lt;&gt;")

View File

@ -54,7 +54,7 @@
<article {{scope "opening_post"}} itemscope itemtype="http://schema.org/CreativeWork" class="rowblock post_container top_post" aria-label="{{lang "topic.opening_post_aria"}}"> <article {{scope "opening_post"}} itemscope itemtype="http://schema.org/CreativeWork" class="rowblock post_container top_post" aria-label="{{lang "topic.opening_post_aria"}}">
<div class="rowitem passive editable_parent post_item {{.Topic.ClassName}}" style="background-image: url({{.Topic.Avatar}}), url(/static/{{.Header.Theme.Name}}/post-avatar-bg.jpg);background-position: 0px {{if le .Topic.ContentLines 5}}-1{{end}}0px;background-repeat:no-repeat, repeat-y;"> <div class="rowitem passive editable_parent post_item {{.Topic.ClassName}}" style="background-image: url({{.Topic.Avatar}}), url(/static/{{.Header.Theme.Name}}/post-avatar-bg.jpg);background-position: 0px {{if le .Topic.ContentLines 5}}-1{{end}}0px;background-repeat:no-repeat, repeat-y;">
<span class="hide_on_edit topic_content user_content" itemprop="text" style="margin:0;padding:0;">{{.Topic.ContentHTML}}</span> <div class="hide_on_edit topic_content user_content" itemprop="text">{{.Topic.ContentHTML}}</div>
{{if .CurrentUser.Loggedin}}<textarea name="topic_content" class="show_on_edit topic_content_input edit_source">{{.Topic.Content}}</textarea>{{end}} {{if .CurrentUser.Loggedin}}<textarea name="topic_content" class="show_on_edit topic_content_input edit_source">{{.Topic.Content}}</textarea>{{end}}
<span class="controls{{if .Topic.LikeCount}} has_likes{{end}}" aria-label="{{lang "topic.post_controls_aria"}}"> <span class="controls{{if .Topic.LikeCount}} has_likes{{end}}" aria-label="{{lang "topic.post_controls_aria"}}">

View File

@ -7,7 +7,7 @@
{{else}} {{else}}
<article {{scope "post"}} id="post-{{.ID}}" itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item {{.ClassName}}" style="background-image: url({{.Avatar}}), url(/static/{{$.Header.Theme.Name}}/post-avatar-bg.jpg);background-position: 0px {{if le .ContentLines 5}}-1{{end}}0px;background-repeat:no-repeat, repeat-y;"> <article {{scope "post"}} id="post-{{.ID}}" itemscope itemtype="http://schema.org/CreativeWork" class="rowitem passive deletable_block editable_parent post_item {{.ClassName}}" style="background-image: url({{.Avatar}}), url(/static/{{$.Header.Theme.Name}}/post-avatar-bg.jpg);background-position: 0px {{if le .ContentLines 5}}-1{{end}}0px;background-repeat:no-repeat, repeat-y;">
{{/** TODO: We might end up with <br>s in the inline editor, fix this **/}} {{/** TODO: We might end up with <br>s in the inline editor, fix this **/}}
<span class="editable_block user_content" itemprop="text" style="margin:0;padding:0;">{{.ContentHtml}}</span> <div class="editable_block user_content" itemprop="text">{{.ContentHtml}}</div>
{{if $.CurrentUser.Loggedin}}<div class="auto_hide edit_source">{{.Content}}</div>{{end}} {{if $.CurrentUser.Loggedin}}<div class="auto_hide edit_source">{{.Content}}</div>{{end}}
<span class="controls{{if .LikeCount}} has_likes{{end}}"> <span class="controls{{if .LikeCount}} has_likes{{end}}">

View File

@ -255,7 +255,7 @@ ul {
.colstack_head h1 { .colstack_head h1 {
font-size: 18px; font-size: 18px;
} }
h1, h2, h3 { h1, h2, h3, h4, h5 {
-webkit-margin-before: 0; -webkit-margin-before: 0;
-webkit-margin-after: 0; -webkit-margin-after: 0;
margin-block-start: 0; margin-block-start: 0;
@ -1067,6 +1067,17 @@ blockquote:first-child {
.post_item .user_content { .post_item .user_content {
margin-bottom: 10px; 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 { .button_container {
margin-top: auto; margin-top: auto;
display: flex; display: flex;

View File

@ -841,6 +841,23 @@ blockquote:first-child {
.user_content { .user_content {
word-break: break-word; 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 { .user_content.in_edit {
padding: 0px; padding: 0px;
background: none; background: none;

View File

@ -183,7 +183,7 @@ a {
font-size: 16px; font-size: 16px;
display: inline; display: inline;
} }
h1, h2, h3 { h1, h2, h3, h4, h5 {
-webkit-margin-before: 0; -webkit-margin-before: 0;
-webkit-margin-after: 0; -webkit-margin-after: 0;
margin-block-start: 0; margin-block-start: 0;
@ -266,6 +266,20 @@ h1, h2, h3 {
.user_content { .user_content {
word-break: break-word; 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 { .controls {
width: 100%; width: 100%;

View File

@ -152,7 +152,7 @@ li a {
#back { #back {
display: flex; display: flex;
} }
#main { #back, #main {
width: 100%; width: 100%;
} }
main > *:last-child { main > *:last-child {
@ -257,13 +257,15 @@ main > *:last-child {
} }
.rowhead h1, .colstack_head h1, .rowhead h1, .colstack_head h1,
.rowhead h2, .colstack_head h2 { .rowhead h2, .colstack_head h2 {
font-size: 16px;
margin-left: 4px;
}
h1, h2, h3, h4, h5 {
-webkit-margin-before: 0; -webkit-margin-before: 0;
-webkit-margin-after: 0; -webkit-margin-after: 0;
margin-block-start: 0; margin-block-start: 0;
margin-block-end: 0; margin-block-end: 0;
font-weight: normal; font-weight: normal;
font-size: 16px;
margin-left: 4px;
} }
.rowitem { .rowitem {
@ -669,6 +671,25 @@ button.username {
opacity: 0.9; 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 { .user_tag {
float: right; float: right;
color: #505050; color: #505050;