UPDATE Markdown

アスタルテで動いてる最新のMarkdownに追従する更新です。
一応テストしてから実装してください。
今回のアップデートで
+ 見出しのレイアウト変更
+ リストのレイアウトの変更
+ 罫線のレイアウトの変更
+ より詳細なclass分け
+ codeのハイライト
+ 外部サーバー向け画像添付メッセージの表示
+ 1件のセキュリティー的な問題の修正
などが変更になっています
This commit is contained in:
霧島ひなた 2018-11-28 20:02:48 +09:00 committed by yoheizuho
parent 0542d92c40
commit 4d4f8b5f52
2 changed files with 301 additions and 204 deletions

View File

@ -1,196 +1,266 @@
.status__content {
font-family: inherit;
max-height: 210px;
overflow-x: hidden;
overflow-y: auto;
h1{
font-size: 195%;
border-bottom: 2px solid #ff3333;
}
h2{
font-size: 180%;
border-bottom: 2px solid #ff3333;
}
h3{
font-size: 165%;
border-bottom: 2px solid #ff3333;
}
h4{
font-size: 150%;
border-bottom: 2px solid #ff3333;
}
h5{
font-size: 135%;
border-bottom: 2px solid #ff3333;
}
h6{
font-size: 120%;
border-bottom: 2px solid #ff3333;
}
em{
font-style: italic;
}
strong{
font-weight: bold;
}
code{
display: block;
border-left: 2px solid;
border-color: #079903;
color: $white;
padding-left: 10px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
background-color: #000000;
}
pre{
display: inline-block;
font-family: 'Noto Sans Japanese', sans-serif;
font-weight: 400;
}
p ~ blockquote {
margin-top: -8px;
}
blockquote{
padding-left: 8px;
margin-top: 0.5em;
margin-bottom: 0.5em;
color: $white;
background-color: $ui-base-color;
display: block;
border-left: 4px solid $classic-highlight-color;
}
ul{
list-style: inside;
br{
display: none;
}
}
ul>ul{
br{
display: none;
}
}
ul>li>ul{
padding-left: 1em;
list-style: inside circle;
}
ul>li{
padding-left: 1em;
list-style: inside circle;
}
ul>br>li{
padding-left: 1em;
list-style: inside circle;
}
ul>ul>li{
padding-left: 2em;
list-style: inside circle;
}
ul>br>ul>br>li{
padding-left: 2em;
list-style: inside circle;
}
ol{
list-style: inside decimal;
}
ol>li>ol{
padding-left: 1em;
}
p>a>img{
width: 100%;
height: 100%;
object-fit: contain;
}
a>img{
width: 100%;
height: 100%;
object-fit: contain;
}
p>a{
color: #1FBFF9;
}
a{
color: #1FBFF9;
}
sup{
font-size: 75.5%;
vertical-align: top;
position: relative;
top: -0.5em;
}
sub{
font-size: 75.5%;
vertical-align: bottom;
position: relative;
top: 0.5em;
}
small{
font-size: 50.0%;
vertical-align: bottom;
position: relative;
}
table {
margin-top: 0.5em;
margin-bottom: 0.5em;
color: $classic-highlight-color;
display: block;
width: 100%;
overflow: auto;
border-spacing: 0;
border-collapse: collapse;
}
table tr{
background-color: #000000;
}
table th, table td{
padding: 6px 13px;
border: 1px solid $classic-highlight-color;
}
table th{
font-weight: 600;
}
table thead tr{
background-color: $black;
}
td, th{
padding: 0;
}
}
.status__content {
font-family: inherit;
h1{
color: #ec840d;
font-weight: bold;
font-size: 1.6em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #ff0000;
}
h2{
color: #ec840d;
font-weight: bold;
font-size: 1.5em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #fffb00;
}
h3{
color: #ec840d;
font-weight: bold;
font-size: 1.4em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #2bff00;
}
h4{
color: #ec840d;
font-weight: bold;
font-size: 1.3em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #00ffea;
}
h5{
color: #ec840d;
font-weight: bold;
font-size: 1.2em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #0004ff;
}
h6{
color: #ec840d;
font-weight: bold;
font-size: 1.1em;
padding: 0.5em;
display: inline-block;
line-height: 1.3;
background: #dbebf8;
vertical-align: middle;
border-radius: 25px 25px 25px 25px;
text-align: center;
border-bottom: solid 3px #7700ff;
}
em{
font-style: italic;
}
strong{
font-weight: bold;
}
code{
display: block;
border-left: 2px solid;
border-color: #079903;
color: $white;
padding-left: 10px;
margin-top: 5px;
margin-bottom: 5px;
margin-left: 5px;
background-color: #000000;
.positive{
color: #5bda57;
}
.negative{
color: #ff4949;
}
.rust-fanc{
color: #ba7eff;
}
.ruby-func{
color: #24a8e6;
}
.rust-macro{
color: #d2ff6a;
}
.contents{
color: #ff9925;
}
}
pre{
display: inline-block;
font-family: 'Noto Sans Japanese', sans-serif;
font-weight: 400;
}
p ~ blockquote {
margin-top: -8px;
}
blockquote{
padding-left: 8px;
margin-top: 0.5em;
margin-bottom: 0.5em;
color: $primary-text-color;
background-color: $ui-base-color;
display: block;
border-left: 4px solid $classic-highlight-color;
}
ul.md-contents {
border: double 4px #21b384;
padding: 0.5em 1em 0.5em 2.3em;
position: relative;
}
ul li.md-contents {
line-height: 1.5;
padding: 0.2em 0;
list-style-type: none!important;
}
ul li.md-contents:before {
font-family: FontAwesome;
content: "\f0a4";
position: absolute;
left : 1em;
color: #21b384;
}
ol.md-contents {
border: double 4px #ff954f;
padding: 0.5em 1em 0.5em 1em;
position: relative;
list-style: inside decimal;
}
ol li.md-contents {
line-height: 1.5;
padding: 0.2em 0;
}
hr {
border-width: 2px 0px 0px 0px;
border-style: dashed;
border-color: #ff7676;
height: 1px;
}
p>a>img{
width: 100%;
height: 100%;
object-fit: contain;
}
a>img{
width: 100%;
height: 100%;
object-fit: contain;
}
p>a{
color: #1FBFF9;
}
a{
color: #1FBFF9;
}
sup{
font-size: 75.5%;
vertical-align: top;
position: relative;
top: -0.5em;
}
sub{
font-size: 75.5%;
vertical-align: bottom;
position: relative;
top: 0.5em;
}
small{
font-size: 50.0%;
vertical-align: bottom;
position: relative;
}
table {
margin-top: 0.5em;
margin-bottom: 0.5em;
color: $classic-highlight-color;
display: block;
width: 100%;
overflow: auto;
border-spacing: 0;
border-collapse: collapse;
}
table tr{
background-color: #000000;
}
table th, table td{
padding: 6px 13px;
border: 1px solid $classic-highlight-color;
}
table th{
font-weight: 600;
}
table thead tr{
background-color: $black;
}
td, th{
padding: 0;
}
span.img_FTL {
display: none;
}
}

View File

@ -88,26 +88,31 @@ class Formatter_Markdown
%(<h#{header_level}>#{encode(mdContentsRemoved)}</h#{header_level}>\n)
end
def block_code(code, language)
%(<br>#{code.strip})
end
def codespan(code)
urlRemoved = "#{remove_url(code)}"
escapedCode = "#{escape_bbcode(urlRemoved)}"
%(<code>#{encode(escapedCode)}</code>)
encoded = "#{encode(escapedCode)}"
%(<code>#{code_contents(encoded)}</code>)
end
def list(contents, list_type)
if list_type == :unordered
%(<ul>#{contents.strip}</ul>)
%(<ul class='md-contents'>#{contents.strip}</ul>)
elsif list_type == :ordered
%(<ol>#{contents.strip}</ol>)
%(<ol class='md-contents'>#{contents.strip}</ol>)
else
%(<#{list_type}>#{contents.strip}</#{list_type}>)
%(<#{list_type} class='md-contents'>#{contents.strip}</#{list_type}>)
end
end
def list_item(text, list_type)
urlRemoved = "#{remove_url(text)}"
mdContentsRemoved = "#{markdown_escape(urlRemoved)}"
%(<li>#{encode(mdContentsRemoved)}</li>)
%(<li class='md-contents'>#{encode(mdContentsRemoved)}</li>)
end
def emphasis(text)
@ -170,7 +175,7 @@ class Formatter_Markdown
if imgcheck !~ /\Ahttps:\/\/[^<>"\[\]  ]+\z/
%(#{encode(alt_text)})
else
%(<img src="#{URI.encode_www_form_component(link)}">)
%(<span class="img_FTL">画像が添付されています。</span><img src="#{URI.encode_www_form_component(link)}">)
end
end
@ -206,7 +211,7 @@ class Formatter_Markdown
#前々から要望があったcode内でBBCodeを無効化するための奴
def escape_bbcode(string)
string.gsub(/\[/){ "" }
string.gsub(/\[/){ "&#091;" }
end
#markdownの中でmarkdownを展開させないためのエスケープする奴
@ -221,6 +226,27 @@ class Formatter_Markdown
string.gsub(/<([\/]?a[^>]*|[\/]?img[^>]*|[\/]?code[^>]*|[\/]?h[1-6][^>]*|[\/]?sup[^>]*|[\/]?sub[^>]*|[\/]?small[^>]*|[\/]?ul[^>]*|[\/]?ol[^>]*|[\/]?li[^>]*|[\/]?hr[^>]*|[\/]?s[^>]*|[\/]?u[^>]*|[\/]?mark[^>]*)>/) { "" }
end
#code内の一部を色分けするための変更
def code_contents(string)
simple = string.gsub(/(true|error|false|failed|def|puts|end|fn|let|mut|use|String|println!)/ ,
"true" => "<span class='positive'>#{:true}</span>",
"error" => "<span class='negative'>#{:error}</span>",
"false" => "<span class='negative'>#{:false}</span>",
"failed" => "<span class='negative'>#{:failed}</span>",
"def" => "<span class='ruby-func'>#{:def}</span>",
"puts" => "<span class='ruby-func'>#{:puts}</span>",
"end" => "<span class='ruby-func'>#{:end}</span>",
"fn" => "<span class='rust-fanc'>#{:fn}</span>",
"let" => "<span class='rust-fanc'>#{:let}</span>",
"mut" => "<span class='rust-fanc'>#{:mut}</span>",
"use" => "<span class='rust-fanc'>#{:use}</span>",
"String" => "<span class='rust-macro'>#{:String}</span>",
"println!" => "<span class='rust-macro'>#{:println!}</span>",
)
simple.gsub(/(&quot;[a-zA-Z0-9_ ,]+&quot;)/){ "<span class='contents'>#{$1}</span>" }
# "" => "<span class=''>#{:}</span>",
end
#テストで書きなぐった奴
def html_escape(string)
string.gsub(/['&\"<>\/]/, {
@ -280,7 +306,8 @@ class MDExtractor
extractByHTMLTagName("br", false, true),
extractByHTMLTagName("a"),
extractByHTMLTagName("img", false, true),
extractByHTMLTagName("s")
extractByHTMLTagName("s"),
extractByHTMLTagName("span")
].flatten.compact
end