stencila / encoda

↔️ A format converter for Stencila documents
https://stencila.github.io/encoda/
Apache License 2.0
35 stars 9 forks source link

JATS: Footnote support #880

Open rgieseke opened 3 years ago

rgieseke commented 3 years ago

Probably related to issue #144

How would one add support to read a footnote as an inline element as part of a paragraph? Right now it's rendered as another paragraph next to the paragraph which has the annotated word as the last word.

E.g. JATS:

    <p id="p1">Text<fn id="idm6"><p id="footnote1">Footy note about Text.</p></fn> begins and ends.</p>

To JSON:

"content": [
    {
      "type": "Paragraph",
      "id": "p1",
      "content": [
        "Text"
      ]
    },
    {
      "type": "Paragraph",
      "id": "footnote1",
      "content": [
        "Footy note about Text."
      ]
    },
    {
      "type": "Paragraph",
      "content": [
        " begins and ends."
      ]
    }

It should be inline like a mark i think:

  {
      "type": "Paragraph",
      "id": "p2",
      "content": [
        "Normal Text, ",
        {
          "type": "Strong",
          "content": [
            "bold"
          ]
        },
        " or not."
      ]
    }

I played around with adding a decodeFootnote function but don't really know what the best approach would be.

nokome commented 3 years ago

Thanks for raising this @rgieseke. I propose a new Note type that would encompass footnotes and endnotes (and perhaps default to being an inline note i.e. in HTML it appears when you hover over it?):

[
  {
    "type": "Paragraph",
    "id": "p1",
    "content": ["Text"]
  },
  {
    "type": "Note",
    "id": "idm6",
    "noteType": "Footnote",
    "content": [
      {
        "type": "Paragraph",
        "id": "footnote1",
        "content": ["Footy note about Text."]
      }
    ]
  },
  {
    "type": "Paragraph",
    "content": [" begins and ends."]
  }
]

The Note.schema.yaml in https://github.com/stencila/schema/tree/master/schema would look something like,

title: Note
'@id': stencila:Note
extends: Entity
role: secondary
status: unstable
description: .
properties:
  noteType:
    '@id': stencila:noteType
    description: Determines where the note content is displayed within document.
    type: string
    enum:
      - Footnote
      - Endnote
  content:
    '@id': stencila:content
    description: Content of the note, usually a paragraph.
    type: array
    items:
      $ref: BlockContent
    $comment: |
      Most notes will have a single paragraph but could have multiple
      paragraphs, tables and even figures.
required:
  - content

But needs more research into how other document schemas represent footnotes etc e.g. JATS, Pandoc, MDAST.

rgieseke commented 3 years ago

This sounds quite good!

JATS describes <fn> footnotes like:

Additional information tied to a particular location in the text. This material is not considered to be part of the body of the text, but is a note used instead of, in addition to, as a source for, or as a commentary on either some body text or on an element in the metadata such as an author.

They can be grouped in <fn-group> for endnotes:

When footnotes are grouped at the end of an article, wrap them in a and use an element in the text, as usual, to tie each footnote in the list to a particular location in the text.

https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/fn.html

Pandoc Markdown extension allows for footnotes like:

Here is a footnote reference,[^1] and another.[^longnote]

[^1]: Here is the footnote.

[^longnote]: Here's one with multiple blocks.

https://pandoc.org/MANUAL.html#footnotes

It HTML sidenotes or margin notes are also quite common (e.g. https://edwardtufte.github.io/tufte-css/#sidenotes), but there is no implementation standard, so it would be difficult to parse and have a separate category to footnote/endnote.

<aside> is sometimes used:

The HTML

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside

Should we continue this as a PR to stencila/schema?

nokome commented 3 years ago

Thanks for doing that research,, useful stuff.

Should we continue this as a PR to stencila/schema?

Yes, if you could start one based on the above YAML that'd be great.