/** * [[include:src/codecs/jats/README.md]] * * @module codecs/jats */ /** * Hello contributor 👋! If you are working on this file, please * endeavor to remove the need for the following `eslint-disable` line 🙏. * Remove the line and run `npx eslint path/to/this/file.ts` to * see which code needs some linting ❤️. * See https://github.com/stencila/encoda/issues/199 for suggestions * on how to refactor code to avoid non-strict boolean expressions. */ import stencila from '@stencila/schema'; import * as vfile from '../../util/vfile'; import * as xml from '../../util/xml'; import { Codec, CommonEncodeOptions } from '../types'; type Content = stencila.InlineContent | stencila.BlockContent; export declare class JatsCodec extends Codec implements Codec { /** * Media types that this codec will match. * * There is currently no registered * [media type](https://www.iana.org/assignments/media-types/media-types.xhtml) * for JATS. * * This custom type uses the [convention](https://en.wikipedia.org/wiki/XML_and_MIME) * of using `application/` and the `+xml` suffix to differentiate this format from other * XML-based formats. */ readonly mediaTypes: string[]; /** * File name extensions that this codec will match. */ readonly extNames: string[]; /** * Sniff content to see if it is JATS XML. * * For speed, rather than parsing the entire content as XML, this * function just uses a regex to checks if the content contains a * JATS DOCTYPE declaration. * Obviously, it's possible that a file in some other format (e.g. Markdown) * could contain this string. * * @param content The content to be sniffed */ readonly sniff: (content: string) => Promise; /** * Decode a `VFile` with JATS content to a Stencila `Node`. * * @param file The `VFile` to decode * @returns A promise that resolves to a Stencila `Node` */ readonly decode: (file: vfile.VFile) => Promise; /** * Encode a Stencila `Node` to a `VFile` with JATS content. * * @param thing The Stencila `Node` to encode * @returns A promise that resolves to a `VFile` */ readonly encode: (node: stencila.Node, options?: CommonEncodeOptions) => Promise; } /** * It is necessary to maintain some state during decoding. * This interface defines that state; an instance * is passed down through decoding functions. * * An alternative approach would be to make the functions * methods of a class (e.g. the `JatsCodec` class). */ export interface DecodeState { /** * The current `
` element. Used for * getting the target of internal references. */ article: xml.Element; /** * The closest ancestor element. It is up to * decode functions to set this, therefore not * necessarily the parent */ ancestorElem: xml.Element; /** * The id of the current section. Used for setting the * id of headings. */ sectionId: string; /** * The depth of the current section. Used for setting the depth * of headings. */ sectionDepth: number; } /** * Decode a JATS `` element to a Stencila `Article.description`. * * Removes any 'Abstract' heading. */ export declare function decodeAbstract(elem: xml.Element | null, state: DecodeState): stencila.Article['description']; /** * Encode a Stencila `Article.description` to a JATS `` element. */ export declare function encodeAbstract(description?: stencila.Article['description']): xml.Element | null; /** * Decode elements from the `` of a JATS article into an `Article.meta` property. */ export declare function decodeMetaFront(front: xml.Element): stencila.Article['meta']; /** * Decode JATS `` elements * to a Stencila `Article.authors` property. */ export declare function decodeAuthors(front: xml.Element, state: DecodeState): stencila.Article['authors']; /** * Decode a JATS `` element into a Stencila `Organization` node. * * Uses the first `` element as the name of the organization. * Sometimes there is no `` element and `` is * used for name and address combined. So this uses the first address components * as the name if necessary. * * When there are multiple `` elements this decodes them * assuming that they are ordered hierarchically i.e. that the first * is a part of the second etc. See https://github.com/stencila/encoda/issues/458 */ export declare function decodeAff(aff: xml.Element): stencila.Organization; /** * Decode a JATS `` or `` element * into a `CreativeWork` node. */ export declare function decodeReference(elem: xml.Element, ident: string | null, label: string | undefined): stencila.CreativeWork; /** * Decode a JATS `` element to a Stencila `Table` node. * * In some JATS, there is no actual table but rather image/s of the table. * For those we return a `Figure` but one which usually has a label begginning * with 'Table'. */ export declare function decodeTableWrap(elem: xml.Element, state: DecodeState): (stencila.Table | stencila.Figure)[]; /** * Decode a JATS `` element to a Stencila `Figure` node. * * Sometimes the element is used for tables (where the table is represented * as an image). So, if the