Skip to content

Commit

Permalink
feat(Microdata): Add microdataRoot function
Browse files Browse the repository at this point in the history
Closes #175
  • Loading branch information
nokome committed Feb 26, 2020
1 parent b64b456 commit a9b1989
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ts/util/microdata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
microdataType,
microdata,
microdataItem,
microdataProperty
microdataProperty,
microdataRoot
} from './microdata'
import { codeChunk, article, person, thing, organization } from '../types'

Expand Down Expand Up @@ -124,3 +125,7 @@ test('microdataItemprop', () => {

expect(microdataItemprop('foo')).toEqual([undefined, undefined])
})

test('microdataRoot', () => {
expect(microdataRoot()).toEqual({'data-itemscope': 'root'})
})
15 changes: 15 additions & 0 deletions ts/util/microdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,18 @@ export function microdataItemprop(

return [prefix, name]
}

/**
* Get the 'pseudo' HTML Microdata attribute for the root element.
*
* This attribute name / value pair is used to scope CSS variables to
* the root Stencila node in an HML document. It is used by Encoda when
* encoding to HTML, it is in Thema to scope CSS variable thereby
* avoiding variable name clashes from using the CSS `:root` pseudo-class.
*
* Although not directly related to Microdata, given it is used in both
* of those projects, this appears to be the best place for it.
*/
export function microdataRoot(): {'data-itemscope': 'root'} {
return {'data-itemscope': 'root'}
}

0 comments on commit a9b1989

Please sign in to comment.