This commit is contained in:
53
node_modules/mdast-util-gfm-table/from-markdown.js
generated
vendored
Normal file
53
node_modules/mdast-util-gfm-table/from-markdown.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
exports.enter = {
|
||||
table: enterTable,
|
||||
tableData: enterCell,
|
||||
tableHeader: enterCell,
|
||||
tableRow: enterRow
|
||||
}
|
||||
exports.exit = {
|
||||
codeText: exitCodeText,
|
||||
table: exitTable,
|
||||
tableData: exit,
|
||||
tableHeader: exit,
|
||||
tableRow: exit
|
||||
}
|
||||
|
||||
function enterTable(token) {
|
||||
this.enter({type: 'table', align: token._align, children: []}, token)
|
||||
this.setData('inTable', true)
|
||||
}
|
||||
|
||||
function exitTable(token) {
|
||||
this.exit(token)
|
||||
this.setData('inTable')
|
||||
}
|
||||
|
||||
function enterRow(token) {
|
||||
this.enter({type: 'tableRow', children: []}, token)
|
||||
}
|
||||
|
||||
function exit(token) {
|
||||
this.exit(token)
|
||||
}
|
||||
|
||||
function enterCell(token) {
|
||||
this.enter({type: 'tableCell', children: []}, token)
|
||||
}
|
||||
|
||||
// Overwrite the default code text data handler to unescape escaped pipes when
|
||||
// they are in tables.
|
||||
function exitCodeText(token) {
|
||||
var value = this.resume()
|
||||
|
||||
if (this.getData('inTable')) {
|
||||
value = value.replace(/\\([\\|])/g, replace)
|
||||
}
|
||||
|
||||
this.stack[this.stack.length - 1].value = value
|
||||
this.exit(token)
|
||||
}
|
||||
|
||||
function replace($0, $1) {
|
||||
// Pipes work, backslashes don’t (but can’t escape pipes).
|
||||
return $1 === '|' ? $1 : $0
|
||||
}
|
||||
2
node_modules/mdast-util-gfm-table/index.js
generated
vendored
Normal file
2
node_modules/mdast-util-gfm-table/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
exports.fromMarkdown = require('./from-markdown')
|
||||
exports.toMarkdown = require('./to-markdown')
|
||||
22
node_modules/mdast-util-gfm-table/license
generated
vendored
Normal file
22
node_modules/mdast-util-gfm-table/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
84
node_modules/mdast-util-gfm-table/package.json
generated
vendored
Normal file
84
node_modules/mdast-util-gfm-table/package.json
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"name": "mdast-util-gfm-table",
|
||||
"version": "0.1.6",
|
||||
"description": "mdast extension to parse and serialize GFM tables",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"markup",
|
||||
"table",
|
||||
"row",
|
||||
"column",
|
||||
"cell",
|
||||
"tabular",
|
||||
"gfm"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-gfm-table",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-gfm-table/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"from-markdown.js",
|
||||
"index.js",
|
||||
"to-markdown.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"markdown-table": "^2.0.0",
|
||||
"mdast-util-to-markdown": "~0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mdast-util-from-markdown": "^0.8.0",
|
||||
"micromark-extension-gfm-table": "^0.4.0",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"string-width": "^4.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"unist-util-remove-position": "^3.0.0",
|
||||
"xo": "^0.37.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test": "npm run format && npm run test-coverage"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"unicorn/prefer-includes": "off"
|
||||
}
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
231
node_modules/mdast-util-gfm-table/readme.md
generated
vendored
Normal file
231
node_modules/mdast-util-gfm-table/readme.md
generated
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
# mdast-util-gfm-table
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
Extension for [`mdast-util-from-markdown`][from-markdown] and/or
|
||||
[`mdast-util-to-markdown`][to-markdown] to support GitHub flavored markdown
|
||||
tables in **[mdast][]**.
|
||||
When parsing (`from-markdown`), must be combined with
|
||||
[`micromark-extension-gfm-table`][extension].
|
||||
|
||||
You probably shouldn’t use this package directly, but instead use
|
||||
[`remark-gfm`][remark-gfm] with **[remark][]**.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install mdast-util-gfm-table
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
Say we have the following file, `example.md`:
|
||||
|
||||
```markdown
|
||||
| a | b | c | d |
|
||||
| - | :- | -: | :-: |
|
||||
| e | f |
|
||||
| g | h | i | j | k |
|
||||
```
|
||||
|
||||
And our script, `example.js`, looks as follows:
|
||||
|
||||
```js
|
||||
var fs = require('fs')
|
||||
var fromMarkdown = require('mdast-util-from-markdown')
|
||||
var toMarkdown = require('mdast-util-to-markdown')
|
||||
var syntax = require('micromark-extension-gfm-table')
|
||||
var table = require('mdast-util-gfm-table')
|
||||
|
||||
var doc = fs.readFileSync('example.md')
|
||||
|
||||
var tree = fromMarkdown(doc, {
|
||||
extensions: [syntax],
|
||||
mdastExtensions: [table.fromMarkdown]
|
||||
})
|
||||
|
||||
console.log(tree)
|
||||
|
||||
var out = toMarkdown(tree, {extensions: [table.toMarkdown()]})
|
||||
|
||||
console.log(out)
|
||||
```
|
||||
|
||||
Now, running `node example` yields (positional info removed for the sake of
|
||||
brevity):
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'root',
|
||||
children: [
|
||||
{
|
||||
type: 'table',
|
||||
align: [null, 'left', 'right', 'center'],
|
||||
children: [
|
||||
{
|
||||
type: 'tableRow',
|
||||
children: [
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'a'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'b'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'c'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'd'}]}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'tableRow',
|
||||
children: [
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'e'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'f'}]}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'tableRow',
|
||||
children: [
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'g'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'h'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'i'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'j'}]},
|
||||
{type: 'tableCell', children: [{type: 'text', value: 'k'}]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```markdown
|
||||
| a | b | c | d | |
|
||||
| - | :- | -: | :-: | - |
|
||||
| e | f | | | |
|
||||
| g | h | i | j | k |
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `table.fromMarkdown`
|
||||
|
||||
### `table.toMarkdown(options?)`
|
||||
|
||||
> Note: the separate extensions are also available at
|
||||
> `mdast-util-gfm-table/from-markdown` and
|
||||
> `mdast-util-gfm-table/to-markdown`.
|
||||
|
||||
Support tables.
|
||||
The exports of `fromMarkdown` is an extension for
|
||||
[`mdast-util-from-markdown`][from-markdown].
|
||||
The export of `toMarkdown` is a function that can be called with options and
|
||||
returns an extension for [`mdast-util-to-markdown`][to-markdown].
|
||||
|
||||
##### `options`
|
||||
|
||||
###### `options.tableCellPadding`
|
||||
|
||||
Create tables with a space between cell delimiters (`|`) and content (`boolean`,
|
||||
default: `true`).
|
||||
|
||||
###### `options.tablePipeAlign`
|
||||
|
||||
Align the delimiters (`|`) between table cells so that they all align nicely and
|
||||
form a grid (`boolean`, default: `true`).
|
||||
|
||||
###### `options.stringLength`
|
||||
|
||||
Function passed to [`markdown-table`][markdown-table] to detect the length of a
|
||||
table cell (`Function`, default: [`s => s.length`][string-length]).
|
||||
Used to pad tables.
|
||||
|
||||
## Related
|
||||
|
||||
* [`remarkjs/remark`][remark]
|
||||
— markdown processor powered by plugins
|
||||
* [`remarkjs/remark-gfm`][remark-gfm]
|
||||
— remark plugin to support GFM
|
||||
* [`micromark/micromark`][micromark]
|
||||
— the smallest commonmark-compliant markdown parser that exists
|
||||
* [`micromark/micromark-extension-gfm-table`][extension]
|
||||
— micromark extension to parse GFM tables
|
||||
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
|
||||
— mdast parser using `micromark` to create mdast from markdown
|
||||
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
|
||||
— mdast serializer to create markdown from mdast
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-table/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-gfm-table/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-table.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-table
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-table.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-gfm-table
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-table.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-table
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[mdast]: https://github.com/syntax-tree/mdast
|
||||
|
||||
[remark]: https://github.com/remarkjs/remark
|
||||
|
||||
[remark-gfm]: https://github.com/remarkjs/remark-gfm
|
||||
|
||||
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
|
||||
|
||||
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
|
||||
|
||||
[micromark]: https://github.com/micromark/micromark
|
||||
|
||||
[extension]: https://github.com/micromark/micromark-extension-gfm-table
|
||||
|
||||
[markdown-table]: https://github.com/wooorm/markdown-table
|
||||
|
||||
[string-length]: https://github.com/wooorm/markdown-table#optionsstringlength
|
||||
112
node_modules/mdast-util-gfm-table/to-markdown.js
generated
vendored
Normal file
112
node_modules/mdast-util-gfm-table/to-markdown.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
var phrasing = require('mdast-util-to-markdown/lib/util/container-phrasing')
|
||||
var defaultInlineCode = require('mdast-util-to-markdown/lib/handle/inline-code')
|
||||
var markdownTable = require('markdown-table')
|
||||
|
||||
module.exports = toMarkdown
|
||||
|
||||
function toMarkdown(options) {
|
||||
var settings = options || {}
|
||||
var padding = settings.tableCellPadding
|
||||
var alignDelimiters = settings.tablePipeAlign
|
||||
var stringLength = settings.stringLength
|
||||
var around = padding ? ' ' : '|'
|
||||
|
||||
return {
|
||||
unsafe: [
|
||||
{character: '\r', inConstruct: 'tableCell'},
|
||||
{character: '\n', inConstruct: 'tableCell'},
|
||||
// A pipe, when followed by a tab or space (padding), or a dash or colon
|
||||
// (unpadded delimiter row), could result in a table.
|
||||
{atBreak: true, character: '|', after: '[\t :-]'},
|
||||
// A pipe in a cell must be encoded.
|
||||
{character: '|', inConstruct: 'tableCell'},
|
||||
// A colon must be followed by a dash, in which case it could start a
|
||||
// delimiter row.
|
||||
{atBreak: true, character: ':', after: '-'},
|
||||
// A delimiter row can also start with a dash, when followed by more
|
||||
// dashes, a colon, or a pipe.
|
||||
// This is a stricter version than the built in check for lists, thematic
|
||||
// breaks, and setex heading underlines though:
|
||||
// <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
|
||||
{atBreak: true, character: '-', after: '[:|-]'}
|
||||
],
|
||||
handlers: {
|
||||
table: handleTable,
|
||||
tableRow: handleTableRow,
|
||||
tableCell: handleTableCell,
|
||||
inlineCode: inlineCodeWithTable
|
||||
}
|
||||
}
|
||||
|
||||
function handleTable(node, _, context) {
|
||||
return serializeData(handleTableAsData(node, context), node.align)
|
||||
}
|
||||
|
||||
// This function isn’t really used normally, because we handle rows at the
|
||||
// table level.
|
||||
// But, if someone passes in a table row, this ensures we make somewhat sense.
|
||||
function handleTableRow(node, _, context) {
|
||||
var row = handleTableRowAsData(node, context)
|
||||
// `markdown-table` will always add an align row
|
||||
var value = serializeData([row])
|
||||
return value.slice(0, value.indexOf('\n'))
|
||||
}
|
||||
|
||||
function handleTableCell(node, _, context) {
|
||||
var exit = context.enter('tableCell')
|
||||
var value = phrasing(node, context, {before: around, after: around})
|
||||
exit()
|
||||
return value
|
||||
}
|
||||
|
||||
function serializeData(matrix, align) {
|
||||
return markdownTable(matrix, {
|
||||
align: align,
|
||||
alignDelimiters: alignDelimiters,
|
||||
padding: padding,
|
||||
stringLength: stringLength
|
||||
})
|
||||
}
|
||||
|
||||
function handleTableAsData(node, context) {
|
||||
var children = node.children
|
||||
var index = -1
|
||||
var length = children.length
|
||||
var result = []
|
||||
var subexit = context.enter('table')
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = handleTableRowAsData(children[index], context)
|
||||
}
|
||||
|
||||
subexit()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function handleTableRowAsData(node, context) {
|
||||
var children = node.children
|
||||
var index = -1
|
||||
var length = children.length
|
||||
var result = []
|
||||
var subexit = context.enter('tableRow')
|
||||
|
||||
while (++index < length) {
|
||||
result[index] = handleTableCell(children[index], node, context)
|
||||
}
|
||||
|
||||
subexit()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function inlineCodeWithTable(node, parent, context) {
|
||||
var value = defaultInlineCode(node, parent, context)
|
||||
|
||||
if (context.stack.indexOf('tableCell') !== -1) {
|
||||
value = value.replace(/\|/g, '\\$&')
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user