MCPcopy Index your code
hub / github.com/writefreely/writefreely / applyBasicMarkdown

Function applyBasicMarkdown

postrender.go:184–216  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

182}
183
184func applyBasicMarkdown(data []byte) string {
185 if len(bytes.TrimSpace(data)) == 0 {
186 return ""
187 }
188
189 mdExtensions := 0 |
190 blackfriday.EXTENSION_STRIKETHROUGH |
191 blackfriday.EXTENSION_SPACE_HEADERS |
192 blackfriday.EXTENSION_HEADER_IDS
193 htmlFlags := 0 |
194 blackfriday.HTML_SKIP_HTML |
195 blackfriday.HTML_USE_SMARTYPANTS |
196 blackfriday.HTML_SMARTYPANTS_DASHES
197
198 // Generate Markdown
199 // This passes the supplied title into blackfriday.Markdown() as an H1 header, so we only render HTML that
200 // belongs in an H1.
201 md := blackfriday.Markdown(append([]byte("# "), data...), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions)
202 // Remove H1 markup
203 md = bytes.TrimSpace(md) // blackfriday.Markdown adds a newline at the end of the <h1>
204 if len(md) == 0 {
205 return ""
206 }
207 md = md[len("<h1>") : len(md)-len("</h1>")]
208 // Strip out bad HTML
209 policy := bluemonday.UGCPolicy()
210 policy.AllowAttrs("class", "id").Globally()
211 outHTML := string(policy.SanitizeBytes(md))
212 outHTML = markeddownReg.ReplaceAllString(outHTML, "$1")
213 outHTML = strings.TrimRightFunc(outHTML, unicode.IsSpace)
214
215 return outHTML
216}
217
218func postTitle(content, friendlyId string) string {
219 const maxTitleLen = 80

Callers 2

formatContentMethod · 0.85
TestApplyBasicMarkdownFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestApplyBasicMarkdownFunction · 0.68