Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(renderer): image alt without separators #1025

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/renderer/sgml/html5/delimited_block_open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ image::another-image.png[]
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div id="another-id" class="imageblock">
<div class="content">
<img src="another-image.png" alt="another-image">
<img src="another-image.png" alt="another image">
</div>
<div class="title">Figure 2. Another title</div>
</div></div></td>
Expand Down
16 changes: 13 additions & 3 deletions pkg/renderer/sgml/html5/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ var _ = Describe("images", func() {

Context("block images", func() {

It("alone", func() {
It("alone with underscores in filename", func() {
source := "image::an_image_here.png[]"
expected := `<div class="imageblock">
<div class="content">
<img src="an_image_here.png" alt="an image here">
</div>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

source := "image::foo.png[]"
It("alone with dashes in filename", func() {
source := "image::an-image-here.png[]"
expected := `<div class="imageblock">
<div class="content">
<img src="foo.png" alt="foo">
<img src="an-image-here.png" alt="an image here">
</div>
</div>
`
Expand Down
4 changes: 2 additions & 2 deletions pkg/renderer/sgml/html5/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ image::another-image.png[]
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div class="imageblock">
<div class="content">
<img src="another-image.png" alt="another-image">
<img src="another-image.png" alt="another image">
</div>
</div></div></td>
</tr>
Expand Down Expand Up @@ -682,7 +682,7 @@ image::another-image.png[]
</div></div></td>
<td class="tableblock halign-center valign-top"><div class="content"><div id="another-id" class="imageblock">
<div class="content">
<img src="another-image.png" alt="another-image">
<img src="another-image.png" alt="another image">
</div>
<div class="title">Figure 2. Another title</div>
</div></div></td>
Expand Down
6 changes: 5 additions & 1 deletion pkg/renderer/sgml/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,9 @@ func (r *sgmlRenderer) renderImageAlt(attrs types.Attributes, path string) (stri
return "", errors.Wrap(err, "unable to render image")
}
// return base path without its extension
return strings.TrimSuffix(filepath.Base(u.Path), filepath.Ext(u.Path)), nil
result := strings.TrimSuffix(filepath.Base(u.Path), filepath.Ext(u.Path))
// replace separators
result = strings.ReplaceAll(result, "-", " ")
result = strings.ReplaceAll(result, "_", " ")
return result, nil
}