Skip to content

Promote img, video, audio, and picture elements to file attachments #54

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

Closed
mbostock opened this issue Oct 23, 2023 · 1 comment · Fixed by #250
Closed

Promote img, video, audio, and picture elements to file attachments #54

mbostock opened this issue Oct 23, 2023 · 1 comment · Fixed by #250
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@mbostock
Copy link
Member

mbostock commented Oct 23, 2023

We currently detect link elements with href attributes and promote them to file attachments, but we should do the same with other types of elements that commonly reference static files.

https://github.com/observablehq/cli/blob/0081db4f685ef635df42d0725ec2bbac5e87fa6c/src/markdown.ts#L64

@Fil
Copy link
Contributor

Fil commented Oct 26, 2023

Adding img[src] in normalizePieceHtml works well:

  for (const element of document.querySelectorAll("img[src]") as any as Iterable<Element>) {
    const src = element.getAttribute("src")!;
    if (/^(\w+:)\/\//.test(src)) continue; // absolute url
    if (canReadSync(join(root, src))) {
      context.files.push({name: src, mimeType: mime.getType(src)});
      element.setAttribute("src", `/_file/${src}`);
    }
  }

likewise a[href] is covered by extending the selector above to "link[href],a[href]".

Can we list what we'd want to support?

  • img[src]
  • img[srcset] and it peculiar syntax
  • picture source[srcset]
  • video[src]
  • audio[src]
  • audio source[src]
  • video source[src]
  • a[href] (for example, <a href=links.md>view source</a>)

(speaking of srcset, would we want to allow a function to generate reduced images for different srcset on build? would this be some sort of plugin which would hook into/before/after normalizePieceHtml?)

@cinxmo cinxmo self-assigned this Nov 1, 2023
@mbostock mbostock added this to the Early access milestone Nov 13, 2023
@Fil Fil closed this as completed in #250 Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants