diff --git a/lib/handlers/footnote.js b/lib/handlers/footnote.js deleted file mode 100644 index 145a6b7..0000000 --- a/lib/handlers/footnote.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @typedef {import('hast').Element} Element - * @typedef {import('mdast').FootnoteDefinition} FootnoteDefinition - * @typedef {import('mdast').Node} Node - * @typedef {import('../state.js').State} State - */ - -import {footnoteReference} from './footnote-reference.js' - -// To do: when both: -// * -// * -// …are archived, remove this (also from mdast). -// These inline notes are not used in GFM. - -/** - * Turn an mdast `footnote` node into hast. - * - * @param {State} state - * Info passed around. - * @param {Node} node - * mdast node. - * @returns {Element} - * hast node. - */ -export function footnote(state, node) { - let no = 1 - - while (state.footnoteById.get(String(no))) no++ - - const identifier = String(no) - /** @type {FootnoteDefinition} */ - const definition = { - type: 'footnoteDefinition', - identifier, - // @ts-expect-error: to do: remove this. - children: [{type: 'paragraph', children: node.children}], - position: node.position - } - - state.footnoteById.set(identifier, definition) - - return footnoteReference(state, { - type: 'footnoteReference', - identifier, - position: node.position - }) -} diff --git a/lib/handlers/index.js b/lib/handlers/index.js index d93f45d..ff572dc 100644 --- a/lib/handlers/index.js +++ b/lib/handlers/index.js @@ -4,7 +4,6 @@ import {code} from './code.js' import {strikethrough} from './delete.js' import {emphasis} from './emphasis.js' import {footnoteReference} from './footnote-reference.js' -import {footnote} from './footnote.js' import {heading} from './heading.js' import {html} from './html.js' import {imageReference} from './image-reference.js' @@ -33,7 +32,6 @@ export const handlers = { delete: strikethrough, emphasis, footnoteReference, - footnote, heading, html, imageReference, diff --git a/test/footnote-mixed.js b/test/footnote-mixed.js deleted file mode 100644 index 14754b1..0000000 --- a/test/footnote-mixed.js +++ /dev/null @@ -1,54 +0,0 @@ -import assert from 'node:assert/strict' -import test from 'node:test' -import {toHtml} from 'hast-util-to-html' -import {toHast} from '../index.js' - -test('footnote', async function (t) { - const mdast = toHast({ - type: 'root', - children: [ - { - type: 'paragraph', - children: [ - {type: 'text', value: 'alpha'}, - // @ts-expect-error: to do: remove footnotes. - {type: 'footnote', children: [{type: 'text', value: 'bravo'}]} - ] - }, - { - type: 'paragraph', - children: [ - {type: 'text', value: 'charlie'}, - {type: 'footnoteReference', identifier: 'x'} - ] - }, - { - type: 'footnoteDefinition', - identifier: 'x', - children: [ - {type: 'paragraph', children: [{type: 'text', value: 'delta'}]} - ] - } - ] - }) - assert(mdast, 'expected node') - - await t.test('should order the footnote section by usage', async function () { - assert.deepEqual( - // @ts-expect-error: to do: remove when `to-html` is released. - toHtml(mdast), - `

alpha1

-

charlie2

-

Footnotes

-
    -
  1. -

    bravo

    -
  2. -
  3. -

    delta

    -
  4. -
-
` - ) - }) -}) diff --git a/test/footnote.js b/test/footnote.js index b899515..952b221 100644 --- a/test/footnote.js +++ b/test/footnote.js @@ -8,65 +8,6 @@ import {toHast} from '../index.js' test('footnote', async function (t) { await t.test('should render `footnote`s (#1)', async function () { - const tree = toHast({ - type: 'root', - // @ts-expect-error: to do: remove `footnote`s. - children: [{type: 'footnote', children: [{type: 'text', value: 'alpha'}]}] - }) - assert(tree, 'expected node') - assert.equal( - // @ts-expect-error: to do: remove when `to-html` is released. - toHtml(tree), - `1 -

Footnotes

-
    -
  1. -

    alpha

    -
  2. -
-
` - ) - }) - - await t.test('should render `footnote`s (#2)', async function () { - const tree = toHast({ - type: 'root', - children: [ - { - type: 'footnoteDefinition', - identifier: '1', - children: [ - {type: 'paragraph', children: [{type: 'text', value: 'bravo'}]} - ] - }, - { - type: 'paragraph', - children: [{type: 'footnoteReference', identifier: '1'}] - }, - // @ts-expect-error: to do: remove `footnote`s. - {type: 'footnote', children: [{type: 'text', value: 'charlie'}]} - ] - }) - assert(tree, 'expected node') - assert.equal( - // @ts-expect-error: to do: remove when `to-html` is released. - toHtml(tree), - `

1

-2 -

Footnotes

-
    -
  1. -

    bravo

    -
  2. -
  3. -

    charlie

    -
  4. -
-
` - ) - }) - - await t.test('should render `footnote`s (#3)', async function () { const tree = toHast({ type: 'root', children: [ diff --git a/test/index.js b/test/index.js index 4572362..4937b93 100644 --- a/test/index.js +++ b/test/index.js @@ -8,7 +8,6 @@ import './delete.js' import './emphasis.js' import './footnote-definition.js' import './footnote-reference.js' -import './footnote-mixed.js' import './footnote.js' import './heading.js' import './html.js'