From b45d847e7aa69dd8ef980a25f02f0c74ded60d1e Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Sat, 18 Jun 2022 15:14:01 +0200 Subject: [PATCH] feat(parser): support cross references to images with ID and title Fixes #1046 Signed-off-by: Xavier Coulon --- pkg/parser/image_test.go | 3 +++ .../sgml/html5/cross_reference_test.go | 19 +++++++++++++++++++ pkg/types/types.go | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/pkg/parser/image_test.go b/pkg/parser/image_test.go index abc5930d..9b684666 100644 --- a/pkg/parser/image_test.go +++ b/pkg/parser/image_test.go @@ -196,6 +196,9 @@ image::cookie.png[cookie image, 600, 400]` }, }, }, + ElementReferences: types.ElementReferences{ + "myid": "mytitle", + }, } Expect(ParseDocument(source)).To(MatchDocument(expected)) }) diff --git a/pkg/renderer/sgml/html5/cross_reference_test.go b/pkg/renderer/sgml/html5/cross_reference_test.go index 3d93ed70..b87821db 100644 --- a/pkg/renderer/sgml/html5/cross_reference_test.go +++ b/pkg/renderer/sgml/html5/cross_reference_test.go @@ -167,6 +167,25 @@ with some content linked to <>!`
+` + Expect(RenderHTML(source)).To(MatchHTML(expected)) + }) + + It("to image with title", func() { + source := `see <> + +[#thecookie] +.A cookie +image::cookie.jpg[]` + expected := `
+

see A cookie

+
+
+
+cookie +
+
Figure 1. A cookie
+
` Expect(RenderHTML(source)).To(MatchHTML(expected)) }) diff --git a/pkg/types/types.go b/pkg/types/types.go index fd09164e..82df71e9 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -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