-
Notifications
You must be signed in to change notification settings - Fork 232
Add \data to html extension #791
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, this should be useful for a lot of people. But before we can merge can you please implement the following changes:
- Instead of the
splitTokensmethod use the existingkeyvalOptionsmethod ininput/tex/ParseUtil.ts. - Postprocess keys and values:
Strip double quotes from values- Remove keys that contain characters not allowed in attribute names as specified in https://html.spec.whatwg.org/multipage/syntax.html#attributes-2. Your current regexp is too restrictive. E.g.,
data-{foo}-123456789-+^#$()&@%is a perfectly legal, albeit very ugly, attribute name. Also the current matching could have unintended effects, likefoo{}bar="baz"leading to the attributedata-bar="baz".
ts/input/tex/html/HtmlMethods.ts
Outdated
| HtmlMethods.Data = (parser: TexParser, name: string) => { | ||
| const dataset = parser.GetArgument(name); | ||
| const arg = GetArgumentMML(parser, name); | ||
| for (const [prop, val] of splitTokens(dataset)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use keyvalOptions method from ParseUtil.ts.
ts/input/tex/html/HtmlMethods.ts
Outdated
| * @param {string} str String to split. | ||
| */ | ||
| function splitTokens(str: string) { | ||
| const matches = Array.from(str.matchAll(/\b([A-Za-z0-9_-]+)=(['"])(.+?)\2/g)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too restrictive. See https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 for HTML attribute names.
I'm not sure that is necessary. Attribute values can include double-quotes, and when they are serialized, the double quote will be represented using |
We only need stripping of quotes, if we want to have the exact behaviour as suggested by the current @ysulyma is there a compelling reason for requiring quotes? |
|
@zorkow KaTeX does not require quotes. I found that objectionable since HTML and JSON both require quotes. In any case, the
Neither does my |
I understand your view, but you are not writing either HTML or JSON, but rather LaTeX, and the LaTeX standard is to handle key/value pairs as in |
|
@zorkow ok, I've made the requested changes. |
|
This looks better, but you should also disallow noncharacters as required by the spec. You might need to add the Also, I wonder if throwing a Finally, we follow the git-flow model for PRs, so this should be branched from the develop branch and targeted at develop as well, not at master. Only releases go to master. You may have to rebase your branch to develop and force push the result. |
|
I'm closing this PR in favor of your other one. We need to make a v3.2.2 release to fix a couple of issues with the v3.2.1 version, but will include your PR in the next feature release. |
This PR adds the
\datacommand to the HTML extension to allow addingdata-*attributes to MathJax content.I have opened a separate PR to document this command: mathjax/MathJax-docs#299