Skip to content

Consider splitting facet-format-html-dom from facet-format-html #1529

@fasterthanlime

Description

@fasterthanlime

Context

In PR #1528, we fixed the <meta charset="utf-8"> parsing issue by adding #[facet(xml::elements)] to the Head struct's Vec fields. However, ideally we'd use #[facet(html::elements)] for consistency.

Problem

Due to Rust limitation rust-lang/rust#52234, macro-expanded macro_export macros from the current crate cannot be referred to by absolute paths. This means facet-format-html cannot use #[facet(html::elements)] in its own elements.rs module - it has to use #[facet(xml::elements)] instead.

This works because is_elements() in facet-core checks both xml::elements and html::elements, but it's not ideal from a consistency/documentation perspective.

Proposed Solution

Split into two crates:

  • facet-format-html: Parser, serializer, and the html:: attribute grammar (html::elements, html::text, etc.)
  • facet-format-html-dom: The DOM types (Html, Head, Body, Meta, Div, etc.) that can properly use #[facet(html::elements)]

This follows the same pattern that allows facet-format-xml/tests/ to use #[facet(xml::elements)] - test files compile as separate crates.

Benefits

  1. DOM types can use the canonical html::elements attribute
  2. Cleaner separation of concerns (format implementation vs. DOM model)
  3. Users who only need the parser/serializer don't need to compile all DOM types
  4. Consistent with how users would define their own HTML types

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✨ enhancementNew feature or request🔗 urlencodedfacet-urlencoded crate, URL-encoded form data

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions