This commit is contained in:
138
node_modules/micromark-extension-gfm-table/html.js
generated
vendored
Normal file
138
node_modules/micromark-extension-gfm-table/html.js
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
var alignment = {
|
||||
null: '',
|
||||
left: ' align="left"',
|
||||
right: ' align="right"',
|
||||
center: ' align="center"'
|
||||
}
|
||||
|
||||
exports.enter = {
|
||||
table: enterTable,
|
||||
tableBody: enterBody,
|
||||
tableData: enterTableData,
|
||||
tableHead: enterHead,
|
||||
tableHeader: enterTableHeader,
|
||||
tableRow: enterRow
|
||||
}
|
||||
exports.exit = {
|
||||
codeTextData: exitCodeTextData,
|
||||
table: exitTable,
|
||||
tableBody: exitBody,
|
||||
tableData: exitTableData,
|
||||
tableHead: exitHead,
|
||||
tableHeader: exitTableHeader,
|
||||
tableRow: exitRow
|
||||
}
|
||||
|
||||
function enterTable(token) {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('<table>')
|
||||
this.setData('tableAlign', token._align)
|
||||
}
|
||||
|
||||
function exitTable() {
|
||||
this.setData('tableAlign')
|
||||
// If there was no table body, make sure the slurping from the delimiter row
|
||||
// is cleared.
|
||||
this.setData('slurpAllLineEndings')
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('</table>')
|
||||
}
|
||||
|
||||
function enterHead() {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('<thead>')
|
||||
}
|
||||
|
||||
function exitHead() {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('</thead>')
|
||||
this.setData('slurpOneLineEnding', true)
|
||||
// Slurp the line ending from the delimiter row.
|
||||
}
|
||||
|
||||
function enterBody() {
|
||||
// Clear slurping line ending from the delimiter row.
|
||||
this.setData('slurpOneLineEnding')
|
||||
this.tag('<tbody>')
|
||||
}
|
||||
|
||||
function exitBody() {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('</tbody>')
|
||||
}
|
||||
|
||||
function enterRow() {
|
||||
this.setData('tableColumn', 0)
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('<tr>')
|
||||
}
|
||||
|
||||
function exitRow() {
|
||||
var align = this.getData('tableAlign')
|
||||
var column = this.getData('tableColumn')
|
||||
|
||||
while (column < align.length) {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('<td' + alignment[align[column]] + '></td>')
|
||||
column++
|
||||
}
|
||||
|
||||
this.setData('tableColumn', column)
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('</tr>')
|
||||
}
|
||||
|
||||
function enterTableHeader() {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag(
|
||||
'<th' +
|
||||
alignment[this.getData('tableAlign')[this.getData('tableColumn')]] +
|
||||
'>'
|
||||
)
|
||||
}
|
||||
|
||||
function exitTableHeader() {
|
||||
this.tag('</th>')
|
||||
this.setData('tableColumn', this.getData('tableColumn') + 1)
|
||||
}
|
||||
|
||||
function enterTableData() {
|
||||
var align = alignment[this.getData('tableAlign')[this.getData('tableColumn')]]
|
||||
|
||||
if (align === undefined) {
|
||||
// Capture results to ignore them.
|
||||
this.buffer()
|
||||
} else {
|
||||
this.lineEndingIfNeeded()
|
||||
this.tag('<td' + align + '>')
|
||||
}
|
||||
}
|
||||
|
||||
function exitTableData() {
|
||||
var column = this.getData('tableColumn')
|
||||
|
||||
if (column in this.getData('tableAlign')) {
|
||||
this.tag('</td>')
|
||||
this.setData('tableColumn', column + 1)
|
||||
} else {
|
||||
// Stop capturing.
|
||||
this.resume()
|
||||
}
|
||||
}
|
||||
|
||||
// Overwrite the default code text data handler to unescape escaped pipes when
|
||||
// they are in tables.
|
||||
function exitCodeTextData(token) {
|
||||
var value = this.sliceSerialize(token)
|
||||
|
||||
if (this.getData('tableAlign')) {
|
||||
value = value.replace(/\\([\\|])/g, replace)
|
||||
}
|
||||
|
||||
this.raw(this.encode(value))
|
||||
}
|
||||
|
||||
function replace($0, $1) {
|
||||
// Pipes work, backslashes don’t (but can’t escape pipes).
|
||||
return $1 === '|' ? $1 : $0
|
||||
}
|
||||
1
node_modules/micromark-extension-gfm-table/index.js
generated
vendored
Normal file
1
node_modules/micromark-extension-gfm-table/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('./syntax')
|
||||
22
node_modules/micromark-extension-gfm-table/license
generated
vendored
Normal file
22
node_modules/micromark-extension-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.
|
||||
76
node_modules/micromark-extension-gfm-table/package.json
generated
vendored
Normal file
76
node_modules/micromark-extension-gfm-table/package.json
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "micromark-extension-gfm-table",
|
||||
"version": "0.4.3",
|
||||
"description": "micromark extension to support GFM tables",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"micromark",
|
||||
"micromark-extension",
|
||||
"table",
|
||||
"row",
|
||||
"column",
|
||||
"cell",
|
||||
"tabular",
|
||||
"gfm",
|
||||
"markdown",
|
||||
"unified"
|
||||
],
|
||||
"repository": "micromark/micromark-extension-gfm-table",
|
||||
"bugs": "https://github.com/micromark/micromark-extension-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": [
|
||||
"index.js",
|
||||
"html.js",
|
||||
"syntax.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"micromark": "~2.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"xo": "^0.38.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test/index.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": {
|
||||
"complexity": "off"
|
||||
}
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
119
node_modules/micromark-extension-gfm-table/readme.md
generated
vendored
Normal file
119
node_modules/micromark-extension-gfm-table/readme.md
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
# micromark-extension-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]
|
||||
|
||||
**[micromark][]** extension to support GitHub flavored markdown [tables][].
|
||||
This syntax extension matches the GFM spec and github.com.
|
||||
|
||||
This package provides the low-level modules for integrating with the micromark
|
||||
tokenizer and the micromark HTML compiler.
|
||||
|
||||
You probably should use this package with
|
||||
[`mdast-util-gfm-table`][mdast-util-gfm-table].
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install micromark-extension-gfm-table
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `html`
|
||||
|
||||
### `syntax`
|
||||
|
||||
> Note: `syntax` is the default export of this module, `html` is available at
|
||||
> `micromark-extension-gfm-table/html`.
|
||||
|
||||
Support [tables][].
|
||||
The exports are extensions for the micromark parser (to tokenize tables; can be
|
||||
passed in `extensions`) and the default HTML compiler (to compile as `<table>`
|
||||
elements; can be passed in `htmlExtensions`).
|
||||
|
||||
## Related
|
||||
|
||||
* [`remarkjs/remark`][remark]
|
||||
— markdown processor powered by plugins
|
||||
* [`micromark/micromark`][micromark]
|
||||
— the smallest commonmark-compliant markdown parser that exists
|
||||
* [`syntax-tree/mdast-util-gfm-table`](https://github.com/syntax-tree/mdast-util-gfm-table)
|
||||
— mdast utility to support 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 `micromark/.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/micromark/micromark-extension-gfm-table/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/micromark/micromark-extension-gfm-table/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-table.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-table
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-table.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-table
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-extension-gfm-table.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=micromark-extension-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/micromark/micromark/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[micromark]: https://github.com/micromark/micromark
|
||||
|
||||
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
|
||||
|
||||
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
|
||||
|
||||
[remark]: https://github.com/remarkjs/remark
|
||||
|
||||
[mdast-util-gfm-table]: https://github.com/syntax-tree/mdast-util-gfm-table
|
||||
|
||||
[tables]: https://github.github.com/gfm/#tables-extension-
|
||||
576
node_modules/micromark-extension-gfm-table/syntax.js
generated
vendored
Normal file
576
node_modules/micromark-extension-gfm-table/syntax.js
generated
vendored
Normal file
@@ -0,0 +1,576 @@
|
||||
exports.flow = {
|
||||
null: {tokenize: tokenizeTable, resolve: resolveTable, interruptible: true}
|
||||
}
|
||||
|
||||
var createSpace = require('micromark/dist/tokenize/factory-space')
|
||||
|
||||
var setextUnderlineMini = {tokenize: tokenizeSetextUnderlineMini, partial: true}
|
||||
var nextPrefixedOrBlank = {tokenize: tokenizeNextPrefixedOrBlank, partial: true}
|
||||
|
||||
function resolveTable(events, context) {
|
||||
var length = events.length
|
||||
var index = -1
|
||||
var token
|
||||
var inHead
|
||||
var inDelimiterRow
|
||||
var inRow
|
||||
var cell
|
||||
var content
|
||||
var text
|
||||
var contentStart
|
||||
var contentEnd
|
||||
var cellStart
|
||||
|
||||
while (++index < length) {
|
||||
token = events[index][1]
|
||||
|
||||
if (inRow) {
|
||||
if (token.type === 'temporaryTableCellContent') {
|
||||
contentStart = contentStart || index
|
||||
contentEnd = index
|
||||
}
|
||||
|
||||
if (
|
||||
// Combine separate content parts into one.
|
||||
(token.type === 'tableCellDivider' || token.type === 'tableRow') &&
|
||||
contentEnd
|
||||
) {
|
||||
content = {
|
||||
type: 'tableContent',
|
||||
start: events[contentStart][1].start,
|
||||
end: events[contentEnd][1].end
|
||||
}
|
||||
text = {
|
||||
type: 'chunkText',
|
||||
start: content.start,
|
||||
end: content.end,
|
||||
contentType: 'text'
|
||||
}
|
||||
|
||||
events.splice(
|
||||
contentStart,
|
||||
contentEnd - contentStart + 1,
|
||||
['enter', content, context],
|
||||
['enter', text, context],
|
||||
['exit', text, context],
|
||||
['exit', content, context]
|
||||
)
|
||||
index -= contentEnd - contentStart - 3
|
||||
length = events.length
|
||||
contentStart = undefined
|
||||
contentEnd = undefined
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
events[index][0] === 'exit' &&
|
||||
cellStart &&
|
||||
cellStart + 1 < index &&
|
||||
(token.type === 'tableCellDivider' ||
|
||||
(token.type === 'tableRow' &&
|
||||
(cellStart + 3 < index ||
|
||||
events[cellStart][1].type !== 'whitespace')))
|
||||
) {
|
||||
cell = {
|
||||
type: inDelimiterRow
|
||||
? 'tableDelimiter'
|
||||
: inHead
|
||||
? 'tableHeader'
|
||||
: 'tableData',
|
||||
start: events[cellStart][1].start,
|
||||
end: events[index][1].end
|
||||
}
|
||||
events.splice(index + (token.type === 'tableCellDivider' ? 1 : 0), 0, [
|
||||
'exit',
|
||||
cell,
|
||||
context
|
||||
])
|
||||
events.splice(cellStart, 0, ['enter', cell, context])
|
||||
index += 2
|
||||
length = events.length
|
||||
cellStart = index + 1
|
||||
}
|
||||
|
||||
if (token.type === 'tableRow') {
|
||||
inRow = events[index][0] === 'enter'
|
||||
|
||||
if (inRow) {
|
||||
cellStart = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
if (token.type === 'tableDelimiterRow') {
|
||||
inDelimiterRow = events[index][0] === 'enter'
|
||||
|
||||
if (inDelimiterRow) {
|
||||
cellStart = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
if (token.type === 'tableHead') {
|
||||
inHead = events[index][0] === 'enter'
|
||||
}
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
function tokenizeTable(effects, ok, nok) {
|
||||
var align = []
|
||||
var tableHeaderCount = 0
|
||||
var seenDelimiter
|
||||
var hasDash
|
||||
|
||||
return start
|
||||
|
||||
function start(code) {
|
||||
/* istanbul ignore if - used to be passed in beta micromark versions. */
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.enter('table')._align = align
|
||||
effects.enter('tableHead')
|
||||
effects.enter('tableRow')
|
||||
|
||||
// If we start with a pipe, we open a cell marker.
|
||||
if (code === 124) {
|
||||
return cellDividerHead(code)
|
||||
}
|
||||
|
||||
tableHeaderCount++
|
||||
effects.enter('temporaryTableCellContent')
|
||||
// Can’t be space or eols at the start of a construct, so we’re in a cell.
|
||||
return inCellContentHead(code)
|
||||
}
|
||||
|
||||
function cellDividerHead(code) {
|
||||
// Always a pipe.
|
||||
effects.enter('tableCellDivider')
|
||||
effects.consume(code)
|
||||
effects.exit('tableCellDivider')
|
||||
seenDelimiter = true
|
||||
return cellBreakHead
|
||||
}
|
||||
|
||||
function cellBreakHead(code) {
|
||||
// EOF, CR, LF, CRLF.
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return atRowEndHead(code)
|
||||
}
|
||||
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.enter('whitespace')
|
||||
effects.consume(code)
|
||||
return inWhitespaceHead
|
||||
}
|
||||
|
||||
if (seenDelimiter) {
|
||||
seenDelimiter = undefined
|
||||
tableHeaderCount++
|
||||
}
|
||||
|
||||
// `|`
|
||||
if (code === 124) {
|
||||
return cellDividerHead(code)
|
||||
}
|
||||
|
||||
// Anything else is cell content.
|
||||
effects.enter('temporaryTableCellContent')
|
||||
return inCellContentHead(code)
|
||||
}
|
||||
|
||||
function inWhitespaceHead(code) {
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.consume(code)
|
||||
return inWhitespaceHead
|
||||
}
|
||||
|
||||
effects.exit('whitespace')
|
||||
return cellBreakHead(code)
|
||||
}
|
||||
|
||||
function inCellContentHead(code) {
|
||||
// EOF, whitespace, pipe
|
||||
if (code === null || code < 0 || code === 32 || code === 124) {
|
||||
effects.exit('temporaryTableCellContent')
|
||||
return cellBreakHead(code)
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
// `\`
|
||||
return code === 92 ? inCellContentEscapeHead : inCellContentHead
|
||||
}
|
||||
|
||||
function inCellContentEscapeHead(code) {
|
||||
// `\` or `|`
|
||||
if (code === 92 || code === 124) {
|
||||
effects.consume(code)
|
||||
return inCellContentHead
|
||||
}
|
||||
|
||||
// Anything else.
|
||||
return inCellContentHead(code)
|
||||
}
|
||||
|
||||
function atRowEndHead(code) {
|
||||
if (code === null) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.exit('tableRow')
|
||||
effects.exit('tableHead')
|
||||
|
||||
// Always a line ending.
|
||||
effects.enter('lineEnding')
|
||||
effects.consume(code)
|
||||
effects.exit('lineEnding')
|
||||
|
||||
// If a setext heading, exit.
|
||||
return effects.check(
|
||||
setextUnderlineMini,
|
||||
nok,
|
||||
// Support an indent before the delimiter row.
|
||||
createSpace(effects, rowStartDelimiter, 'linePrefix', 4)
|
||||
)
|
||||
}
|
||||
|
||||
function rowStartDelimiter(code) {
|
||||
// If there’s another space, or we’re at the EOL/EOF, exit.
|
||||
if (code === null || code < 0 || code === 32) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.enter('tableDelimiterRow')
|
||||
return atDelimiterRowBreak(code)
|
||||
}
|
||||
|
||||
function atDelimiterRowBreak(code) {
|
||||
// EOF, CR, LF, CRLF.
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return rowEndDelimiter(code)
|
||||
}
|
||||
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.enter('whitespace')
|
||||
effects.consume(code)
|
||||
return inWhitespaceDelimiter
|
||||
}
|
||||
|
||||
// `-`
|
||||
if (code === 45) {
|
||||
effects.enter('tableDelimiterFiller')
|
||||
effects.consume(code)
|
||||
hasDash = true
|
||||
align.push(null)
|
||||
return inFillerDelimiter
|
||||
}
|
||||
|
||||
// `:`
|
||||
if (code === 58) {
|
||||
effects.enter('tableDelimiterAlignment')
|
||||
effects.consume(code)
|
||||
effects.exit('tableDelimiterAlignment')
|
||||
align.push('left')
|
||||
return afterLeftAlignment
|
||||
}
|
||||
|
||||
// If we start with a pipe, we open a cell marker.
|
||||
if (code === 124) {
|
||||
effects.enter('tableCellDivider')
|
||||
effects.consume(code)
|
||||
effects.exit('tableCellDivider')
|
||||
return atDelimiterRowBreak
|
||||
}
|
||||
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
function inWhitespaceDelimiter(code) {
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.consume(code)
|
||||
return inWhitespaceDelimiter
|
||||
}
|
||||
|
||||
effects.exit('whitespace')
|
||||
return atDelimiterRowBreak(code)
|
||||
}
|
||||
|
||||
function inFillerDelimiter(code) {
|
||||
// `-`
|
||||
if (code === 45) {
|
||||
effects.consume(code)
|
||||
return inFillerDelimiter
|
||||
}
|
||||
|
||||
effects.exit('tableDelimiterFiller')
|
||||
|
||||
// `:`
|
||||
if (code === 58) {
|
||||
effects.enter('tableDelimiterAlignment')
|
||||
effects.consume(code)
|
||||
effects.exit('tableDelimiterAlignment')
|
||||
|
||||
align[align.length - 1] =
|
||||
align[align.length - 1] === 'left' ? 'center' : 'right'
|
||||
|
||||
return afterRightAlignment
|
||||
}
|
||||
|
||||
return atDelimiterRowBreak(code)
|
||||
}
|
||||
|
||||
function afterLeftAlignment(code) {
|
||||
// `-`
|
||||
if (code === 45) {
|
||||
effects.enter('tableDelimiterFiller')
|
||||
effects.consume(code)
|
||||
hasDash = true
|
||||
return inFillerDelimiter
|
||||
}
|
||||
|
||||
// Anything else is not ok.
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
function afterRightAlignment(code) {
|
||||
// EOF, CR, LF, CRLF.
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return rowEndDelimiter(code)
|
||||
}
|
||||
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.enter('whitespace')
|
||||
effects.consume(code)
|
||||
return inWhitespaceDelimiter
|
||||
}
|
||||
|
||||
// `|`
|
||||
if (code === 124) {
|
||||
effects.enter('tableCellDivider')
|
||||
effects.consume(code)
|
||||
effects.exit('tableCellDivider')
|
||||
return atDelimiterRowBreak
|
||||
}
|
||||
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
function rowEndDelimiter(code) {
|
||||
effects.exit('tableDelimiterRow')
|
||||
|
||||
// Exit if there was no dash at all, or if the header cell count is not the
|
||||
// delimiter cell count.
|
||||
if (!hasDash || tableHeaderCount !== align.length) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (code === null) {
|
||||
return tableClose(code)
|
||||
}
|
||||
|
||||
return effects.check(nextPrefixedOrBlank, tableClose, tableContinue)(code)
|
||||
}
|
||||
|
||||
function tableClose(code) {
|
||||
effects.exit('table')
|
||||
return ok(code)
|
||||
}
|
||||
|
||||
function tableContinue(code) {
|
||||
// Always a line ending.
|
||||
effects.enter('lineEnding')
|
||||
effects.consume(code)
|
||||
effects.exit('lineEnding')
|
||||
// We checked that it’s not a prefixed or blank line, so we’re certain a
|
||||
// body is coming, though it may be indented.
|
||||
return createSpace(effects, bodyStart, 'linePrefix', 4)
|
||||
}
|
||||
|
||||
function bodyStart(code) {
|
||||
effects.enter('tableBody')
|
||||
return rowStartBody(code)
|
||||
}
|
||||
|
||||
function rowStartBody(code) {
|
||||
effects.enter('tableRow')
|
||||
|
||||
// If we start with a pipe, we open a cell marker.
|
||||
if (code === 124) {
|
||||
return cellDividerBody(code)
|
||||
}
|
||||
|
||||
effects.enter('temporaryTableCellContent')
|
||||
// Can’t be space or eols at the start of a construct, so we’re in a cell.
|
||||
return inCellContentBody(code)
|
||||
}
|
||||
|
||||
function cellDividerBody(code) {
|
||||
// Always a pipe.
|
||||
effects.enter('tableCellDivider')
|
||||
effects.consume(code)
|
||||
effects.exit('tableCellDivider')
|
||||
return cellBreakBody
|
||||
}
|
||||
|
||||
function cellBreakBody(code) {
|
||||
// EOF, CR, LF, CRLF.
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return atRowEndBody(code)
|
||||
}
|
||||
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.enter('whitespace')
|
||||
effects.consume(code)
|
||||
return inWhitespaceBody
|
||||
}
|
||||
|
||||
// `|`
|
||||
if (code === 124) {
|
||||
return cellDividerBody(code)
|
||||
}
|
||||
|
||||
// Anything else is cell content.
|
||||
effects.enter('temporaryTableCellContent')
|
||||
return inCellContentBody(code)
|
||||
}
|
||||
|
||||
function inWhitespaceBody(code) {
|
||||
// HT, VS, SP.
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.consume(code)
|
||||
return inWhitespaceBody
|
||||
}
|
||||
|
||||
effects.exit('whitespace')
|
||||
return cellBreakBody(code)
|
||||
}
|
||||
|
||||
function inCellContentBody(code) {
|
||||
// EOF, whitespace, pipe
|
||||
if (code === null || code < 0 || code === 32 || code === 124) {
|
||||
effects.exit('temporaryTableCellContent')
|
||||
return cellBreakBody(code)
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
// `\`
|
||||
return code === 92 ? inCellContentEscapeBody : inCellContentBody
|
||||
}
|
||||
|
||||
function inCellContentEscapeBody(code) {
|
||||
// `\` or `|`
|
||||
if (code === 92 || code === 124) {
|
||||
effects.consume(code)
|
||||
return inCellContentBody
|
||||
}
|
||||
|
||||
// Anything else.
|
||||
return inCellContentBody(code)
|
||||
}
|
||||
|
||||
function atRowEndBody(code) {
|
||||
effects.exit('tableRow')
|
||||
|
||||
if (code === null) {
|
||||
return tableBodyClose(code)
|
||||
}
|
||||
|
||||
return effects.check(
|
||||
nextPrefixedOrBlank,
|
||||
tableBodyClose,
|
||||
tableBodyContinue
|
||||
)(code)
|
||||
}
|
||||
|
||||
function tableBodyClose(code) {
|
||||
effects.exit('tableBody')
|
||||
return tableClose(code)
|
||||
}
|
||||
|
||||
function tableBodyContinue(code) {
|
||||
// Always a line ending.
|
||||
effects.enter('lineEnding')
|
||||
effects.consume(code)
|
||||
effects.exit('lineEnding')
|
||||
// Support an optional prefix, then start a body row.
|
||||
return createSpace(effects, rowStartBody, 'linePrefix', 4)
|
||||
}
|
||||
}
|
||||
|
||||
// Based on micromark, but that won’t work as we’re in a table, and that expects
|
||||
// content.
|
||||
// <https://github.com/micromark/micromark/blob/main/lib/tokenize/setext-underline.js>
|
||||
function tokenizeSetextUnderlineMini(effects, ok, nok) {
|
||||
return start
|
||||
|
||||
function start(code) {
|
||||
// `-`
|
||||
if (code !== 45) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.enter('setextUnderline')
|
||||
return sequence(code)
|
||||
}
|
||||
|
||||
function sequence(code) {
|
||||
if (code === 45) {
|
||||
effects.consume(code)
|
||||
return sequence
|
||||
}
|
||||
|
||||
return whitespace(code)
|
||||
}
|
||||
|
||||
function whitespace(code) {
|
||||
if (code === -2 || code === -1 || code === 32) {
|
||||
effects.consume(code)
|
||||
return whitespace
|
||||
}
|
||||
|
||||
if (code === null || code === -5 || code === -4 || code === -3) {
|
||||
return ok(code)
|
||||
}
|
||||
|
||||
return nok(code)
|
||||
}
|
||||
}
|
||||
|
||||
function tokenizeNextPrefixedOrBlank(effects, ok, nok) {
|
||||
var size = 0
|
||||
|
||||
return start
|
||||
|
||||
function start(code) {
|
||||
// This is a check, so we don’t care about tokens, but we open a bogus one
|
||||
// so we’re valid.
|
||||
effects.enter('check')
|
||||
// EOL.
|
||||
effects.consume(code)
|
||||
return whitespace
|
||||
}
|
||||
|
||||
function whitespace(code) {
|
||||
// VS or SP.
|
||||
if (code === -1 || code === 32) {
|
||||
effects.consume(code)
|
||||
size++
|
||||
return size === 4 ? ok : whitespace
|
||||
}
|
||||
|
||||
// EOF or whitespace
|
||||
if (code === null || code < 0) {
|
||||
return ok(code)
|
||||
}
|
||||
|
||||
// Anything else.
|
||||
return nok(code)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user