@adobe/helix-markdown-support 1.5.0 → 3.1.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.
@@ -1,8 +1,8 @@
1
1
  version: 2.1
2
2
  executors:
3
- node12:
3
+ node14:
4
4
  docker:
5
- - image: circleci/node:12
5
+ - image: circleci/node:14
6
6
  environment:
7
7
  NPM_CONFIG_PREFIX: ~/.npm-global
8
8
 
@@ -29,7 +29,7 @@ commands:
29
29
 
30
30
  jobs:
31
31
  build:
32
- executor: node12
32
+ executor: node14
33
33
 
34
34
  steps:
35
35
  - setup
package/.eslintrc.cjs ADDED
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright 2019 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ module.exports = {
14
+ root: true,
15
+ extends: '@adobe/helix',
16
+ env: {
17
+ node: true,
18
+ es6: true,
19
+ },
20
+ parserOptions: {
21
+ sourceType: 'module',
22
+ ecmaVersion: 2020,
23
+ },
24
+ rules: {
25
+ 'import/extensions': 0,
26
+ },
27
+ };
@@ -10,10 +10,10 @@ jobs:
10
10
  if: "!contains(github.event.head_commit.message, '[skip ci]')"
11
11
  steps:
12
12
  - uses: actions/checkout@v2
13
- - name: Use Node.js 12.x
13
+ - name: Use Node.js 14.x
14
14
  uses: actions/setup-node@v2
15
15
  with:
16
- node-version: '12.x'
16
+ node-version: '14.x'
17
17
  - run: npm install
18
18
  - run: npm test
19
19
  - run: npm run semantic-release
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -0,0 +1,6 @@
1
+ {
2
+ "reporterEnabled": "spec,xunit",
3
+ "xunitReporterOptions": {
4
+ "output": "junit/test-results.xml"
5
+ }
6
+ }
package/.nycrc.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "reporter": [
3
+ "lcov",
4
+ "text"
5
+ ],
6
+ "check-coverage": true,
7
+ "lines": 100,
8
+ "branches": 100,
9
+ "statements": 100
10
+ }
package/.releaserc.cjs ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ plugins: [
3
+ "@semantic-release/commit-analyzer",
4
+ "@semantic-release/release-notes-generator",
5
+ ["@semantic-release/changelog", {
6
+ "changelogFile": "CHANGELOG.md",
7
+ }],
8
+ "@semantic-release/npm",
9
+ ["@semantic-release/git", {
10
+ "assets": ["package.json", "CHANGELOG.md"],
11
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
12
+ }],
13
+ ["@semantic-release/github", {}]
14
+ ],
15
+ branches: [ 'main' ],
16
+ };
package/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ # [3.1.0](https://github.com/adobe/helix-markdown-support/compare/v3.0.0...v3.1.0) (2022-01-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * improve sanitize-headings to move leading images before heading ([292dc72](https://github.com/adobe/helix-markdown-support/commit/292dc72dbe43def0d97e8f1c528eeb065b3bff12)), closes [#83](https://github.com/adobe/helix-markdown-support/issues/83)
7
+
8
+ # [3.0.0](https://github.com/adobe/helix-markdown-support/compare/v2.0.1...v3.0.0) (2021-12-07)
9
+
10
+
11
+ ### Features
12
+
13
+ * convert to esm ([0b5e09b](https://github.com/adobe/helix-markdown-support/commit/0b5e09bac1e7e26128d7af8f25c85eadc82ff56c))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * only esm supported
19
+
20
+ ## [2.0.1](https://github.com/adobe/helix-markdown-support/compare/v2.0.0...v2.0.1) (2021-07-23)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * allow html in table cells ([9afe468](https://github.com/adobe/helix-markdown-support/commit/9afe468057101b28d17ae218f45666e1ec9829c6))
26
+
27
+ # [2.0.0](https://github.com/adobe/helix-markdown-support/compare/v1.5.0...v2.0.0) (2021-06-09)
28
+
29
+
30
+ ### Features
31
+
32
+ * **table:** convert all tables to HTML and convey cell alignment ([#27](https://github.com/adobe/helix-markdown-support/issues/27)) ([154bfe4](https://github.com/adobe/helix-markdown-support/commit/154bfe46e0416272fa08122e447ab4aea2cafc58)), closes [#26](https://github.com/adobe/helix-markdown-support/issues/26)
33
+
34
+
35
+ ### BREAKING CHANGES
36
+
37
+ * **table:** simple md tables no longer remain markdown
38
+
1
39
  # [1.5.0](https://github.com/adobe/helix-markdown-support/compare/v1.4.0...v1.5.0) (2021-05-11)
2
40
 
3
41
 
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "1.5.0",
3
+ "version": "3.1.0",
4
4
  "description": "Helix Markdown Support",
5
+ "type": "module",
5
6
  "scripts": {
6
- "test": " nyc --reporter=text --reporter=lcov --check-coverage --branches 100 --statements 100 --lines 100 mocha",
7
- "test-ci": "nyc --reporter=text --reporter=lcov --check-coverage --branches 100 --statements 100 --lines 100 mocha --reporter xunit --reporter-options output=./junit/test-results.xml && codecov",
8
- "lint": "./node_modules/.bin/eslint .",
7
+ "test": " c8 mocha",
8
+ "test-ci": "c8 mocha && codecov",
9
+ "lint": "eslint .",
9
10
  "semantic-release": "semantic-release",
10
- "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
11
- "commit": "git-cz"
11
+ "prepare": "husky install"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -22,51 +22,44 @@
22
22
  "homepage": "https://github.com/adobe/helix-markdown-support#readme",
23
23
  "main": "src/index.js",
24
24
  "dependencies": {
25
- "hast-util-to-html": "7.1.3",
25
+ "hast-util-to-html": "8.0.3",
26
26
  "js-yaml": "4.1.0",
27
- "mdast-util-to-hast": "10.2.0",
27
+ "mdast-util-to-hast": "12.0.0",
28
28
  "unist-util-find": "1.0.2",
29
- "unist-util-visit": "2.0.3"
29
+ "unist-util-visit": "4.1.0"
30
+ },
31
+ "mocha": {
32
+ "spec": "test/**/*.test.js",
33
+ "recursive": "true",
34
+ "reporter": "mocha-multi-reporters",
35
+ "reporter-options": "configFile=.mocha-multi.json"
30
36
  },
31
37
  "peerDependencies": {
32
- "unified": "9.x"
38
+ "unified": "10.x"
33
39
  },
34
40
  "devDependencies": {
35
- "@adobe/eslint-config-helix": "1.1.4",
36
- "@semantic-release/changelog": "5.0.1",
37
- "@semantic-release/git": "9.0.0",
38
- "@semantic-release/npm": "7.1.3",
39
- "ajv": "8.2.0",
40
- "codecov": "3.8.2",
41
- "commitizen": "4.2.4",
42
- "cz-conventional-changelog": "3.3.0",
43
- "eslint": "7.26.0",
41
+ "@adobe/eslint-config-helix": "1.3.2",
42
+ "@semantic-release/changelog": "6.0.1",
43
+ "@semantic-release/git": "10.0.1",
44
+ "c8": "7.11.0",
45
+ "codecov": "3.8.3",
46
+ "eslint": "8.6.0",
44
47
  "eslint-plugin-header": "3.1.1",
45
- "eslint-plugin-import": "2.22.1",
46
- "fs-extra": "10.0.0",
47
- "ghooks": "2.0.4",
48
- "jsdoc-to-markdown": "7.0.1",
48
+ "eslint-plugin-import": "2.25.4",
49
+ "husky": "7.0.4",
49
50
  "junit-report-builder": "3.0.0",
50
- "lint-staged": "11.0.0",
51
+ "lint-staged": "12.1.7",
51
52
  "mdast-builder": "1.1.1",
52
- "mocha": "8.4.0",
53
- "nyc": "15.1.0",
54
- "remark-gfm": "1.0.0",
55
- "remark-parse": "9.0.0",
56
- "remark-stringify": "9.0.1",
57
- "semantic-release": "17.4.2",
58
- "unified": "9.2.1",
59
- "unist-util-inspect": "6.0.1"
53
+ "mocha": "9.1.3",
54
+ "mocha-multi-reporters": "1.5.1",
55
+ "remark-gfm": "3.0.1",
56
+ "remark-parse": "10.0.1",
57
+ "remark-stringify": "10.0.2",
58
+ "semantic-release": "18.0.1",
59
+ "unified": "10.1.1",
60
+ "unist-util-inspect": "7.0.0"
60
61
  },
61
62
  "lint-staged": {
62
63
  "*.js": "eslint"
63
- },
64
- "config": {
65
- "commitizen": {
66
- "path": "node_modules/cz-conventional-changelog"
67
- },
68
- "ghooks": {
69
- "pre-commit": "npx lint-staged"
70
- }
71
64
  }
72
65
  }
package/src/index.js CHANGED
@@ -10,24 +10,12 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- const remarkMatter = require('./remark-matter');
14
- const robustTables = require('./mdast-robust-tables.js');
15
- const breaksAsSpaces = require('./remark-breaks-as-spaces.js');
16
- const sanitizeHeading = require('./mdast-sanitize-heading.js');
17
- const suppressSpaceCode = require('./mdast-suppress-spacecode.js');
18
- const sanitizeFormats = require('./mdast-sanitize-formats.js');
19
- const fixCodeFlow = require('./mdast-fix-code-flow.js');
20
- const sanitizeLinks = require('./mdast-sanitize-links.js');
21
- const sanitizeText = require('./mdast-sanitize-text.js');
22
-
23
- module.exports = {
24
- remarkMatter,
25
- robustTables,
26
- breaksAsSpaces,
27
- sanitizeHeading,
28
- suppressSpaceCode,
29
- sanitizeFormats,
30
- fixCodeFlow,
31
- sanitizeLinks,
32
- sanitizeText,
33
- };
13
+ export { default as remarkMatter } from './remark-matter/index.js';
14
+ export { default as robustTables } from './mdast-robust-tables.js';
15
+ export { default as breaksAsSpaces } from './remark-breaks-as-spaces.js';
16
+ export { default as sanitizeHeading } from './mdast-sanitize-heading.js';
17
+ export { default as suppressSpaceCode } from './mdast-suppress-spacecode.js';
18
+ export { default as sanitizeFormats } from './mdast-sanitize-formats.js';
19
+ export { default as fixCodeFlow } from './mdast-fix-code-flow.js';
20
+ export { default as sanitizeLinks } from './mdast-sanitize-links.js';
21
+ export { default as sanitizeText } from './mdast-sanitize-text.js';
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  /* eslint-disable no-param-reassign */
13
- const visit = require('unist-util-visit');
13
+ import { visit, CONTINUE } from 'unist-util-visit';
14
14
 
15
15
  /**
16
16
  * ensures that `code` is at a flow level. i.e. outside a paragraph
@@ -18,7 +18,7 @@ const visit = require('unist-util-visit');
18
18
  * @param {object} tree
19
19
  * @returns {object} The modified (original) tree.
20
20
  */
21
- function fixCodeFlow(tree) {
21
+ export default function fixCodeFlow(tree) {
22
22
  visit(tree, (node, index, parent) => {
23
23
  if (node.type === 'paragraph' && node.children) {
24
24
  for (let i = 0; i < node.children.length; i += 1) {
@@ -50,9 +50,7 @@ function fixCodeFlow(tree) {
50
50
  }
51
51
  }
52
52
  // return index;
53
- return visit.CONTINUE;
53
+ return CONTINUE;
54
54
  });
55
55
  return tree;
56
56
  }
57
-
58
- module.exports = fixCodeFlow;
@@ -10,44 +10,68 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  /* eslint-disable no-param-reassign */
13
- const md2hast = require('mdast-util-to-hast');
14
- const hast2html = require('hast-util-to-html');
15
- const visit = require('unist-util-visit');
13
+ import { toHast as md2hast } from 'mdast-util-to-hast';
14
+ import { toHtml as hast2html } from 'hast-util-to-html';
15
+ import { visit, CONTINUE } from 'unist-util-visit';
16
16
 
17
17
  /**
18
- * Converts table cell content to HTML if it cannot be represented nicely as markdown.
18
+ * Converts tables to HTML
19
19
  *
20
20
  * @param {object} tree
21
21
  * @returns {object} The modified (original) tree.
22
22
  */
23
- function robustTables(tree) {
23
+ export default function robustTables(tree) {
24
24
  visit(tree, (node) => {
25
- if (node.type !== 'tableCell') {
26
- return visit.CONTINUE;
25
+ if (node.type !== 'table') {
26
+ return CONTINUE;
27
27
  }
28
- /* istanbul ignore next */
29
- const { children = [] } = node;
30
- if (children.length > 1 || (children.length === 1 && children[0].type !== 'paragraph')) {
31
- // ...then convert the problematic children to html nodes
32
- node.children.forEach((child) => {
33
- const html = hast2html(md2hast(child));
34
- switch (child.type) {
35
- case 'code': {
36
- // code needs special treatment, otherwise the newlines disappear.
37
- child.value = html.replace(/\r?\n/g, '<br>');
38
- break;
39
- }
40
- default: {
41
- // convert the rest to html
42
- child.value = html.replace(/\r?\n/g, ' ');
43
- }
28
+ let html = '<table>\n';
29
+ (node.children /* c8 ignore next */ || []).forEach((row) => {
30
+ html += ' <tr>\n';
31
+ (row.children /* c8 ignore next */ || []).forEach((cell) => {
32
+ let align = '';
33
+ if (cell.align === 'right') {
34
+ align = ' align="right"';
35
+ } else if (cell.align === 'center') {
36
+ align = ' align="center"';
37
+ } else if (cell.align === 'both') {
38
+ align = ' align="justify"';
39
+ }
40
+ if (cell.valign === 'middle') {
41
+ align += ' valign="middle"';
42
+ } else if (cell.valign === 'bottom') {
43
+ align += ' valign="bottom"';
44
+ }
45
+ html += ` <td${align}>`;
46
+
47
+ // if cell contains only 1 single paragraph, unwrap it
48
+ let { children } = cell;
49
+ if (children && children.length === 1 && children[0].type === 'paragraph') {
50
+ children = children[0].children;
44
51
  }
45
- child.type = 'html';
52
+
53
+ (children /* c8 ignore next */ || []).forEach((child) => {
54
+ if (child.type === 'html') {
55
+ html += child.value;
56
+ } else {
57
+ const cellHtml = hast2html(md2hast(child));
58
+ if (child.type === 'code') {
59
+ // code needs special treatment, otherwise the newlines disappear.
60
+ html += cellHtml.replace(/\r?\n/g, '<br>');
61
+ } else {
62
+ html += cellHtml.replace(/\r?\n/g, ' ');
63
+ }
64
+ }
65
+ });
66
+ html += '</td>\n';
46
67
  });
47
- }
48
- return visit.CONTINUE;
68
+ html += ' </tr>\n';
69
+ });
70
+ html += '</table>';
71
+ node.type = 'html';
72
+ node.value = html;
73
+ delete node.children;
74
+ return CONTINUE;
49
75
  });
50
76
  return tree;
51
77
  }
52
-
53
- module.exports = robustTables;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const visit = require('unist-util-visit');
12
+ import { visit, CONTINUE } from 'unist-util-visit';
13
13
 
14
14
  /**
15
15
  * Sanitizes text:
@@ -19,7 +19,7 @@ const visit = require('unist-util-visit');
19
19
  * @param {object} tree
20
20
  * @returns {object} The modified (original) tree.
21
21
  */
22
- function sanitizeFormats(tree) {
22
+ export default function sanitizeFormats(tree) {
23
23
  visit(tree, (node, index, parent) => {
24
24
  const { children: siblings = [] } = parent || {};
25
25
  const { children } = node;
@@ -43,9 +43,7 @@ function sanitizeFormats(tree) {
43
43
  }
44
44
  }
45
45
  }
46
- return visit.CONTINUE;
46
+ return CONTINUE;
47
47
  });
48
48
  return tree;
49
49
  }
50
-
51
- module.exports = sanitizeFormats;
@@ -9,42 +9,53 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const visit = require('unist-util-visit');
12
+ import { visit } from 'unist-util-visit';
13
13
 
14
14
  /**
15
15
  * Sanitizes headings:
16
- * - (re)move images
16
+ * - (re)move images ('before', 'both', 'after')
17
17
  *
18
18
  * @param {object} tree
19
+ * @param {object} [opts] options
20
+ * @param {string} [opts.imageHandling] specifies how images are handled. defaults to 'after'.
19
21
  * @returns {object} The modified (original) tree.
20
22
  */
21
- function sanitizeHeading(tree) {
23
+ export default function sanitizeHeading(tree, opts = {}) {
24
+ const { imageHandling = 'after' } = opts;
22
25
  visit(tree, (node, index, parent) => {
23
26
  const { children: siblings = [] } = parent || {};
24
27
  const { children = [] } = node;
28
+ let after = index + 1;
25
29
  if (node.type === 'heading') {
26
30
  for (let i = 0; i < children.length; i += 1) {
27
31
  const child = children[i];
28
32
  if (child.type === 'image') {
29
- // move after heading
30
- children.splice(i, 1);
31
- i -= 1;
32
33
  const para = {
33
34
  type: 'paragraph',
34
35
  children: [child],
35
36
  };
36
- siblings.splice(index + 1, 0, para);
37
+ children.splice(i, 1);
38
+ i -= 1;
39
+ if ((i < 0 && imageHandling !== 'after') || imageHandling === 'before') {
40
+ // move before heading
41
+ siblings.splice(index, 0, para);
42
+ // eslint-disable-next-line no-param-reassign
43
+ index += 1;
44
+ after = index + 1;
45
+ } else {
46
+ // move after heading
47
+ siblings.splice(after, 0, para);
48
+ after += 1;
49
+ }
37
50
  }
38
51
  }
39
52
  // remove empty headings
40
53
  if (!children.length) {
41
54
  siblings.splice(index, 1);
42
- return index;
55
+ after -= 1;
43
56
  }
44
57
  }
45
- return visit.CONTINUE;
58
+ return after;
46
59
  });
47
60
  return tree;
48
61
  }
49
-
50
- module.exports = sanitizeHeading;
@@ -9,8 +9,8 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const visit = require('unist-util-visit');
13
- const find = require('unist-util-find');
12
+ import { visit, CONTINUE } from 'unist-util-visit';
13
+ import find from 'unist-util-find';
14
14
 
15
15
  /**
16
16
  * Sanitizes links:
@@ -19,7 +19,7 @@ const find = require('unist-util-find');
19
19
  * @param {object} tree
20
20
  * @returns {object} The modified (original) tree.
21
21
  */
22
- function sanitizeLinks(tree) {
22
+ export default function sanitizeLinks(tree) {
23
23
  visit(tree, (node, index, parent) => {
24
24
  const { children = [] } = node;
25
25
  if (node.type === 'link' && children.length === 1) {
@@ -61,9 +61,7 @@ function sanitizeLinks(tree) {
61
61
  }
62
62
  }
63
63
  }
64
- return visit.CONTINUE;
64
+ return CONTINUE;
65
65
  });
66
66
  return tree;
67
67
  }
68
-
69
- module.exports = sanitizeLinks;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const visit = require('unist-util-visit');
12
+ import { visit, CONTINUE } from 'unist-util-visit';
13
13
 
14
14
  /**
15
15
  * Sanitizes text:
@@ -22,7 +22,7 @@ const visit = require('unist-util-visit');
22
22
  * @param {object} tree
23
23
  * @returns {object} The modified (original) tree.
24
24
  */
25
- function sanitizeText(tree) {
25
+ export default function sanitizeText(tree) {
26
26
  visit(tree, (node, index, parent) => {
27
27
  const { children: siblings = [] } = parent || {};
28
28
  const { children = [] } = node;
@@ -107,9 +107,7 @@ function sanitizeText(tree) {
107
107
  }
108
108
  }
109
109
  }
110
- return visit.CONTINUE;
110
+ return CONTINUE;
111
111
  });
112
112
  return tree;
113
113
  }
114
-
115
- module.exports = sanitizeText;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const visit = require('unist-util-visit');
12
+ import { visit, CONTINUE } from 'unist-util-visit';
13
13
 
14
14
  /**
15
15
  * Looks for text starting with 4 spaces. As this would render as code in some markdown,
@@ -18,7 +18,7 @@ const visit = require('unist-util-visit');
18
18
  * @param {object} tree
19
19
  * @returns {object} The modified (original) tree.
20
20
  */
21
- function suppressSpaceCode(tree) {
21
+ export default function suppressSpaceCode(tree) {
22
22
  visit(tree, (child, index, parent) => {
23
23
  const { children } = parent || {};
24
24
  if (child.type === 'text'
@@ -27,9 +27,7 @@ function suppressSpaceCode(tree) {
27
27
  // eslint-disable-next-line no-param-reassign
28
28
  child.value = child.value.replace(/^\s+/, ' ');
29
29
  }
30
- return visit.CONTINUE;
30
+ return CONTINUE;
31
31
  });
32
32
  return tree;
33
33
  }
34
-
35
- module.exports = suppressSpaceCode;
@@ -13,7 +13,7 @@
13
13
  /**
14
14
  * Remark extension that handles soft-breaks correctly.
15
15
  */
16
- function softBreak() {
16
+ export default function softBreak() {
17
17
  function handleBreak(node, _, context) {
18
18
  if (context.stack.indexOf('tableCell') !== -1) {
19
19
  return ' ';
@@ -31,5 +31,3 @@ function softBreak() {
31
31
  },
32
32
  });
33
33
  }
34
-
35
- module.exports = softBreak;
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const jsYaml = require('js-yaml');
12
+ import jsYaml from 'js-yaml';
13
13
 
14
14
  function open(token) {
15
15
  this.enter({ type: 'yaml', value: '', payload: {} }, token);
@@ -38,7 +38,7 @@ function value(token) {
38
38
  }
39
39
 
40
40
  // eslint-disable-next-line no-unused-vars
41
- function fromMarkdown(options = {}) {
41
+ export default function fromMarkdown(options = {}) {
42
42
  return {
43
43
  enter: {
44
44
  yaml: open,
@@ -49,5 +49,3 @@ function fromMarkdown(options = {}) {
49
49
  },
50
50
  };
51
51
  }
52
-
53
- module.exports = fromMarkdown;
@@ -9,9 +9,9 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const fromMarkdown = require('./from-markdown.js');
13
- const toMarkdown = require('./to-markdown.js');
14
- const syntax = require('./syntax.js');
12
+ import fromMarkdown from './from-markdown.js';
13
+ import toMarkdown from './to-markdown.js';
14
+ import syntax from './syntax.js';
15
15
 
16
16
  /**
17
17
  * Front- and mid-matter remark plugin.
@@ -83,11 +83,11 @@ const syntax = require('./syntax.js');
83
83
  * @param {object} options Plugin options
84
84
  * @param {Function} options.errorHandler Function that is invoked on yaml parsing errors.
85
85
  */
86
- function matterPlugin(options) {
86
+ export default function matterPlugin(options) {
87
87
  const data = this.data();
88
88
 
89
89
  function add(field, value) {
90
- /* istanbul ignore next */
90
+ /* c8 ignore next 2 */
91
91
  if (data[field]) {
92
92
  data[field].push(value);
93
93
  } else {
@@ -99,5 +99,3 @@ function matterPlugin(options) {
99
99
  add('fromMarkdownExtensions', fromMarkdown(options));
100
100
  add('toMarkdownExtensions', toMarkdown(options));
101
101
  }
102
-
103
- module.exports = matterPlugin;
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  /* eslint-disable no-use-before-define */
13
- const jsYaml = require('js-yaml');
13
+ import jsYaml from 'js-yaml';
14
14
 
15
15
  const type = (v) => ((v !== undefined && v !== null) ? v.constructor : v);
16
16
 
@@ -33,11 +33,9 @@ function validYaml(str, errorHandler) {
33
33
  if (Array.isArray(payload)) {
34
34
  payloadType = 'Array';
35
35
  }
36
- errorHandler(
37
- 'Found ambiguous frontmatter block: Block contains valid yaml, but '
36
+ errorHandler('Found ambiguous frontmatter block: Block contains valid yaml, but '
38
37
  + `it's data type is "${payloadType}" instead of Object. `
39
- + 'Make sure your yaml blocks contain only key-value pairs at the root level!', str,
40
- );
38
+ + 'Make sure your yaml blocks contain only key-value pairs at the root level!', str);
41
39
  }
42
40
  return false;
43
41
  }
@@ -265,12 +263,10 @@ function parse(options) {
265
263
  }
266
264
  }
267
265
 
268
- function create(options = {}) {
266
+ export default function create(options = {}) {
269
267
  return {
270
268
  flow: {
271
269
  [CODE_DASH]: [parse(options)],
272
270
  },
273
271
  };
274
272
  }
275
-
276
- module.exports = create;
@@ -9,12 +9,10 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- function toMarkdown() {
12
+ export default function toMarkdown() {
13
13
  return {
14
14
  handlers: {
15
15
  yaml: (node) => `---\n${node.value.trim()}\n---`,
16
16
  },
17
17
  };
18
18
  }
19
-
20
- module.exports = toMarkdown;
package/docs/API.md DELETED
@@ -1,12 +0,0 @@
1
- <a name="main"></a>
2
-
3
- ## main(name) ⇒ <code>string</code>
4
- This is the main function
5
-
6
- **Kind**: global function
7
- **Returns**: <code>string</code> - a greeting
8
-
9
- | Param | Type | Default | Description |
10
- | --- | --- | --- | --- |
11
- | name | <code>string</code> | <code>&quot;world&quot;</code> | name of the person to greet |
12
-