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

Providing #+NAME and #+CAPTION for images #87

Open
ispringle opened this issue Aug 24, 2023 · 3 comments
Open

Providing #+NAME and #+CAPTION for images #87

ispringle opened this issue Aug 24, 2023 · 3 comments

Comments

@ispringle
Copy link
Contributor

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
Copy link
Contributor Author

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:

const attrs = isFirstLink ? getAffiliatedAttrs(parent) : {};

@rasendubi
Copy link
Owner

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:

if (isImageLink(org, this.options)) {
return h(org, 'img', { ...attrs, src: link });
}

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

@ispringle
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants