Skip to content

Commit

Permalink
feat(sec.js): support style attribute
Browse files Browse the repository at this point in the history
Adds support for new style attribute on sectioning
elements, mapping to data-ams-style.
- readme/docs:
  - update attribute mappings
- sec.js
  - map style to data-ams-style (matching statement)
- test
  - add test case and test

Resolves #461
  • Loading branch information
pkra committed Sep 9, 2024
1 parent 4dbc680 commit 84c7699
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Beyond HTML element and attributes, texml-to-html stores data in custom `data-*`
- underline
- {disp-quote@specific-use}
- (inline-)graphic{@specific-use}
- {@style} [expected: theorem styles]
- {@style} [expected: theorem styles, sec styles]
- boxed (from boxed-text)
- data-ams-ref
- {@ref-type} [expected: bibr, fn, disp-formula, sec, fig, table, algorithm, list, statement]
Expand Down Expand Up @@ -250,7 +250,7 @@ The following provide a list from the reverse point of view.
- attributes
- @disp-level => data-ams-doc-level [data-ams-doc-level is also added to some elements that lack disp-level]
- @content-type => data-ams-content-type
- @style => data-ams-style
- @style => data-ams-style [e.g., statement, sec]
- @specific-use => data-ams-specific-use [sometimes mapped to other attributes, e.g., style]
- @has-qed-box => data-ams-qed-box
- @position => data-ams-position
Expand Down
2 changes: 2 additions & 0 deletions lib/elements/sec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default function (htmlParentNode, xmlnode) {
});
htmlParentNode.appendChild(section);

if (xmlnode.hasAttribute('style')) section.setAttribute('data-ams-style', xmlnode.getAttribute('style'));

if (specificUse === 'part') {
section.setAttribute('role', 'doc-part');
}
Expand Down
3 changes: 3 additions & 0 deletions test/book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<sec id="inpartlabel" disp-level="3" specific-use="section">
<label>Label</label>
</sec>
<sec id="xcb" disp-level="3" specific-use="section" style="xcb">
<label>Exercise</label>
</sec>
</sec>
</sec>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import tape from 'tape';


tape('sec, app, front-matter-part, dedication, title, label', async function (t) {
t.plan(43);
t.plan(44);
const document = article;

t.ok(document.querySelector('#ack1[role="doc-acknowledgments"][data-ams-doc-level="1"]'), 'ack to role doc-acknowledgments with data-ams-doc-level');
Expand Down Expand Up @@ -65,6 +65,7 @@ tape('sec, app, front-matter-part, dedication, title, label', async function (t)
t.equal(document2.querySelector('#part').getAttribute('role'), 'doc-part', 'part role');
t.ok(document2.querySelector('#inparttitle h2'), 'sec with title in chapter in part: heading level reduced');
t.ok(document2.querySelector('#inpartlabel h2'), 'sec with label in chapter in part: heading level reduced');
t.equal(document2.querySelector('#xcb').getAttribute('data-ams-style'), 'xcb', 'sec with style, mapped to data-ams-style');

t.ok(document2.querySelector('#fmtitle header p[data-ams-doc="subtitle"]'), 'sec with title: subtitle to p with data-ams-doc');
t.ok(document2.querySelector('#fmlabel header p[data-ams-doc="subtitle"]'), 'sec with title: subtitle to p with data-ams-doc');
Expand Down

0 comments on commit 84c7699

Please sign in to comment.