Skip to content

Interoperable handling of invalid markup  #136

Closed

Description

@fred-wang

https://mathml-refresh.github.io/mathml/chapter2.html#interf.error

If a MathML-input-conformant application receives input containing one or more elements with an illegal number or type of attributes or child schemata, it should nonetheless attempt to render all the input in an intelligible way, i.e., to render normally those parts of the input that were valid, and to render error messages (rendered as if enclosed in an merror element) in place of invalid expressions.

Gecko renders (not very useful) "invalid-markup" message
WebKit just layout a 0x0 box for the invalid subtree

I think the latter is more efficient and less code so I'd prefer it. Probably if we want to log errors, it should be in the console instead.

Activity

  1. davidcarlisle commented on Feb 19, 2019

    @davidcarlisle
    Collaborator

    I certainly would not want error reporting to be placing any constraints on browsers here, so I'd agree to any wording here that tells authors not to produce bad markup, but basically authorises browsers to do whatever they find convenient if there is bad markup. If making a zero sized subtree works (could be made to work) for all the current implementations, specifying that to get interoperable behaviour would also be Ok I think.

  2. changed the title [-]Handling of invalid markup interoperability[/-] [+]Interoperable handling of invalid markup [/+] on Feb 19, 2019
  3. fred-wang commented on Feb 22, 2019

    @fred-wang
    ContributorAuthor

    Adding mathml4 label too, as we might want to adjust the behavior.

  4. fred-wang commented on Feb 25, 2019

    @fred-wang
    ContributorAuthor
  5. fred-wang commented on Feb 25, 2019

    @fred-wang
    ContributorAuthor

    Just for the record, there is a third option which is probably a bit more complicate to implement/describe but more aligned with to what people expect with CSS / HTML5: Add anonymous <mrow> elements (e.g. one for numerator and one for denominator for mfrac) to ensure that MathML elements have the right number of arguments.

  6. fred-wang commented on Feb 28, 2019

    @fred-wang
    ContributorAuthor

    Quoting @bfgeek

    See:
    https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=6704
    ... for a simple example.

    https://www.software.hixie.ch/utilities/js/live-dom-viewer/?saved=6705
    ... for a more complex example.

    The above example indicates that the implementations are trying to do something funny with various inputs which an implementation thinks is invalid.

    I suggest removing these, and instead making sure that all the MathML algorithms can deal with the edge cases which developers might feed them.

    (an alternative would be to strictly define, with algorithms, what type of DOM input is required, and the validation steps, however this would be prone to bugs, and compatibility issues).

    This the a bit of a meta issue, however would need lots of tests with the "edge" cases for all of the different layout algorithms within MathML.

  7. fred-wang commented on Feb 28, 2019

    @fred-wang
    ContributorAuthor

    I'm not sure there is a canonical way to "fix" invalid markup (Ignore extra children? Add empty anonymous? Wrap a subset of children into anonymous containers?). My preference would be to align on WebKit's behavior as it's the easiest to specify/test/implement. This is already how we (at Igalia) implement it our Chromium branch and we would only have to fix Firefox. Basically, my proposal would be:

    1. Add a section about invalid markup in MathML Core (maybe import from MathML 4 full), define the invalid constructions (essentially elements that don't have the expected number of children). There is probably an exception do make for mtable, until we clarify what the table layout is.
    2. Say that invalid markup has intrinsize size of 0, the layout results as an empty 0x0 box and no painting.
    3. In each section where we define algorithm and intrinsic size (Modify reference point for "shape a stretchy glyph" #54 etc), say that we do an early return with the result specified in (2)
    4. Write testharness tests with all markup of the form <span style="display: inline-block"><math>INVALID MARKUP</math></span> as defined in (1) and ensure that the span has size 0 (intrinsic size) and that the "INVALID MARKUP" subtree has size 0x0. Write reftests checking that they don't paint anything (e.g. for fractions, roots...). Probably more tests involving valid and invalid subtrees. I believe we already have tests for invalid markup in Gecko and WebKit that we could "import". However, they would need to be tweaked a bit probably.

    Putting this on the agenda of next meeting.

  8. bfgeek commented on Feb 28, 2019

    @bfgeek

    WebKits implementation causes issues in other areas of the browser. For example the "invalid" is still accessible from VoiceOver, etc.

    This type of "easy" fixup produces technical debt in the codebase, and complexity later on which I'd be strongly opposed to adding in chromium.

    Having said that one guiding principle that CSS usually follows is that it should attempt to display all content. This is probably a good principle for MathML to also follow.

    I think that for display types which can only accept up to "N" children, inserting any additional children in an anonymous mrow type would be acceptable.

    E.g.

    <mfrac><mi>a</mi><mi>b</mi><mi>c</mi></mfrac>

    would render as:

    <mfrac><mi>a</mi><mrow><mi>b</mi><mi>c</mi></mrow></mfrac>

    @emilio @heycam

  9. bfgeek commented on Feb 28, 2019

    @bfgeek

    @tabatkins also might have some good thoughts.

  10. fred-wang commented on Mar 1, 2019

    @fred-wang
    ContributorAuthor

    So the alternative proposal would be:

    1. Add a section about invalid markup in MathML Core defining the invalid constructions. Essentially elements they have n children while they expect N != n children. If n < N, they append N - n anonymous empty mrow's. If n > N, they wrap the last N - n + 1 children into an anonymous mrow. An alternative is to always generate N anonymous children but that would lead to bigger render/layout trees and complexity for such elements (even when they are valid) and so is less optimal. Again, there is an exception to make for mtable, were the fixup is instead using anonymous mtr and mtd like in HTML.
    2. In each section where we define elements, mention the expected number of children if appropriate (import from MathML 4 full) and link to the general section about how to fix it.
    3. Write static reftests checking that invalid markup render the same as their "fixed" version. Also write dynamic versions where n varies between 0 and (at least) N + 2.
    4. Implement the behavior for WebKit, Gecko and Chromium.

    My main concern (in addition to adding more work) is how dynamic changes will be handled. In the past, WebKit generated some anonymous elements (sometimes two levels of nested anonymous e.g. for scripted elements) in the Renderer/Layout classes and set/remove anonymous style on them: That caused at best inconsistencies after dynamic changes and at worst asserts/crashes. Hopefully, this proposal is a bit safer and we could maybe even handle the Render/Layout tree fixup & reorganization from the DOM classes.

    However, I agree that the proposed behavior would be more aligned with HTML5 / CSS (adding the label now btw) and more natural for users, so it's probably worth the added complexity/work.

    I don't really like the alternative of "making sure that all the MathML algorithms can deal with the edge cases" as that makes the algorithm more complex and harder to read. For example, the advantage of WebKit's current implementation is that once we know an element is valid we can just call the children and associated variable numerator/denominator/base/superscript etc and that makes the algorithm (which is already relatively complex when we follow all TeX / Open Type MATH metrics) much easier to read and understand.

  11. fred-wang commented on Mar 1, 2019

    @fred-wang
    ContributorAuthor

    An alternative is to always generate N anonymous children but that would lead to bigger render/layout trees and complexity for such elements (even when they are valid) and so is less optimal.

    Since VoiceOver was mentioned above, I however have to say that adding such anonymous children could help accessibility ( w3c/mathml#9 ). Typically,

    mfrac
      |_mfrac
      |_mfrac
    

    would become

    mfrac
      |_mrow
        |__frac
      |_mrow
        |__frac
    

    and then we can add roles numerator/denominator on the anonymous mrow's while still keeping roles fraction on the mfrac. Otherwise, this fixup would have to be done in the a11y tree.

  12. 25 remaining items

  13. NSoiffer commented on Aug 3, 2020

    @NSoiffer
    Contributor

    w3c/mathml#175 was resolved with 'render as an mrow'.

    I'm not sure what is left, but @bkardell pointed out this can't be closed until there is agreement from the other implementations that rendering as an mrow is ok with them -- they do something different now as pointed out in the initial comment.

  14. NSoiffer commented on Aug 17, 2020

    @NSoiffer
    Contributor

    @fred-wang: I don't think this can be closed unless you heard from other implementers as per @bkardell comment.

  15. fred-wang commented on Aug 21, 2020

    @fred-wang
    ContributorAuthor

    Checking the discussions, it seems Mozilla and Apple are happy with the "render as mrow" approach, but let's see what @bkardell says.

  16. NSoiffer commented on Aug 21, 2020

    @NSoiffer
    Contributor

    For my benefit and the benefit of others that are interested in what was said by Mozilla and Apple, can you provide a link to the discussions?

  17. fred-wang commented on Aug 22, 2020

    @fred-wang
    ContributorAuthor

    For my benefit and the benefit of others that are interested in what was said by Mozilla and Apple, can you provide a link to the discussions?

    This was discussed in an Apple/Igalia private chat, but Brian will be able to explain.

    About Mozilla, I don't have a link either but I'm pretty sure @emilio had mentioned several times in the past that having this error message layout was complicating things (I'll ping him again). I actually had written a WIP patch one year ago https://bugzilla.mozilla.org/show_bug.cgi?id=1583037

  18. transferred this issue fromw3c/mathmlon Mar 30, 2022
  19. fred-wang commented on Dec 8, 2022

    @fred-wang
    ContributorAuthor

    Closing this bug:

    There is also a WebKit bug to align with the spec: https://bugs.webkit.org/show_bug.cgi?id=123348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions