diff --git a/src/extensions/cite/index.test.ts b/src/extensions/cite/index.test.ts new file mode 100644 index 000000000..b3415953e --- /dev/null +++ b/src/extensions/cite/index.test.ts @@ -0,0 +1,47 @@ +import { whenReady, select, tag, attr } from '../../util' + +test('DOM manipulations', async () => { + const body = document.body + body.innerHTML = ` +
+
    +
  1. +
    + +
    + +
    +
    The continuing case for the Renshaw cell + +
      + + +
    + +
  2. +
+
+ ` + + await import('.') + whenReady() + + expect(select('ol:--authors').length).toBe(0) + expect(select('span:--authors').length).toBe(1) + + expect(select('li:--author').length).toBe(0) + expect(select('span:--author').length).toBe(2) + + expect( + select(':--reference > *').map(elem => [ + tag(elem).toLowerCase(), + attr(elem, 'itemprop') ?? attr(elem, 'data-itemprop') + ]) + ).toEqual([ + ['span', 'authors'], + ['time', 'datePublished'], + ['span', 'headline'], + ['span', 'publisher'], + ['meta', 'image'] + ]) +}) diff --git a/src/extensions/cite/index.ts b/src/extensions/cite/index.ts index da32c413f..6f4038cf5 100644 --- a/src/extensions/cite/index.ts +++ b/src/extensions/cite/index.ts @@ -1,7 +1,58 @@ -import { ready, create, replace, select, attr } from '../../util' +import { ready, create, replace, select, attr, first, tag, attrs } from '../../util' + +// Import the `person` extension for improved structure of a Person's name +import '../person' /** - * Currently, Encoda encodes a `CreativeWork.datePublished` as + * This is a temporary patch for https://github.com/stencila/encoda/issues/455 + * + * Currently, Encoda encodes each `reference` in the `references` property of + * an article as. + * + * ```html + *
  • + *
    + * ... + *
    + * + * + * A comparative review of short and long neuropeptide F signaling in invertebrates: any + * similarities to vertebrate neuropeptide Y signaling? + * + * + *
      + * + * + *
    + * + * + * + * + *
  • + * ``` + * + * We want to be able to display them using citation styles like APA: + * + * ```text + * Nässel, D. R., & Wegener, C. (2011). A comparative review of short and long + * neuropeptide F signaling in invertebrates: any similarities to vertebrate + * neuropeptide Y signaling?. Peptides, 32(6), 1335-1355. + * ``` + * + * It would be less work for CSS developers if these properties were in the order most commonly + * used in citation styles: + * + * - authors (as nested spans, rather than an ol) + * - datePublished + * - title (aka headline) + * - isPartOf + * - publisher + * - image + * + * Note that `publisher` and `image` are always encoded to HTML, even if missing, for conformance with GSDTT, + * and that some properties are missing in HTML, e.g. `isPartOf` (which provides the `Peptides, 32(6), 1335-1355` bit). + * + * Also, currently, `datePublished` is encoded as * * ```html * @@ -10,23 +61,46 @@ import { ready, create, replace, select, attr } from '../../util' * * ``` * - * So that we can style the date, a better encoding would simply be: + * A better encoding for styling, and concision, is: * * ```html - * + * * ``` * * Noting that for `