@@ -3,6 +3,7 @@ package components
33import (
44 "fmt"
55 "regexp"
6+ "strings"
67)
78
89var rReg = regexp .MustCompile (`\r` )
@@ -101,6 +102,7 @@ func MDToHTML(content string) (string, bool) {
101102 icI := 0
102103 esI := 0
103104
105+ // escaped characters
104106 for syntax := range mdSyntax {
105107 reg := regexp .MustCompile (`\\` + syntax )
106108 for reg .MatchString (content ) {
@@ -110,11 +112,33 @@ func MDToHTML(content string) (string, bool) {
110112 esI ++
111113 }
112114 }
115+
116+ skipIC := 0
113117
114118 // inline code index
115- for mdSpreadInline .Reg .MatchString (content ) {
116- curLoc := mdSpreadInline .Reg .FindStringIndex (content )
117- inlineCodeMap [icI ] = content [curLoc [0 ]:curLoc [1 ]]
119+ for skipIC != len (mdSpreadInline .Reg .FindAllStringIndex (content , skipIC + 1 )) {
120+ curLocs := mdSpreadInline .Reg .FindAllStringIndex (content , skipIC + 1 )
121+ curLoc := curLocs [skipIC ]
122+
123+ testContent := content [curLoc [0 ]:curLoc [1 ]]
124+ codeBlock := false
125+
126+ if len (testContent ) >= 7 {
127+ codeBlock = testContent [:3 ] == "```" && testContent [len (testContent )- 3 :] == "```"
128+ }
129+
130+ // don't parse multi-line `inline code`
131+ if len (testContent ) >= 3 && ! codeBlock {
132+ if testContent [:1 ] == "`" && testContent [len (testContent )- 1 :] == "`" {
133+ if len (strings .Split (testContent , "<br />" )) != 1 {
134+ skipIC ++
135+ continue
136+ }
137+ }
138+ }
139+
140+ inlineCodeMap [icI ] = testContent
141+
118142 content = fmt .Sprintf ("%v--\t ic%v--%v" , content [:curLoc [0 ]], icI , content [curLoc [1 ]:])
119143 icI ++
120144 }
@@ -134,7 +158,45 @@ func MDToHTML(content string) (string, bool) {
134158
135159 for i , str := range inlineCodeMap {
136160 reg := regexp .MustCompile (fmt .Sprintf (`--\tic%v--` , i ))
137- content = reg .ReplaceAllString (content , str )
161+ prefix := ""
162+ suffix := ""
163+
164+ for {
165+ changed := false
166+ if len (str ) >= 7 {
167+ if str [:3 ] == "```" && str [len (str )- 3 :] == "```" {
168+ str = str [3 : len (str )- 3 ]
169+ prefix += `<span class="code-block-wrapper"><span class="code-block">`
170+ suffix = "</span></span>" + suffix
171+ spl := strings .SplitN (str , "<br />" , 2 )
172+
173+ if len (spl ) == 2 {
174+ str = spl [1 ]
175+ }
176+
177+ changed = true
178+ }
179+ }
180+ if len (str ) >= 3 {
181+ if str [:1 ] == "`" && str [len (str )- 1 :] == "`" {
182+ str = str [1 : len (str )- 1 ]
183+ prefix += `<span class="inline-code">`
184+ suffix = "</span>" + suffix
185+ changed = true
186+ }
187+ }
188+ if ! changed {
189+ break
190+ }
191+ }
192+
193+ if len (str ) >= 6 {
194+ if str [len (str )- 6 :] == "<br />" {
195+ str = str [:len (str )- 6 ]
196+ }
197+ }
198+
199+ content = reg .ReplaceAllString (content , prefix + str + suffix )
138200 }
139201
140202 for i , str := range escapedSyntaxMap {
0 commit comments