Add code block to Creole and Markdown
This commit is contained in:
@@ -41,7 +41,6 @@ type state struct {
|
||||
prevLine string
|
||||
line string
|
||||
title string
|
||||
firstCode bool
|
||||
outerDeco decoMode
|
||||
innerDeco decoMode
|
||||
}
|
||||
@@ -620,10 +619,11 @@ func handleBlock(s *state) bool {
|
||||
|
||||
// open code block
|
||||
if s.block != blockRaw && s.block != blockCode &&
|
||||
s.block != blockMath && s.prevLine == "{{{" && isBlank(s.line) {
|
||||
s.block != blockMath && s.line == "{{{" {
|
||||
s.text.WriteString("{{{\n")
|
||||
s.plain.WriteString("\n")
|
||||
ensureBlock(s, blockCode)
|
||||
nextLine(s)
|
||||
s.firstCode = true
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -645,11 +645,10 @@ func handleBlock(s *state) bool {
|
||||
}
|
||||
|
||||
// close code block
|
||||
if s.block == blockCode && s.prevLine == "" && s.line == "}}}" {
|
||||
if s.block == blockCode && s.line == "}}}" {
|
||||
ensureBlock(s, blockNone)
|
||||
s.text.WriteString("}}}\n\n")
|
||||
s.text.WriteString("}}}\n")
|
||||
s.plain.WriteString("\n")
|
||||
s.html.WriteString("<span class=\"markup\">}}}</span>\n")
|
||||
nextLine(s)
|
||||
return true
|
||||
}
|
||||
@@ -723,12 +722,6 @@ func handleBlock(s *state) bool {
|
||||
|
||||
// in code block
|
||||
if s.block == blockCode {
|
||||
if s.firstCode {
|
||||
s.text.WriteString("\n")
|
||||
s.html.WriteString("\n")
|
||||
s.firstCode = false
|
||||
}
|
||||
|
||||
s.text.WriteString(s.line)
|
||||
s.text.WriteString("\n")
|
||||
|
||||
@@ -754,13 +747,6 @@ func handleBlock(s *state) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if s.line == "{{{" {
|
||||
s.text.WriteString("{{{\n")
|
||||
s.html.WriteString("<span class=\"markup\">{{{</span>\n")
|
||||
nextLine(s)
|
||||
return true
|
||||
}
|
||||
|
||||
if s.line == "" {
|
||||
ensureBlock(s, blockNone)
|
||||
s.text.WriteString("\n")
|
||||
@@ -805,7 +791,6 @@ func Apply(fc formatConfig, title string, text string) (
|
||||
prevLine: "",
|
||||
line: "",
|
||||
title: "",
|
||||
firstCode: false,
|
||||
outerDeco: decoNone,
|
||||
innerDeco: decoNone,
|
||||
}
|
||||
|
||||
@@ -145,6 +145,15 @@ func TestApply(t *testing.T) {
|
||||
"This is a test.\n",
|
||||
"<p>\nThis <em>is</em> a test.\n</p>\n",
|
||||
},
|
||||
{
|
||||
"code",
|
||||
"WikiPage",
|
||||
"{{{\nbegin\n print\nend\n}}}\n",
|
||||
"WikiPage",
|
||||
"{{{\nbegin\n print\nend\n}}}\n",
|
||||
"\nbegin\n print\nend\n\n",
|
||||
"<pre><code>begin\n print\nend\n</code></pre>\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -41,7 +41,6 @@ type state struct {
|
||||
prevLine string
|
||||
line string
|
||||
title string
|
||||
firstCode bool
|
||||
outerDeco decoMode
|
||||
innerDeco decoMode
|
||||
}
|
||||
@@ -692,10 +691,11 @@ func handleBlock(s *state) bool {
|
||||
|
||||
// open code block
|
||||
if s.block != blockRaw && s.block != blockCode &&
|
||||
s.block != blockMath && s.prevLine == "{{{" && isBlank(s.line) {
|
||||
s.block != blockMath && s.line == "```" {
|
||||
s.text.WriteString("```\n")
|
||||
s.plain.WriteString("\n")
|
||||
ensureBlock(s, blockCode)
|
||||
nextLine(s)
|
||||
s.firstCode = true
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -717,11 +717,10 @@ func handleBlock(s *state) bool {
|
||||
}
|
||||
|
||||
// close code block
|
||||
if s.block == blockCode && s.prevLine == "" && s.line == "}}}" {
|
||||
if s.block == blockCode && s.line == "```" {
|
||||
ensureBlock(s, blockNone)
|
||||
s.text.WriteString("}}}\n\n")
|
||||
s.text.WriteString("```\n")
|
||||
s.plain.WriteString("\n")
|
||||
s.html.WriteString("<span class=\"markup\">}}}</span>\n")
|
||||
nextLine(s)
|
||||
return true
|
||||
}
|
||||
@@ -795,12 +794,6 @@ func handleBlock(s *state) bool {
|
||||
|
||||
// in code block
|
||||
if s.block == blockCode {
|
||||
if s.firstCode {
|
||||
s.text.WriteString("\n")
|
||||
s.html.WriteString("\n")
|
||||
s.firstCode = false
|
||||
}
|
||||
|
||||
s.text.WriteString(s.line)
|
||||
s.text.WriteString("\n")
|
||||
|
||||
@@ -826,13 +819,6 @@ func handleBlock(s *state) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if s.line == "{{{" {
|
||||
s.text.WriteString("{{{\n")
|
||||
s.html.WriteString("<span class=\"markup\">{{{</span>\n")
|
||||
nextLine(s)
|
||||
return true
|
||||
}
|
||||
|
||||
if s.line == "" {
|
||||
ensureBlock(s, blockNone)
|
||||
s.text.WriteString("\n")
|
||||
@@ -877,7 +863,6 @@ func Apply(fc formatConfig, title string, text string) (
|
||||
prevLine: "",
|
||||
line: "",
|
||||
title: "",
|
||||
firstCode: false,
|
||||
outerDeco: decoNone,
|
||||
innerDeco: decoNone,
|
||||
}
|
||||
|
||||
@@ -154,6 +154,15 @@ func TestApply(t *testing.T) {
|
||||
"This is a test.\n",
|
||||
"<p>\nThis <em>is</em> a test.\n</p>\n",
|
||||
},
|
||||
{
|
||||
"code",
|
||||
"WikiPage",
|
||||
"```\nbegin\n print\nend\n```\n",
|
||||
"WikiPage",
|
||||
"```\nbegin\n print\nend\n```\n",
|
||||
"\nbegin\n print\nend\n\n",
|
||||
"<pre><code>begin\n print\nend\n</code></pre>\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -634,9 +634,8 @@ func handleBlock(s *state) bool {
|
||||
|
||||
// close code block
|
||||
if s.block == blockCode && s.prevLine == "" && s.line == "}}}" {
|
||||
ensureBlock(s, blockNone)
|
||||
ensureBlock(s, blockParagraph)
|
||||
s.text.WriteString("}}}\n\n")
|
||||
s.plain.WriteString("\n")
|
||||
s.html.WriteString("<span class=\"markup\">}}}</span>\n")
|
||||
nextLine(s)
|
||||
return true
|
||||
@@ -723,8 +722,7 @@ func handleBlock(s *state) bool {
|
||||
if s.block == blockCode {
|
||||
if s.firstCode {
|
||||
s.text.WriteString("\n")
|
||||
s.html.WriteString("\n")
|
||||
s.firstCode = false
|
||||
s.plain.WriteString("\n")
|
||||
}
|
||||
|
||||
s.text.WriteString(s.line)
|
||||
@@ -733,8 +731,12 @@ func handleBlock(s *state) bool {
|
||||
s.plain.WriteString(s.line)
|
||||
s.plain.WriteString("\n")
|
||||
|
||||
if s.firstCode {
|
||||
s.firstCode = false
|
||||
} else {
|
||||
s.html.WriteString("\n")
|
||||
}
|
||||
s.html.WriteString(template.HTMLEscapeString(s.line))
|
||||
s.html.WriteString("\n")
|
||||
|
||||
nextLine(s)
|
||||
return true
|
||||
@@ -753,6 +755,7 @@ func handleBlock(s *state) bool {
|
||||
}
|
||||
|
||||
if s.line == "{{{" {
|
||||
ensureBlock(s, blockParagraph)
|
||||
s.text.WriteString("{{{\n")
|
||||
s.html.WriteString("<span class=\"markup\">{{{</span>\n")
|
||||
nextLine(s)
|
||||
|
||||
@@ -118,6 +118,15 @@ func TestApply(t *testing.T) {
|
||||
"This is a test.\n",
|
||||
"<p>\nThis <span class=\"markup\">//</span><em>is</em><span class=\"markup\">//</span> a test.\n</p>\n",
|
||||
},
|
||||
{
|
||||
"code",
|
||||
"WikiPage",
|
||||
"{{{\n\nbegin\n print\nend\n\n}}}\n\n",
|
||||
"WikiPage",
|
||||
"{{{\n\nbegin\n print\nend\n\n}}}\n\n",
|
||||
"\nbegin\n print\nend\n\n",
|
||||
"<p>\n<span class=\"markup\">{{{</span>\n</p>\n<pre><code>begin\n print\nend\n</code></pre>\n<p>\n<span class=\"markup\">}}}</span>\n</p>\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user