Skip to content

Commit

Permalink
feat(parser): support cross references to images with ID and title (#…
Browse files Browse the repository at this point in the history
…1047)

Fixes #1046

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Jun 18, 2022
1 parent 0e73153 commit db62762
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/parser/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ image::cookie.png[cookie image, 600, 400]`
},
},
},
ElementReferences: types.ElementReferences{
"myid": "mytitle",
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
Expand Down
19 changes: 19 additions & 0 deletions pkg/renderer/sgml/html5/cross_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ with some content linked to <<thewrongtitle>>!`
<div class="sectionbody">
</div>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("to image with title", func() {
source := `see <<thecookie>>
[#thecookie]
.A cookie
image::cookie.jpg[]`
expected := `<div class="paragraph">
<p>see <a href="#thecookie">A cookie</a></p>
</div>
<div id="thecookie" class="imageblock">
<div class="content">
<img src="cookie.jpg" alt="cookie">
</div>
<div class="title">Figure 1. A cookie</div>
</div>
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
})
Expand Down
10 changes: 10 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,16 @@ func (i *ImageBlock) GetLocation() *Location {
return i.Location
}

var _ Referencable = &ImageBlock{}

func (i *ImageBlock) Reference(refs ElementReferences) {
id := i.Attributes.GetAsStringWithDefault(AttrID, "")
title := i.Attributes.GetAsStringWithDefault(AttrTitle, "")
if id != "" && title != "" {
refs[id] = title
}
}

// InlineImage the structure for the inline image macros
type InlineImage struct {
Location *Location
Expand Down

0 comments on commit db62762

Please sign in to comment.