@canopycanopycanopy/b-ber-grammar-footnotes 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,20 @@
1
- # `@canopycanopycanopy/b-ber-grammar-footnotes`
1
+ # b-ber-grammar-footnotes
2
2
 
3
- The `b-ber-grammar-footnotes` package renders b-ber's custom `footnotes` Markdown extension (directive) into HTML. More information about b-ber directives can be found in the [All directives](https://github.com/triplecanopy/b-ber/wiki/all-directives) page in the b-ber [Wiki](https://github.com/triplecanopy/b-ber/wiki).
3
+ Handles footnote collection and rendering as a MarkdownIt core rule (not a container directive). After MarkdownIt processes a source file, this package's plugin function receives the full token stream, prepends a `<section class="footnotes break-after">` wrapper with an `<h1>` heading (using the spine entry's title for the current file), appends the closing `</section>`, renders the augmented token stream to HTML, and stores the result in global state under `state.footnotes`. Footnote pages are generated later by `b-ber-parser-footnotes` from that collected state.
4
4
 
5
- ## Install
5
+ ## Usage
6
6
 
7
+ Registered as a MarkdownIt core rule by the rendering engine:
8
+
9
+ ```js
10
+ import footnotes from '@canopycanopycanopy/b-ber-grammar-footnotes'
11
+ // default export is a factory: (self) => plugin(tokens)
7
12
  ```
8
- $ npm i -g @canopycanopycanopy/b-ber-grammar-footnotes
13
+
14
+ ## Dev
15
+
9
16
  ```
17
+ npm test
18
+ ```
19
+
20
+ Tests are in `__tests__/index.test.js`.
@@ -0,0 +1,4 @@
1
+ //#region src/index.d.ts
2
+ declare function markdownItFootnotePlugin(self: any): (tokens: any) => void;
3
+ export = markdownItFootnotePlugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";iBAEwB,wBAAA,CAAyB,IAAA,SACxB,MAAM;AAAA"}
package/dist/index.js CHANGED
@@ -1,59 +1,41 @@
1
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
5
- _Object$defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = markdownItFootnotePlugin;
9
- var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
10
- var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
1
+ let _canopycanopycanopy_b_ber_lib = require("@canopycanopycanopy/b-ber-lib");
2
+ //#region src/index.ts
11
3
  function markdownItFootnotePlugin(self) {
12
- return function plugin(tokens) {
13
- const {
14
- fileName
15
- } = self;
16
- const entry = (0, _find.default)(_State.default).call(_State.default, 'spine.flattened', {
17
- fileName
18
- });
19
- const title = (entry === null || entry === void 0 ? void 0 : entry.title) || fileName;
20
-
21
- // Add footnote container and heading. Doing this here instead of in
22
- // `footnotes.js` because we need the file's title
23
- tokens.unshift({
24
- type: 'block',
25
- tag: 'section',
26
- attrs: [['class', 'footnotes break-after']],
27
- nesting: 1,
28
- block: true
29
- }, {
30
- type: 'block',
31
- tag: 'h1',
32
- nesting: 1,
33
- block: true
34
- }, {
35
- type: 'text',
36
- block: false,
37
- content: title
38
- }, {
39
- type: 'block',
40
- tag: 'h1',
41
- nesting: -1
42
- });
43
-
44
- // add closing section tag
45
- tokens.push({
46
- type: 'block',
47
- tag: 'section',
48
- nesting: -1
49
- });
50
- const notes = self.markdownIt.renderer.render(tokens, 0, {
51
- reference: `${fileName}.xhtml`
52
- });
53
- _State.default.add('footnotes', {
54
- fileName,
55
- title,
56
- notes
57
- });
58
- };
59
- }
4
+ return function plugin(tokens) {
5
+ const { fileName } = self;
6
+ const title = _canopycanopycanopy_b_ber_lib.State.find("spine.flattened", { fileName })?.title || fileName;
7
+ tokens.unshift({
8
+ type: "block",
9
+ tag: "section",
10
+ attrs: [["class", "footnotes break-after"]],
11
+ nesting: 1,
12
+ block: true
13
+ }, {
14
+ type: "block",
15
+ tag: "h1",
16
+ nesting: 1,
17
+ block: true
18
+ }, {
19
+ type: "text",
20
+ block: false,
21
+ content: title
22
+ }, {
23
+ type: "block",
24
+ tag: "h1",
25
+ nesting: -1
26
+ });
27
+ tokens.push({
28
+ type: "block",
29
+ tag: "section",
30
+ nesting: -1
31
+ });
32
+ const notes = self.markdownIt.renderer.render(tokens, 0, { reference: `${fileName}.xhtml` });
33
+ _canopycanopycanopy_b_ber_lib.State.add("footnotes", {
34
+ fileName,
35
+ title,
36
+ notes
37
+ });
38
+ };
39
+ }
40
+ //#endregion
41
+ module.exports = markdownItFootnotePlugin;
package/package.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-footnotes",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "prepare:dist": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --ignore **/__tests__/**",
8
- "clean": "rimraf dist",
9
- "prepare": "npm run clean && npm run prepare:dist",
10
- "build": "npm run prepare",
11
- "watch": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --watch src",
7
+ "build": "tsdown",
8
+ "watch": "tsdown --watch",
9
+ "typecheck": "tsc --noEmit",
12
10
  "test": "jest"
13
11
  },
14
12
  "author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
@@ -17,15 +15,15 @@
17
15
  "access": "public"
18
16
  },
19
17
  "devDependencies": {
20
- "@babel/cli": "^7.10.5",
21
- "@babel/core": "^7.10.5",
22
- "@babel/preset-env": "^7.10.4",
23
- "browserslist": "^4.17.4",
24
- "jest": "^26.6.3",
25
- "rimraf": "^2.7.1"
18
+ "@swc/core": "^1.15.40",
19
+ "@swc/jest": "^0.2.39",
20
+ "jest": "^29.7.0",
21
+ "rimraf": "^2.7.1",
22
+ "tsdown": "^0.22.1",
23
+ "typescript": "^6.0.3"
26
24
  },
27
25
  "dependencies": {
28
- "@canopycanopycanopy/b-ber-lib": "3.1.0",
26
+ "@canopycanopycanopy/b-ber-lib": "4.0.0",
29
27
  "lodash": "^4.17.21",
30
28
  "lodash.find": "latest",
31
29
  "tar": "^6.1.11"
@@ -47,5 +45,6 @@
47
45
  "url": "https://maxwellsimmer.com"
48
46
  }
49
47
  ],
50
- "gitHead": "59963709eda1a8eb12dde95405f8f01086d12cc7"
48
+ "gitHead": "435b9c7e6b97d3fbdeb21f2308283597040ebfc8",
49
+ "types": "dist/index.d.ts"
51
50
  }