From cc5afc95e52967079062d79ed08a72bf6dc2c3cb Mon Sep 17 00:00:00 2001
From: Aki Kareha
\n") } else if block == blockRaw { + s.html.WriteString("
")
+ } else if block == blockCode {
s.text.WriteString("\n")
s.plain.WriteString("\n")
s.html.WriteString("")
@@ -182,7 +208,7 @@ func math(cfg *config.Config, s *state) bool {
if end == -1 {
return false
}
- text := s.data[s.index + 2:s.index + 2 + end]
+ text := s.data[s.index+2 : s.index+2+end]
html := template.HTMLEscapeString(string(text))
s.text.WriteString("%%" + string(text) + "%%")
s.plain.WriteString(string(text))
@@ -308,7 +334,7 @@ func em(cfg *config.Config, s *state) bool {
func camel(s *state) bool {
if s.index > 0 {
- c := s.data[s.index - 1]
+ c := s.data[s.index-1]
if c >= 'A' && c <= 'Z' {
return false
}
@@ -346,7 +372,7 @@ func camel(s *state) bool {
upper := true
for i < len(line) {
c = line[i]
- if c >= '0' && c <='9' {
+ if c >= '0' && c <= '9' {
i += 1
for i < len(line) {
c = line[i]
@@ -399,7 +425,7 @@ func wikiLink(s *state) bool {
if ket == -1 {
return false
}
- name := string(line[2:2 + ket])
+ name := string(line[2 : 2+ket])
s.text.WriteString("[[" + name + "]]")
s.plain.WriteString(name)
@@ -410,7 +436,7 @@ func wikiLink(s *state) bool {
}
func spaceIndex(b []byte) int {
- for i := 0; i < len(b) ; i += 1 {
+ for i := 0; i < len(b); i += 1 {
c := b[i]
if c == '\r' || c == '\n' || c == ' ' || c == '\t' {
return i
@@ -425,7 +451,7 @@ func link(cfg *config.Config, s *state) bool {
return false
}
space := spaceIndex(line[6:])
- rawURL := string(line[:6 + space])
+ rawURL := string(line[:6+space])
u, err := url.Parse(rawURL)
if err != nil || u.Scheme != "https" {
@@ -436,7 +462,7 @@ func link(cfg *config.Config, s *state) bool {
ext := filepath.Ext(filename)
extFound := false
for _, extension := range cfg.Image.Extensions {
- if ext == "." + extension {
+ if ext == "."+extension {
extFound = true
break
}
@@ -569,7 +595,29 @@ func markup(cfg *config.Config, s *state) {
}
func nomarkLine(cfg *config.Config, s *state) {
+ if s.block != blockRaw && s.block != blockCode && s.block != blockMath {
+ line := string(s.data[s.index:s.lineEnd])
+ if strings.HasPrefix(line, " ") {
+ blockEnd(s, blockRaw)
+ blockBegin(s, blockRaw)
+ s.text.WriteString(line)
+ s.html.WriteString(template.HTMLEscapeString(line))
+ nextLine(s)
+ return
+ }
+ }
+
if s.block == blockRaw {
+ line := string(s.data[s.index:s.lineEnd])
+ if strings.HasPrefix(line, " ") {
+ s.text.WriteString("\n" + line)
+ s.html.WriteString("\n" + template.HTMLEscapeString(line))
+ nextLine(s)
+ return
+ }
+ }
+
+ if s.block == blockCode {
line := string(s.data[s.index:s.lineEnd])
if s.firstRaw {
s.text.WriteString(line)
@@ -599,8 +647,15 @@ func nomarkLine(cfg *config.Config, s *state) {
nextLine(s)
return
}
+ if line == "}}}" {
+ s.text.WriteString("}}}")
+ s.html.WriteString("}}}")
+ nextLine(s)
+ return
+ }
}
+ prevBlock := s.block
checkBlock(s, blockParagraph)
markup(cfg, s)
nextLine(s)
@@ -609,27 +664,29 @@ func nomarkLine(cfg *config.Config, s *state) {
line := s.data[s.index:s.lineEnd]
if !isBlank(line) && string(line) != "%%%" {
s.text.WriteString("\n")
- s.html.WriteString("
\n")
+ if prevBlock != blockRaw {
+ s.html.WriteString("
\n")
+ }
}
}
}
func nomark(cfg *config.Config, title string, text string) (string, string, string, string) {
d := []byte(text)
- s := state {
- data: d,
- index: 0,
- text: new(bytes.Buffer),
- plain: new(bytes.Buffer),
- html: new(bytes.Buffer),
- block: blockNone,
- nextLine: 0,
- lineEnd: 0,
+ s := state{
+ data: d,
+ index: 0,
+ text: new(bytes.Buffer),
+ plain: new(bytes.Buffer),
+ html: new(bytes.Buffer),
+ block: blockNone,
+ nextLine: 0,
+ lineEnd: 0,
outerDeco: decoNone,
innerDeco: decoNone,
- prevLine: d[0:0],
- firstRaw: false,
- title: "",
+ prevLine: d[0:0],
+ firstRaw: false,
+ title: "",
}
skip(&s)
@@ -638,11 +695,11 @@ func nomark(cfg *config.Config, title string, text string) (string, string, stri
for s.index < len(s.data) {
s.prevLine = line
line = s.data[s.index:s.lineEnd]
- if s.block != blockRaw && s.block != blockMath && isBlank(line) {
+ if s.block != blockRaw && s.block != blockCode && s.block != blockMath && isBlank(line) {
if string(s.prevLine) == "{{{" {
- blockEnd(&s, blockRaw)
+ blockEnd(&s, blockCode)
nextLine(&s)
- blockBegin(&s, blockRaw)
+ blockBegin(&s, blockCode)
s.firstRaw = true
continue
}
@@ -658,13 +715,11 @@ func nomark(cfg *config.Config, title string, text string) (string, string, stri
break
}
}
- } else if s.block == blockRaw && string(s.prevLine) == "" && string(line) == "}}}" {
+ } else if s.block == blockCode && string(s.prevLine) == "" && string(line) == "}}}" {
blockEnd(&s, blockParagraph)
- nextLine(&s)
- blockBegin(&s, blockParagraph)
- s.text.WriteString("}}}")
- s.html.WriteString("}}}")
- } else if s.block != blockMath && s.block != blockRaw && string(line) == "%%%" {
+ checkBlock(&s, blockParagraph)
+ nomarkLine(cfg, &s)
+ } else if s.block != blockMath && s.block != blockRaw && s.block != blockCode && string(line) == "%%%" {
blockEnd(&s, blockMath)
nextLine(&s)
blockBegin(&s, blockMath)
@@ -683,7 +738,7 @@ func nomark(cfg *config.Config, title string, text string) (string, string, stri
levelStr := strconv.Itoa(level)
var buf bytes.Buffer
buf.Write([]byte("!!!"))
- for i := 0; i <= 3 - level; i += 1 {
+ for i := 0; i <= 3-level; i += 1 {
buf.WriteByte('!')
}
mark := buf.String()