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

Function applyMarkdownSpecial

postrender.go:145–182  ·  view source on GitHub ↗
(data []byte, baseURL string, cfg *config.Config, skipNoFollow bool)

Source from the content-addressed store, hash-verified

143}
144
145func applyMarkdownSpecial(data []byte, baseURL string, cfg *config.Config, skipNoFollow bool) string {
146 mdExtensions := 0 |
147 blackfriday.EXTENSION_TABLES |
148 blackfriday.EXTENSION_FENCED_CODE |
149 blackfriday.EXTENSION_AUTOLINK |
150 blackfriday.EXTENSION_STRIKETHROUGH |
151 blackfriday.EXTENSION_SPACE_HEADERS |
152 blackfriday.EXTENSION_AUTO_HEADER_IDS
153 htmlFlags := 0 |
154 blackfriday.HTML_USE_SMARTYPANTS |
155 blackfriday.HTML_SMARTYPANTS_DASHES
156
157 if baseURL != "" {
158 htmlFlags |= blackfriday.HTML_HASHTAGS
159 }
160
161 // Generate Markdown
162 md := blackfriday.Markdown([]byte(data), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions)
163 if baseURL != "" {
164 // Replace special text generated by Markdown parser
165 tagPrefix := baseURL + "tag:"
166 if cfg.App.Chorus {
167 tagPrefix = "/read/t/"
168 }
169 md = []byte(hashtagReg.ReplaceAll(md, []byte("<a href=\""+tagPrefix+"$1\" class=\"hashtag\"><span>#</span><span class=\"p-category\">$1</span></a>")))
170 handlePrefix := cfg.App.Host + "/@/"
171 md = []byte(mentionReg.ReplaceAll(md, []byte("<a href=\""+handlePrefix+"$1$2\" class=\"u-url mention\">@<span>$1$2</span></a>")))
172 }
173 // Strip out bad HTML
174 policy := getSanitizationPolicy()
175 policy.RequireNoFollowOnLinks(!skipNoFollow)
176 outHTML := string(policy.SanitizeBytes(md))
177 // Strip newlines on certain block elements that render with them
178 outHTML = blockReg.ReplaceAllString(outHTML, "<$1>")
179 outHTML = endBlockReg.ReplaceAllString(outHTML, "</$1></$2>")
180 outHTML = disableYoutubeAutoplay(outHTML)
181 return outHTML
182}
183
184func applyBasicMarkdown(data []byte) string {
185 if len(bytes.TrimSpace(data)) == 0 {

Callers 1

applyMarkdownFunction · 0.85

Calls 2

getSanitizationPolicyFunction · 0.85
disableYoutubeAutoplayFunction · 0.85

Tested by

no test coverage detected