web frontend for git repositories, written in Go git.pocka.jp/legit.git
3

Configure Feed

Select the types of activity you want to include in your feed.

Display checked-in image in Markdown preview

Co-authored-by: Anthony Wang <a@unnamed.website>

Shota FUJI (Jul 11, 2026, 9:23 PM +0900) 09c5f871 74ed6804

+45 -22
+37 -1
routes/preview/renderer.go
··· 6 6 package preview 7 7 8 8 import ( 9 + "bytes" 10 + "net/url" 9 11 "path/filepath" 10 12 11 13 "github.com/microcosm-cc/bluemonday" ··· 26 28 27 29 func (r MarkdownToHtmlRenderer) Render(code []byte) ([]byte, error) { 28 30 sanitizer := bluemonday.UGCPolicy() 29 - unsafe := blackfriday.Run(code, blackfriday.WithExtensions(blackfriday.CommonExtensions)) 31 + parser := blackfriday.New(blackfriday.WithExtensions(blackfriday.CommonExtensions)) 32 + 33 + tree := parser.Parse(code) 34 + tree.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { 35 + if !entering { 36 + return blackfriday.GoToNext 37 + } 38 + 39 + if node.Type == blackfriday.Image { 40 + src := string(node.LinkData.Destination) 41 + parsedURL, err := url.Parse(src) 42 + if err == nil && parsedURL.Host != "" { 43 + // External URL, skip. 44 + return blackfriday.GoToNext 45 + } 46 + 47 + queries := parsedURL.Query() 48 + queries.Add("raw", "1") 49 + parsedURL.RawQuery = queries.Encode() 50 + 51 + node.LinkData.Destination = []byte(parsedURL.String()) 52 + } 53 + 54 + return blackfriday.GoToNext 55 + }) 56 + 57 + var writer bytes.Buffer 58 + renderer := blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{}) 59 + renderer.RenderHeader(&writer, tree) 60 + tree.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { 61 + return renderer.RenderNode(&writer, node, entering) 62 + }) 63 + renderer.RenderFooter(&writer, tree) 64 + 65 + unsafe := blackfriday.Run(writer.Bytes(), blackfriday.WithExtensions(blackfriday.CommonExtensions)) 30 66 return sanitizer.SanitizeBytes(unsafe), nil 31 67 } 32 68
+4 -2
routes/routes.go
··· 142 142 return blackfriday.GoToNext 143 143 } 144 144 145 - if node.Type == blackfriday.Link { 145 + if node.Type == blackfriday.Link || node.Type == blackfriday.Image { 146 146 href := string(node.LinkData.Destination) 147 147 parsedURL, err := url.Parse(href) 148 148 if err == nil && parsedURL.Host != "" { ··· 155 155 href = "." + href 156 156 } 157 157 158 - if strings.LastIndexByte(href, '/') == len(href)-1 { 158 + if node.Type == blackfriday.Image { 159 + node.LinkData.Destination = fmt.Appendf([]byte{}, "/%s/blob/%s/%s?raw=true", name, mainBranch, href) 160 + } else if strings.LastIndexByte(href, '/') == len(href)-1 { 159 161 node.LinkData.Destination = fmt.Appendf([]byte{}, "/%s/tree/%s/%s", name, mainBranch, href) 160 162 node.LinkData.Destination = node.LinkData.Destination[:len(node.LinkData.Destination)-1] 161 163 } else {
+4 -19
static/html-content.css
··· 125 125 color: inherit; 126 126 } 127 127 128 - .html-content img[src^="./"] { 129 - display: inline-flex; 130 - flex-direction: column; 131 - padding: var(--space-lg) var(--space-xl); 132 - font-size: var(--font-sm); 133 - border: 1px solid var(--color-border-subtle); 134 - line-height: 1.2; 135 - gap: var(--space-xs); 136 - 137 - border-radius: var(--radii-md); 138 - box-shadow: 1px 1px 4px var(--color-shadow); 139 - } 140 - .html-content img[src^="./"]::after { 141 - display: block; 142 - content: "Rendering of local image is not supported."; 143 - font-size: var(--font-xs); 144 - font-style: italic; 145 - 146 - color: var(--color-fg-weak); 128 + .html-content img, 129 + .html-content picture, 130 + .html-content video { 131 + max-width: 100%; 147 132 }