MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / BuildExcerpt

Function BuildExcerpt

apps/server/internal/vault/parse.go:166–212  ·  view source on GitHub ↗

BuildExcerpt makes a short plaintext preview from markdown.

(body string)

Source from the content-addressed store, hash-verified

164
165// BuildExcerpt makes a short plaintext preview from markdown.
166func BuildExcerpt(body string) string {
167 withoutFront := body
168 if strings.HasPrefix(body, "---\n") {
169 withoutFront = frontmatterRe.ReplaceAllString(body, "")
170 }
171 text := stripCodeContent(withoutFront)
172 if strings.Contains(text, "](") {
173 text = imageMdRe.ReplaceAllString(text, " ")
174 text = mdLinkRe.ReplaceAllString(text, "$1")
175 }
176 if strings.Contains(text, "![[") {
177 text = mdEmbedAltRe.ReplaceAllStringFunc(text, func(s string) string {
178 m := mdEmbedAltRe.FindStringSubmatch(s)
179 if len(m) >= 3 && m[2] != "" {
180 return m[2]
181 }
182 if len(m) >= 2 {
183 return m[1]
184 }
185 return ""
186 })
187 }
188 if strings.Contains(text, "[[") {
189 text = mdWikiAltRe.ReplaceAllStringFunc(text, func(s string) string {
190 m := mdWikiAltRe.FindStringSubmatch(s)
191 if len(m) >= 3 && m[2] != "" {
192 return m[2]
193 }
194 if len(m) >= 2 {
195 return m[1]
196 }
197 return ""
198 })
199 }
200 if strings.Contains(text, "#") {
201 text = headingRe.ReplaceAllString(text, "")
202 }
203 if strings.ContainsAny(text, "*_~>") {
204 text = markupTrimRe.ReplaceAllString(text, "")
205 }
206 text = wsCollapseRe.ReplaceAllString(text, " ")
207 text = strings.TrimSpace(text)
208 if len(text) > 220 {
209 text = text[:220]
210 }
211 return text
212}
213
214func localAssetTargetKind(target string) string {
215 clean := target

Callers 1

buildNoteMetaFunction · 0.85

Calls 1

stripCodeContentFunction · 0.70

Tested by

no test coverage detected