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

Extend dl with div wrapped groups #89

Merged
merged 7 commits into from
Apr 7, 2023
Merged

Extend dl with div wrapped groups #89

merged 7 commits into from
Apr 7, 2023

Conversation

nkalvi
Copy link
Contributor

@nkalvi nkalvi commented Feb 24, 2023

According to the HTML spec: // https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element

The <div> element wraps a group, that is part of a term-description group in a description list (<dl> element).

The proposed solution (using dlDiv instead of div) is a workaround for the current requirement for ElementDefinition.

…oposed solution is a workaround the current requirement for ElementDefinition.
Copy link
Owner

@JohnSundell JohnSundell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @nkalvi, and sorry for taking so long to review your PR. Left a few comments inline.

/// This is allowed according to the HTML spec: // https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
///
/// - parameter nodes: The element's attributes and child elements (`<dl>` or `<dd>` elements).
static func dlDiv(_ nodes: Node<HTML.DescriptionListContext>...) -> Node {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why we can't use div here? You mentioned that it being a requirement of ElementDefinition, but I don't really understand why that has something to do with this extension? Mind clarifying?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing this - I cannot remember what error I was getting related to ElementDefinition while working on this. I will get back to this if I see or remember the situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wait on this pull request. This is what I get when I changed from dlDiv to div:

Type 'ElementDefinitions.Div' does not conform to protocol 'ElementDefinition'

I will see what can be done without adding a new method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi John, I'm not sure how to accomplish this without a defining a new function for the context.

What I cannot understand is, if I add Plot as a dependency and the following in my app, it works as expected;

public extension Node where Context == HTML.DescriptionListContext {

    // The `<div>` element wraps a group, that is part of a term-description group in a description list (`<dl>` element).
    //
    // This is allowed according to the HTML spec: // https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
    
    /// - parameter nodes: The element's attributes and child elements (`<dl>` or `<dd>` elements).
    static func div(_ nodes: Node<HTML.DescriptionListContext>...) -> Node {
        .element(named: "div", nodes: nodes)
    }
}

but when I try to add this to Plot, it fails because, Node.div becomes ambiguous in

public enum Div: ElementDefinition { public static var wrapper = Node.div }

Since adding it inside the app works for my purposes (I would love to know why though), I can scrap this pull request.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @nkalvi! Let me look into this a bit later in the week, and I'll let you know what I'll find 👍

public extension Node where Context == HTML.DescriptionListContext {
/// The `<div>` element wraps a group, that is part of a term-description group in a description list (`<dl>` element).
///
/// This is allowed according to the HTML spec: // https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great sentence to add to the commit message, but I don't think it needs to be a part of the public documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I have changed it.

@JohnSundell JohnSundell added the awaiting update Waiting for an update from the PR's author. label Mar 31, 2023
nkalvi added 4 commits March 31, 2023 10:59
The `<div>` element wraps a group, that is part of a term-description group in a description list (`<dl>` element).

This is allowed according to the HTML spec: https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
Add tests for `div` inside description lists.
@JohnSundell JohnSundell added needs investigation Some issue requires a bit of investigation to resolve and removed awaiting update Waiting for an update from the PR's author. labels Apr 3, 2023
Base the `Node.div` API on a new `HTMLDividableContext` protocol,
which enables that API to be shared between `HTML.BodyContext`
and `HTML.DescriptionListContext`. While this does come with a minor
downside of now requiring an explicit context whenever a `div` node
is created as a stand-alone value (when using `Node.div` directly, without
defining any child nodes within it), in practice that should be very rare, as
`div` nodes are most likely placed within a known context (such as within
a `body` node, or another node that inherits `HTML.BodyContext` from its
parent).
Copy link
Owner

@JohnSundell JohnSundell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out what was wrong, @nkalvi. The problem was that, by adding another div overload, the Node.div reference used within the Div element definition became ambiguous, which in turn made the compiler not consider that class to conform to the ElementDefinition protocol. I solved that problem by extracting the div API to a protocol, which is conformed to by both HTML.BodyContext and HTML.DescriptionListContext. Updated your PR with a commit containing those changes, so this PR is now ready to be merged! Thanks a lot for contributing 👍

@JohnSundell JohnSundell removed the needs investigation Some issue requires a bit of investigation to resolve label Apr 7, 2023
@JohnSundell JohnSundell merged commit 4237057 into JohnSundell:master Apr 7, 2023
@nkalvi
Copy link
Contributor Author

nkalvi commented Apr 7, 2023

Very nice John! Thank you.

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.

2 participants