uniorg icon indicating copy to clipboard operation
uniorg copied to clipboard

Providing #+NAME and #+CAPTION for images

Open ispringle opened this issue 2 years ago • 3 comments

Orgmode has a few keywords you can specify for an image and they are #+NAME, #+CAPTION, and #+ATTR_. Using Uniorg the attr values come through when I specify ATTR_HTML (I believe this is the correct behavior). But I am not sure how to access the name or caption. For reference, I'm using AstroJS and I am overwriting img tags in my Content by specifying a replacement in the components lookup attribute.

When an image is processed the props provided include anything set in the ATTR_HTML and then the src data, so filepath, format, and dimensions. I see that the parser captures these but I'm not sure if I'm doing something wrong or if they're not being passed through for further processing. https://github.com/rasendubi/uniorg/blob/cb0709da1478d92b26391e288d1133cf959e2ff7/packages/uniorg-parse/src/parser.ts#L2162C2-L2162C2

ispringle avatar Aug 24 '23 17:08 ispringle

As best as I can tell, the parser is grabbing this data and putting it into the affiliated object. But then org-rehype ignores this data, extracting the attrs but not the other possible values in there such as NAME and CAPTION:

https://github.com/rasendubi/uniorg/blob/cb0709da1478d92b26391e288d1133cf959e2ff7/packages/uniorg-rehype/src/org-to-hast.ts#L442

ispringle avatar Aug 24 '23 19:08 ispringle

Hey, you're correct that #+NAME: and #+CAPTION: are ignored by uniorg-rehype.

I think the good behavior is to transform

#+CAPTION: hello
[[image.png]]

into:

<figure>
  <img src="image.png" />
  <figcaption>hello</figcaption>
</figure>

I think that should be a straightforward fix somewhere around here: https://github.com/rasendubi/uniorg/blob/cb0709da1478d92b26391e288d1133cf959e2ff7/packages/uniorg-rehype/src/org-to-hast.ts#L444-L446

#+NAME: is not exported in org-export but can be referenced with Internal Links (currently not supported #77).

rasendubi avatar Aug 26 '23 09:08 rasendubi

Yes, I was thinking it would be best to just pass this data without changing how it renders, since org-export never reaches for the CAPTION or NAME, as you suggest. Instead it makes sense to me at least that uniorg would just ensure this data is passed on so that it can be used for further use if desired.

ispringle avatar Aug 30 '23 14:08 ispringle