Skip to content

Commit

Permalink
internal/frontend: handle emph and strong in rewriteLinks
Browse files Browse the repository at this point in the history
For golang/go#61399

Change-Id: Iaf9be9ccd4d9deef61750b50ce3ea7699cf3c16b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/548216
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
kokoro-CI: kokoro <[email protected]>
  • Loading branch information
matloob committed Dec 18, 2023
1 parent 56a70e8 commit 035a41c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/frontend/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@ func (g *linkRewriter) rewriteLinksInline(inlines []markdown.Inline) {
x.URL = d
}
case *markdown.Image:
g.rewriteLinksInline(x.Inner)
if d := translateLink(x.URL, g.info, true, g.readme); d != "" {
x.URL = d
}
case *markdown.Emph:
g.rewriteLinksInline(x.Inner)
case *markdown.Strong:
g.rewriteLinksInline(x.Inner)
}

}
}

Expand Down
10 changes: 10 additions & 0 deletions internal/frontend/readme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ func TestReadme(t *testing.T) {
{Level: 1, Text: "A link link", ID: "readme-a-link-link"},
},
},
{
name: "rewritten link in emph",
unit: unit,
readme: &internal.Readme{
Filepath: "README.md",
Contents: `**![alt](https://github.com/gobuffalo/buffalo/blob/master/logo.svg)**`,
},
wantHTML: `<p><strong><img src="https://github.com/gobuffalo/buffalo/raw/master/logo.svg" alt="alt"/></strong></p>`,
wantOutline: nil,
},
} {
t.Run(test.name, func(t *testing.T) {
processReadmes := map[string]func(ctx context.Context, u *internal.Unit) (frontendReadme *Readme, err error){
Expand Down

0 comments on commit 035a41c

Please sign in to comment.