add ReferenceImage to the IR and use it for ![alt][ref]
The reference form of the image syntax had nowhere to go: Image only has a url, so the parser was putting the label there and `![a][b]` came out identical to ``, with nothing downstream aware the url still needed resolving against a RefDef. Adds a ReferenceImage constructor mirroring ReferenceLink and has the djot parser emit it. As with reference links, an empty label falls back to the alt text. Note HTML.hs still renders neither reference form. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
d695910c7c
commit
7a0032c7d3
2 changed files with 10 additions and 2 deletions
|
|
@ -893,9 +893,8 @@ image = do
|
|||
url <- inlineDestination
|
||||
pure $ Image {altText, url, title = Nothing, misc_attrs = mempty},
|
||||
do
|
||||
-- the IR has no reference image, so the label stands in for the url
|
||||
label <- referenceLabel
|
||||
pure $ Image {altText, url = if T.null label then altText else label, title = Nothing, misc_attrs = mempty}
|
||||
pure $ ReferenceImage {altText, label = if T.null label then altText else label, attrs = mempty}
|
||||
]
|
||||
|
||||
-- | @(url)@, with line endings inside the url removed as djot specifies.
|
||||
|
|
@ -1000,6 +999,7 @@ plainOf = T.concat . map go
|
|||
go (Link {linkText}) = plainOf linkText
|
||||
go (ReferenceLink {linkText}) = plainOf linkText
|
||||
go (Image {altText}) = altText
|
||||
go (ReferenceImage {altText}) = altText
|
||||
go (HTMLInline {inline_html_content}) = inline_html_content
|
||||
go (Superscript content _) = plainOf content
|
||||
go (Subscript content _) = plainOf content
|
||||
|
|
@ -1034,6 +1034,7 @@ applyAttrs element extra = case element of
|
|||
Link {linkText, url, title, misc_attrs} -> Link {linkText, url, title, misc_attrs = misc_attrs <> extra}
|
||||
ReferenceLink {linkText, label, attrs} -> ReferenceLink {linkText, label, attrs = attrs <> extra}
|
||||
Image {altText, url, title, misc_attrs} -> Image {altText, url, title, misc_attrs = misc_attrs <> extra}
|
||||
ReferenceImage {altText, label, attrs} -> ReferenceImage {altText, label, attrs = attrs <> extra}
|
||||
FootnoteReference {label, attrs} -> FootnoteReference {label, attrs = attrs <> extra}
|
||||
-- anything else (plain text in particular) becomes a span carrying the attrs
|
||||
other -> Span [other] extra
|
||||
|
|
|
|||
|
|
@ -90,6 +90,13 @@ data InlineText
|
|||
title :: Maybe Text,
|
||||
misc_attrs :: Attrs
|
||||
}
|
||||
| -- the image equivalent of ReferenceLink, url comes from a RefDef with a
|
||||
-- matching label
|
||||
ReferenceImage
|
||||
{ altText :: Text,
|
||||
label :: Text,
|
||||
attrs :: Attrs
|
||||
}
|
||||
| -- Markdown only DJOT uses RawInline
|
||||
HTMLInline {inline_html_content :: Text}
|
||||
| Superscript [InlineText] Attrs
|
||||
|
|
|
|||
Loading…
Reference in a new issue