Skip to content

Commit 2859e32

Browse files
committed
fix(HTML): Add data-itemscope=root to top level node
The current use for this is to scope CSS variables in Thema to the lop-level Stencila node.
1 parent 2b7a011 commit 2859e32

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/codecs/html/__file_snapshots__/article-math.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article itemscope="" itemtype="http://schema.org/Article">
1+
<article itemscope="" itemtype="http://schema.org/Article" data-itemscope="root">
22
<div itemscope="" itemtype="http://schema.org/Organization" itemprop="publisher">
33
<meta itemprop="name" content="Unknown">
44
<div itemscope="" itemtype="http://schema.org/ImageObject" itemprop="logo">

src/codecs/html/__file_snapshots__/elife-50356.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article itemscope="" itemtype="http://schema.org/Article">
1+
<article itemscope="" itemtype="http://schema.org/Article" data-itemscope="root">
22
<div itemscope="" itemtype="http://schema.org/Organization" itemprop="publisher">
33
<meta itemprop="name" content="Unknown">
44
<div itemscope="" itemtype="http://schema.org/ImageObject" itemprop="logo">

src/codecs/html/__file_snapshots__/kitchen-sink.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<article itemscope="" itemtype="http://schema.org/Article">
1+
<article itemscope="" itemtype="http://schema.org/Article" data-itemscope="root">
22
<div itemscope="" itemtype="http://schema.org/Organization" itemprop="publisher">
33
<meta itemprop="name" content="Unknown">
44
<div itemscope="" itemtype="http://schema.org/ImageObject" itemprop="logo">

src/codecs/html/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,13 @@ export class HTMLCodec extends Codec implements Codec {
234234
}
235235

236236
/**
237-
* Encode a `stencila.Node` to a `VFile` with HTML contents.
237+
* Encode a Stencila `Node` to a `VFile` with HTML contents.
238238
*
239-
* @param node The `stencila.Node` to encode. Will be mutated to an `Node`.
239+
* The attribute `data-itemscope="root"` is added to the root node
240+
* of the encoded HTML. This attribute can be used to scope CSS variables
241+
* to within the top-level Stencila Node.
242+
*
243+
* @param node The `Node` to encode.
240244
* @returns A promise that resolves to a `VFile`
241245
*/
242246
public readonly encode = async (
@@ -259,12 +263,13 @@ export class HTMLCodec extends Codec implements Codec {
259263
const nodeToEncode = isBundle
260264
? await bundle(node)
261265
: await toFiles(node, filePath, ['data', 'file'])
262-
let dom: HTMLHtmlElement = encodeNode(nodeToEncode) as HTMLHtmlElement
266+
267+
let dom = encodeNode(nodeToEncode) as HTMLElement
268+
dom.setAttribute('data-itemscope', 'root')
263269

264270
const mathjaxCss = await mathJaxFinish()
265271

266272
if (isStandalone) {
267-
const nodeToEncode = isBundle ? await bundle(node) : node
268273
const { title = 'Untitled' } = getArticleMetaData(nodeToEncode)
269274
dom = await generateHtmlElement(
270275
stringifyContent(title),

0 commit comments

Comments
 (0)