This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

9
node_modules/@slorber/remark-comment/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright 2021, Lee Byron
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.

92
node_modules/@slorber/remark-comment/README.md generated vendored Normal file
View File

@@ -0,0 +1,92 @@
# remark-comment
Parse HTML style comments as a different node type so it can be ignored during
serialization.
## Install and usage
```sh
npm install remark-comment
```
```js
import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkComment from 'remark-comment'
unified().use(remarkParse).use(remarkComment)
```
For more help with unified, please see the docs for [unified] and [remark].
This package also exports its [micromark] and [mdast] plugins:
```js
import {
comment,
commentHtml,
commentFromMarkdown,
commentToMarkdown,
} from 'remark-comment'
```
**Options:**
The `remarkComment` and `commentFromMarkdown` functions take the options:
- `ast`: If true, a `{ type: "comment" }` node will be included in the
resulting AST. This is useful if you want to do post-processing and stringify
back to markdown. Default: `false`.
[unified]: https://unifiedjs.com/learn/guide/using-unified/
[remark]: https://unifiedjs.com/explore/package/remark-parse/
[micromark]: https://github.com/micromark/micromark
[mdast]: https://github.com/syntax-tree/mdast#extensions
## Example
```markdown
# This file
<!-- contains a comment -->
And a paragraph
```
Renders to:
```html
<h1>This file</h1>
<p>And a paragraph</p>
```
## Motivation
This package was created after realizing that MDX lacked support for HTML style
comments. When trying to migrate an existing collection of markdown files to
MDX, hitting syntax errors for HTML comments was a non-starter. Rather than go
modify all those files to use a (more awkward) JSX expression comment, I created
this plugin to add back this support.
However, I found this useful when used outside of MDX. Common markdown
interprets an HTML comment as an HTML block, and during serialization will pass
it directly through to the final HTML document. I typically do not want my
markdown comments appearing in my final HTML documents, and this plugin achieves
this effect.
## Caveats
This plugin must be added after MDX, otherwise you will see this error:
```
Unexpected character `!` (U+0021) before name, expected a character that can start a name, such as a letter, `$`, or `_` (note: to create a comment in MDX, use `{/* text */}`)
```
In a unified pipeline:
```js
unified().use(remarkMDX).use(remarkComment)
```
Unlike HTML, comments cannot be used within a JSX body. JSX is still JSX.
HTML comments must appear outside of JSX, use JSX style comments (`{/* comment */}`) inside of JSX.

19
node_modules/@slorber/remark-comment/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,19 @@
export default function remarkComment(
options?: void | Options | undefined
):
| void
| import('unified').Transformer<import('mdast').Root, import('mdast').Root>
export const comment: Extension
export const commentHtml: HtmlExtension
export const commentFromMarkdown: FromMarkdownExtension
export function commentToMarkdown(
options?: Options | undefined
): ToMarkdownExtension
export type Options = { emit?: boolean }
export type Root = import('mdast').Root
export type Extension = import('micromark-util-types').Extension
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension
export type ToMarkdownExtension = import('mdast-util-to-markdown').Options

195
node_modules/@slorber/remark-comment/index.js generated vendored Normal file
View File

@@ -0,0 +1,195 @@
import { factorySpace } from 'micromark-factory-space'
import { markdownLineEnding } from 'micromark-util-character'
import { codes } from 'micromark-util-symbol/codes.js'
import { types } from 'micromark-util-symbol/types.js'
export default function remarkComment(options) {
const data = this.data()
const add = (field, value) =>
(data[field] ? data[field] : (data[field] = [])).push(value)
add('micromarkExtensions', comment)
add('htmlExtensions', commentHtml)
add('fromMarkdownExtensions', commentFromMarkdown(options))
add('toMarkdownExtensions', commentToMarkdown)
}
export const comment = {
flow: { [60]: { tokenize, concrete: true } },
text: { [60]: { tokenize } },
}
export const commentHtml = {
enter: {
comment() {
this.buffer()
},
},
exit: {
comment() {
this.resume()
this.setData('slurpOneLineEnding', true)
},
},
}
export function commentFromMarkdown(options) {
return {
canContainEols: ['comment'],
enter: {
comment(token) {
this.buffer()
},
},
exit: {
comment(token) {
const text = this.resume()
if (options?.ast) {
this.enter(
{
type: 'comment',
value: '',
commentValue: text.slice(0, -2),
},
token
)
this.exit(token)
}
},
},
}
}
export const commentToMarkdown = {
handlers: {
comment(node) {
return `<!--${node.commentValue.replace(/(?<=--)>/g, '\\>')}-->`
},
},
}
function tokenize(effects, ok, nok) {
const self = this
return start
function start(code) {
effects.enter('comment')
effects.consume(code)
return open
}
function open(code) {
if (code === codes.exclamationMark) {
effects.consume(code)
return declarationOpen
}
return nok(code)
}
function declarationOpen(code) {
if (code === codes.dash) {
effects.consume(code)
return commentOpen
}
return nok(code)
}
function commentOpen(code) {
if (code === codes.dash) {
effects.consume(code)
return commentStart
}
return nok(code)
}
function commentStart(code) {
if (code === codes.greaterThan) {
return nok(code)
}
if (markdownLineEnding(code)) {
return atLineEnding(code);
}
effects.enter(types.data)
if (code === codes.dash) {
effects.consume(code)
return commentStartDash
}
return comment(code)
}
function commentStartDash(code) {
if (code === codes.greaterThan) {
return nok(code)
}
return comment(code)
}
function comment(code) {
if (code === codes.eof) {
return nok(code)
}
if (code === codes.dash) {
effects.consume(code)
return commentClose
}
if (markdownLineEnding(code)) {
effects.exit(types.data)
return atLineEnding(code)
}
effects.consume(code)
return comment
}
function atLineEnding(code) {
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return factorySpace(effects, afterPrefix, types.linePrefix)
}
function afterPrefix(code) {
if (markdownLineEnding(code)) {
return atLineEnding(code)
}
effects.enter(types.data)
return comment(code)
}
function commentClose(code) {
if (code === codes.dash) {
effects.consume(code)
return end
}
return comment(code)
}
function end(code) {
if (code === codes.greaterThan) {
effects.exit(types.data)
effects.enter('commentEnd') // See https://github.com/leebyron/remark-comment/pull/3#discussion_r1239494357
effects.consume(code)
effects.exit('commentEnd')
effects.exit('comment')
return ok(code)
}
if (code === codes.dash) {
effects.consume(code)
return end
}
return comment(code)
}
}

33
node_modules/@slorber/remark-comment/package.json generated vendored Normal file
View File

@@ -0,0 +1,33 @@
{
"name": "@slorber/remark-comment",
"version": "1.0.0",
"description": "Remark plugin to support comments",
"author": "Lee Byron <lee@leebyron.com> (https://leebyron.com)",
"license": "MIT",
"keywords": [
"unified",
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"comment"
],
"repository": "https://github.com/leebyron/remark-comment",
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"index.d.ts"
],
"dependencies": {
"micromark-factory-space": "^1.0.0",
"micromark-util-character": "^1.1.0",
"micromark-util-symbol": "^1.0.1"
},
"scripts": {
"test": "cd test && npm install --no-package-lock && npm test"
}
}