Skip to content

Issue #74 - add the fn:parse-html function - #259

Merged
rhdunn merged 35 commits into
qt4cg:masterfrom
rhdunn:parse-html
Jan 15, 2023
Merged

Issue #74 - add the fn:parse-html function#259
rhdunn merged 35 commits into
qt4cg:masterfrom
rhdunn:parse-html

Conversation

@rhdunn

@rhdunn rhdunn commented Nov 18, 2022

Copy link
Copy Markdown
Contributor

This PR makes the following changes:

  1. Add an .editorconfig file to allow editors and IDEs to indent the XML source documents consistently.
  2. Group the XML and JSON parsing and serialization functions into a common top-level section.
  3. Update the html5 bibref to the WHATWG specification -- the old HTML5 link redirects there.
  4. Add a new fn:parse-html function specification.
  5. Define a mapping between the HTML DOM and the XDM nodes.

The function specification itself is complete. The HTML DOM to XDM node mapping currently only contains the overview. I'm going to write that for this PR, this is just to start the ball rolling in specifying this function.

@liamquin

Copy link
Copy Markdown
Contributor

Possibly there should be an html-version option as per Serialization spec and XSLT. And possibly allow automatic detection of HTML 5 vs quirks mode vs XHTML with validation?? I like simple, but i am not confident hard-wiring HTML 5 (as opposed to XHTML 5 or XHTML 1.1) is necessarily the way to go. Of course, the HTML 5 spec says what to do with these too, but the proposed prose here seems explicit that only HTML 5 is accepted. Nonetheless i'm very pleased to see this.

@rhdunn

rhdunn commented Nov 19, 2022

Copy link
Copy Markdown
Contributor Author

@liamquin I've incorporated your suggestions into the spec. Thanks!

@michaelhkay

Copy link
Copy Markdown
Contributor

Could I ask what are the implications of

Add an .editorconfig file to allow editors and IDEs to indent the XML source documents consistently.

We've always had a problem with multiple (human) editors using multiple (software) editors causing whitespace changes that disrupt change marking and conflict resolution. I don't know what an .editorconfig file does: is it going to help with this problem or make it worse?

@rhdunn

rhdunn commented Nov 19, 2022

Copy link
Copy Markdown
Contributor Author

Could I ask what are the implications of

Add an .editorconfig file to allow editors and IDEs to indent the XML source documents consistently.

We've always had a problem with multiple (human) editors using multiple (software) editors causing whitespace changes that disrupt change marking and conflict resolution. I don't know what an .editorconfig file does: is it going to help with this problem or make it worse?

An editor config file allows you to specify the encoding, line ending, indentation style, etc. for files in the project. This allows you to have different rules for different language extensions, or even different files. The settings are documented in https://editorconfig.org/.

I added it because my IDE (IntelliJ IDEA) was defaulting to 4 characters indentation of the elements instead of the 3 that the files use. As such, I've added a rule in the editor config to make that consistent. I've not extended it to other settings such as encoding, line endings, or removing trailing spaces.

@rhdunn

rhdunn commented Nov 20, 2022

Copy link
Copy Markdown
Contributor Author

The XDM node mapping for the HTML DOM is now complete. I've incorporated @michaelhkay's notes from the issue, except for the point about if case normalization is needed.

@ndw

ndw commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

I think I'd have a marginal preference for putting method-specific additional parameters in their own key:

 parse-html($html, method:="tagsoup",  method_params:=map{'nons': true()})

instead of

 parse-html($html, method:="tagsoup", nons:=true())

Conflating the two together means you can't have a parameter with the same name as our options and means we can't safely add any new optionsin the future because someone might be using them as method parameter names.

@ndw

ndw commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

A higher-level comment is that, while I don't object to the options provided, I'd have been equally happy if the function said that the input string is parsed with the HTML5 parsing algorithm, full stop.

@ChristianGruen

Copy link
Copy Markdown
Contributor

I think I'd have a marginal preference for putting method-specific additional parameters in their own key:

Sounds reasonable to me, not just because TagSoup has a method option, too: https://www.mankier.com/1/tagsoup#--method

@michaelhkay

michaelhkay commented Dec 20, 2022 via email

Copy link
Copy Markdown
Contributor

@ndw

ndw commented Dec 21, 2022

Copy link
Copy Markdown
Contributor

I think the comment about dropping various 2.6.x things is related to the agendas. I've made those changes for the next agenda.

@michaelhkay

Copy link
Copy Markdown
Contributor

I think we need greater clarity as regards error handling. The proposed spec says:

A dynamic error is raised [[err:FODC0011] if the content of $html is not a well-formed HTML document.

But I'm not sure the concept of a "well-formed HTML document" is well defined.

Specifically, there seem to be differences between implementations of the HTML5 parsing algorithm (both in browsers, and in free-standing libraries) as to how much recovery is attempted. For example the proposed test case test-003 include the ill-formed SVG fragment:

<svg style="overflow: clip; width: 100px; height: 100px">
  <rect width="200" height="200" fill="green">
</svg>

(note the missing end tag for rect). Browsers and parsing libraries appear to differ on how they handle this (validator.nu reports an error, JSoup takes silent recovery action).

We could take several paths:

  • be prescriptive one way or the other
  • make it a user option
  • make it implementation-defined

I think this is probably a case for pragmatism; implementations are going to want to use existing parsing libraries, and if these differ in their behaviour, it's probably best to leave things implementation-defined.

There are no easy answers here; the HTML5 spec has a lot of fuzziness. For example, most of the requirements it places on "user agents" are not applicable because they only affect rendering and interaction, but the construction of a DOM from lexical HTML is also described as a function of a "user agent".

@rhdunn
rhdunn merged commit 36e4200 into qt4cg:master Jan 15, 2023
@rhdunn
rhdunn deleted the parse-html branch February 28, 2023 08:44
@michaelhkay michaelhkay added Tests Added Tests have been added to the test suites Completed PR has been applied, tests written and tagged, no further action needed labels Dec 11, 2024
@michaelhkay michaelhkay added In Saxon 12 The feature is substantially implemented in the latest Saxon 12.x maintenance release In Saxon 13 The feature is implemented in the Saxon 13 development branch labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Completed PR has been applied, tests written and tagged, no further action needed In Saxon 12 The feature is substantially implemented in the latest Saxon 12.x maintenance release In Saxon 13 The feature is implemented in the Saxon 13 development branch Tests Added Tests have been added to the test suites

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants