From d8b7c5fad16486b12a0ab995526f60c35ae7cb48 Mon Sep 17 00:00:00 2001 From: Ben Younes Date: Wed, 13 May 2026 22:36:17 +0200 Subject: [PATCH] feat(cli): add --dump markdown output mode (#54) (#78) Surfaces the existing LP.getMarkdown CDP machinery as a CLI flag so text-pipeline users (LLM agents, scrapers feeding markdown to other tools) don't need a separate HTML-to-markdown converter step. obscura fetch --dump markdown 'https://example.com' Layout: - crates/obscura-js/src/markdown.rs holds HTML_TO_MARKDOWN_JS as a pub const so every layer can share the same DOM-walker. obscura-js is at the bottom of the dep DAG (obscura-browser -> obscura-js, obscura-cdp -> obscura-js, obscura-cli -> obscura-js) so a single source of truth works without a circular dependency. - crates/obscura-browser/src/lib.rs re-exports it for ergonomics. - crates/obscura-cdp/src/domains/lp.rs drops its inline duplicate and calls the shared const. - crates/obscura-cli/src/main.rs adds the `Markdown` DumpFormat variant + dump_markdown(&mut Page) which page.evaluate's the shared script and prints the result. Net diff: a new 75-line markdown.rs, a 70+ line deletion in lp.rs that's reborn as 3 lines, and ~10 lines added across the other four files. No behavior change for `--dump html|text|links`, and LP.getMarkdown over CDP keeps the exact same JSON shape. Four new unit tests in obscura-js cover headings, inline emphasis + links, ordered/unordered lists, and that ", + ); + let md = rt + .evaluate(crate::HTML_TO_MARKDOWN_JS) + .unwrap() + .as_str() + .unwrap() + .to_string(); + assert!(md.contains("Text"), "missing visible text: {}", md); + assert!(!md.contains("alert"), "leaked script content: {}", md); + assert!(!md.contains("color:red"), "leaked style content: {}", md); + } + #[test] fn test_page_content_puppeteer_pattern() { let mut rt = setup_runtime("

Test

");