Skip to content

Include media elements in content_html and markdown exports - #4

Open
gorango wants to merge 3 commits into
Murrough-Foley:mainfrom
gorango:main
Open

Include media elements in content_html and markdown exports#4
gorango wants to merge 3 commits into
Murrough-Foley:mainfrom
gorango:main

Conversation

@gorango

@gorango gorango commented May 11, 2026

Copy link
Copy Markdown

This PR adds the ability to include images, video, and audio elements in content_html and content_markdown exports.

  • Images (include_images): Preserves img, figure, figcaption, picture, and source tags in HTML/markdown output
  • Video (include_videos): Preserves video, source, and track elements
  • Audio (include_audio): Preserves audio and source elements
  • Also bumps Rust toolchain to 1.86 for ICU compatibility

Changes

src/options.rs

  • Add include_videos: bool and include_audio: bool fields (default: false)

src/result.rs

  • Add VideoData struct with src, filename, poster, caption, is_hero fields
  • Add AudioData struct with src, filename, caption fields

src/extract.rs

  • Extend push_filtered_html_children() to handle video/audio elements
  • Add extract_videos() and extract_audio() functions
  • Preserve <video> and <audio> tags in fallback extraction

src/html_processing.rs

  • Preserve video/audio/figure/source/track tags during cleaning when respective options are enabled

Testing

New tests in tests/video_audio_toggle_test.rs cover:

  • Toggle behavior for video/audio extraction
  • HTML/Markdown output verification
  • Figure-wrapped media handling
  • Multiple source elements
  • Track subtitles
  • Deduplication
  • Poster preservation
  • Fallback behavior

Image tests in tests/image_link_toggle_test.rs verify images appear in both content_html and content_markdown.


Closes #5

gorango added 3 commits May 7, 2026 11:48
Resolves build error where icu_collections@2.2.0, icu_locale_core@2.2.0,
icu_normalizer@2.2.0, icu_properties@2.2.0, icu_provider@2.2.0, and
idna_adapter@1.2.2 require rustc 1.86.
Add img, figure, figcaption, picture, and source tags to the HTML
extraction output in push_filtered_html_children(). Images were
previously extracted to result.images but stripped from content_html,
making them unavailable in inline HTML and markdown exports.

Also preserve original content_html during fallback extraction when it
contains <img> tags but the fallback result doesn't. The baseline
fallback creates text-only <p> elements that lose image tags.

Add tests verifying images appear in both content_html and
content_markdown when include_images is enabled.
Add include_videos and include_audio options to control extraction of
<video>, <audio>, <source>, and <track> elements. These were previously
stripped during document cleaning (video/audio/source/track are in
TAGS_TO_CLEAN) and not handled in push_filtered_html_children().

Changes mirror the image extraction pattern from commit 3b13f06:
- src/options.rs: Add include_videos and include_audio fields (default:
false)
- src/result.rs: Add VideoData and AudioData structs with src, filename,
poster/caption, and is_hero fields
- src/html_processing.rs: Preserve video/audio/figure/source/track tags
during cleaning when respective options are enabled
- src/extract.rs: Add video/audio/track handlers to
push_filtered_html_children(), add extract_videos() and extract_audio()
functions, extend fallback protection to preserve <video> and <audio>
- src/lib.rs: Re-export VideoData and AudioData
- tests/video_audio_toggle_test.rs: 22 tests covering toggle behavior,
HTML/Markdown output, figure-wrapped media, multiple sources, track
subtitles, deduplication, poster preservation, and fallback

Markdown output: quick_html2md strips unknown tags, so video/audio
appear as text-only in markdown but are fully preserved in content_html
and extracted to result.videos/result.audio with metadata.
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

Successfully merging this pull request may close these issues.

Include media elements (images, video, audio) in content_html and markdown exports

1 participant