Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ts/input/tex/autoload/AutoloadConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const AutoloadConfiguration = Configuration.create(
color: ['color', 'definecolor', 'textcolor', 'colorbox', 'fcolorbox'],
enclose: ['enclose'],
extpfeil: ['xtwoheadrightarrow', 'xtwoheadleftarrow', 'xmapsto', 'xlongequal', 'xtofrom', 'Newextarrow'],
html: ['href', 'class', 'style', 'cssId'],
html: ['data', 'href', 'class', 'style', 'cssId'],
mhchem: ['ce', 'pu'],
newcommand: ['newcommand', 'renewcommand', 'newenvironment', 'renewenvironment', 'def', 'let'],
unicode: ['unicode'],
Expand Down
1 change: 1 addition & 0 deletions ts/input/tex/html/HtmlConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import HtmlMethods from './HtmlMethods.js';


new CommandMap('html_macros', {
data: 'Data',
href: 'Href',
'class': 'Class',
style: 'Style',
Expand Down
27 changes: 27 additions & 0 deletions ts/input/tex/html/HtmlMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,39 @@
import TexParser from '../TexParser.js';
import {ParseMethod} from '../Types.js';
import NodeUtil from '../NodeUtil.js';
import ParseUtil from "../ParseUtil.js";
import {MmlNode} from '../../../core/MmlTree/MmlNode.js';


// Namespace
let HtmlMethods: Record<string, ParseMethod> = {};

/**
* Implements \data{dataset}{content}
* @param {TexParser} parser The calling parser.
* @param {string} name The macro name.
*/
HtmlMethods.Data = (parser: TexParser, name: string) => {
const dataset = parser.GetArgument(name);
const arg = GetArgumentMML(parser, name);
const data = ParseUtil.keyvalOptions(dataset);
for (const key in data) {
// remove illegal attribute names
if (!isLegalAttributeName(key)) {
continue;
}
NodeUtil.setAttribute(arg, `data-${key}`, data[key]);
}
parser.Push(arg);
};

/**
* Whether the string is a valid HTML attribute name according to {@link https://html.spec.whatwg.org/multipage/syntax.html#attributes-2}.
* @param {string} name String to validate.
*/
function isLegalAttributeName(name: string): boolean {
return Boolean(name.match(/^([^\x00-\x1f\x7f-\x9f "'>\/=]+)$/));
}

/**
* Implements \href{url}{math}
Expand Down
1 change: 1 addition & 0 deletions ts/input/tex/textmacros/TextMacrosMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ new CommandMap('text-macros', {
href: 'CheckAutoload',
style: 'CheckAutoload',
class: 'CheckAutoload',
data: 'CheckAutoload',
cssId: 'CheckAutoload',
unicode: 'CheckAutoload',

Expand Down