Compare commits
15 commits
Author | SHA1 | Date | |
---|---|---|---|
f67c8452ab | |||
5e61c16964 | |||
722e6bee28 | |||
|
103c85adba | ||
|
b685b00060 | ||
|
7ca8974f14 | ||
|
8f29f1e456 | ||
|
7e9a5a78b8 | ||
|
f2eefc2418 | ||
|
a29bc053db | ||
|
9f8e165510 | ||
|
6fe12e7771 | ||
|
320c56aacf | ||
|
7831904974 | ||
|
876a45ad4c |
13 changed files with 257 additions and 193 deletions
|
@ -1,9 +1,9 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
|
12
.github/workflows/bb.yml
vendored
12
.github/workflows/bb.yml
vendored
|
@ -1,9 +1,3 @@
|
|||
name: bb
|
||||
on:
|
||||
issues:
|
||||
types: [opened, reopened, edited, closed, labeled, unlabeled]
|
||||
pull_request_target:
|
||||
types: [opened, reopened, edited, closed, labeled, unlabeled]
|
||||
jobs:
|
||||
main:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -11,3 +5,9 @@ jobs:
|
|||
- uses: unifiedjs/beep-boop-beta@main
|
||||
with:
|
||||
repo-token: ${{secrets.GITHUB_TOKEN}}
|
||||
name: bb
|
||||
on:
|
||||
issues:
|
||||
types: [closed, edited, labeled, opened, reopened, unlabeled]
|
||||
pull_request_target:
|
||||
types: [closed, edited, labeled, opened, reopened, unlabeled]
|
||||
|
|
16
.github/workflows/main.yml
vendored
16
.github/workflows/main.yml
vendored
|
@ -1,21 +1,21 @@
|
|||
name: main
|
||||
on:
|
||||
- pull_request
|
||||
- push
|
||||
jobs:
|
||||
main:
|
||||
name: ${{matrix.node}}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{matrix.node}}
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
- uses: codecov/codecov-action@v3
|
||||
- uses: codecov/codecov-action@v5
|
||||
strategy:
|
||||
matrix:
|
||||
node:
|
||||
- lts/gallium
|
||||
- lts/hydrogen
|
||||
- node
|
||||
name: main
|
||||
on:
|
||||
- pull_request
|
||||
- push
|
||||
|
|
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -1,6 +1,9 @@
|
|||
coverage/
|
||||
node_modules/
|
||||
.DS_Store
|
||||
*.d.ts
|
||||
*.log
|
||||
*.map
|
||||
*.tsbuildinfo
|
||||
.DS_Store
|
||||
coverage/
|
||||
node_modules/
|
||||
yarn.lock
|
||||
!/index.d.ts
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
coverage/
|
||||
*.json
|
||||
*.md
|
||||
coverage/
|
||||
|
|
15
index.d.ts
vendored
Normal file
15
index.d.ts
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
import type {ToMarkdownOptions} from 'mdast-util-directive'
|
||||
|
||||
export {default} from './lib/index.js'
|
||||
|
||||
/**
|
||||
* Configuration for `remark-directive`.
|
||||
*
|
||||
* Currently supports
|
||||
* `collapseEmptyAttributes`,
|
||||
* `preferShortcut`,
|
||||
* `preferUnquoted`,
|
||||
* `quoteSmart`,
|
||||
* and `quote` as serialization options.
|
||||
*/
|
||||
export interface Options extends ToMarkdownOptions {}
|
1
index.js
1
index.js
|
@ -1 +1,2 @@
|
|||
// Note: types exposed from `index.d.ts`.
|
||||
export {default} from './lib/index.js'
|
||||
|
|
35
lib/index.js
35
lib/index.js
|
@ -1,14 +1,16 @@
|
|||
/// <reference types="remark-parse" />
|
||||
/// <reference types="remark-stringify" />
|
||||
/// <reference types="mdast-util-directive" />
|
||||
|
||||
/**
|
||||
* @typedef {import('mdast').Root} Root
|
||||
* @typedef {import('unified').Processor<Root>} Processor
|
||||
* @import {} from 'mdast-util-directive'
|
||||
* @import {Root} from 'mdast'
|
||||
* @import {} from 'remark-arse'
|
||||
* @import {} from 'remark-stringify'
|
||||
* @import {Processor} from 'unified'
|
||||
*/
|
||||
|
||||
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
||||
import {directive} from 'micromark-extension-directive'
|
||||
import {
|
||||
directiveFromMarkdown,
|
||||
directiveToMarkdown,
|
||||
} from "mdast-util-directive";
|
||||
import { directive } from "micromark-extension-directive";
|
||||
|
||||
/**
|
||||
* Add support for generic directives.
|
||||
|
@ -21,19 +23,16 @@ import {directive} from 'micromark-extension-directive'
|
|||
* Nothing.
|
||||
*/
|
||||
export default function remarkDirective() {
|
||||
// @ts-expect-error: TS is wrong about `this`.
|
||||
// eslint-disable-next-line unicorn/no-this-assignment
|
||||
const self = /** @type {Processor} */ (this)
|
||||
const data = self.data()
|
||||
const data = this.data();
|
||||
|
||||
const micromarkExtensions =
|
||||
data.micromarkExtensions || (data.micromarkExtensions = [])
|
||||
data.micromarkExtensions || (data.micromarkExtensions = []);
|
||||
const fromMarkdownExtensions =
|
||||
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
|
||||
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
|
||||
const toMarkdownExtensions =
|
||||
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
|
||||
data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
|
||||
|
||||
micromarkExtensions.push(directive())
|
||||
fromMarkdownExtensions.push(directiveFromMarkdown())
|
||||
toMarkdownExtensions.push(directiveToMarkdown())
|
||||
micromarkExtensions.push(directive());
|
||||
fromMarkdownExtensions.push(directiveFromMarkdown());
|
||||
toMarkdownExtensions.push(directiveToMarkdown());
|
||||
}
|
||||
|
|
2
license
2
license
|
@ -1,6 +1,6 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
Copyright (c) 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
|
||||
|
|
126
package.json
126
package.json
|
@ -1,8 +1,33 @@
|
|||
{
|
||||
"name": "remark-directive",
|
||||
"version": "3.0.0",
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"bugs": "https://github.com/remarkjs/remark-directive/issues",
|
||||
"contributors": ["Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"],
|
||||
"dependencies": {
|
||||
"@types/mdast": "^4.0.0",
|
||||
"mdast-util-directive": "^3.0.0",
|
||||
"micromark-extension-directive": "git+https://git.v-sli.me/HidemaruOwO/micromark-extension-directive.git#fix.1",
|
||||
"unified": "^11.0.0"
|
||||
},
|
||||
"description": "remark plugin to support directives",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.0.0",
|
||||
"c8": "^10.0.0",
|
||||
"is-hidden": "^2.0.0",
|
||||
"prettier": "^3.0.0",
|
||||
"remark": "^15.0.0",
|
||||
"remark-cli": "^12.0.0",
|
||||
"remark-preset-wooorm": "^10.0.0",
|
||||
"to-vfile": "^8.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"xo": "^0.60.0"
|
||||
},
|
||||
"exports": "./index.js",
|
||||
"files": ["index.d.ts", "index.js", "lib/"],
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"keywords": [
|
||||
"container",
|
||||
"directive",
|
||||
|
@ -10,55 +35,12 @@
|
|||
"markdown",
|
||||
"mdast",
|
||||
"plugin",
|
||||
"remark",
|
||||
"remark-plugin",
|
||||
"remark",
|
||||
"unified"
|
||||
],
|
||||
"repository": "remarkjs/remark-directive",
|
||||
"bugs": "https://github.com/remarkjs/remark-directive/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)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"exports": "./index.js",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/mdast": "^4.0.0",
|
||||
"mdast-util-directive": "^3.0.0",
|
||||
"micromark-extension-directive": "^3.0.0",
|
||||
"unified": "^11.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"c8": "^8.0.0",
|
||||
"is-hidden": "^2.0.0",
|
||||
"prettier": "^3.0.0",
|
||||
"remark": "^15.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"to-vfile": "^8.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"xo": "^0.56.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --build --clean && tsc --build && type-coverage",
|
||||
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
|
||||
"prepack": "npm run build && npm run format",
|
||||
"test": "npm run build && npm run format && npm run test-coverage",
|
||||
"test-api": "node --conditions development test/index.js",
|
||||
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
|
||||
},
|
||||
"license": "MIT",
|
||||
"name": "remark-directive",
|
||||
"prettier": {
|
||||
"bracketSpacing": false,
|
||||
"singleQuote": true,
|
||||
|
@ -68,27 +50,57 @@
|
|||
"useTabs": false
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"remark-preset-wooorm"
|
||||
]
|
||||
"plugins": ["remark-preset-wooorm"]
|
||||
},
|
||||
"repository": "remarkjs/remark-directive",
|
||||
"scripts": {
|
||||
"build": "tsc --build --clean && tsc --build && type-coverage",
|
||||
"format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
|
||||
"prepack": "npm run build && npm run format",
|
||||
"test-api": "node --conditions development test/index.js",
|
||||
"test-coverage": "c8 --100 --reporter lcov -- npm run test-api",
|
||||
"test": "npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"ignoreCatch": true,
|
||||
"strict": true
|
||||
},
|
||||
"type": "module",
|
||||
"version": "3.0.1",
|
||||
"xo": {
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"test/**/*.js"
|
||||
"files": ["**/*.d.ts"],
|
||||
"rules": {
|
||||
"@typescript-eslint/array-type": [
|
||||
"error",
|
||||
{
|
||||
"default": "generic"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/ban-types": [
|
||||
"error",
|
||||
{
|
||||
"extendDefaults": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/consistent-type-definitions": [
|
||||
"error",
|
||||
"interface"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["test/**/*.js"],
|
||||
"rules": {
|
||||
"no-await-in-loop": "off"
|
||||
}
|
||||
}
|
||||
],
|
||||
"prettier": true
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"logical-assignment-operators": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
82
readme.md
82
readme.md
|
@ -19,7 +19,8 @@ proposal][commonmark-prop] (`:cite[smith04]`,
|
|||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`unified().use(remarkDirective)`](#unifieduseremarkdirective)
|
||||
* [`unified().use(remarkDirective[, options])`](#unifieduseremarkdirective-options)
|
||||
* [`Options`](#options)
|
||||
* [Examples](#examples)
|
||||
* [Example: YouTube](#example-youtube)
|
||||
* [Example: Styled blocks](#example-styled-blocks)
|
||||
|
@ -104,10 +105,11 @@ A :i[lovely] language know as :abbr[HTML]{title="HyperText Markup Language"}.
|
|||
…and our module `example.js` contains:
|
||||
|
||||
```js
|
||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
||||
/// <reference types="mdast-util-to-hast" />
|
||||
// Register directive nodes in mdast:
|
||||
/// <reference types="mdast-util-directive" />
|
||||
/**
|
||||
* @import {} from 'mdast-util-directive'
|
||||
* @import {} from 'mdast-util-to-hast'
|
||||
* @import {Root} from 'mdast'
|
||||
*/
|
||||
|
||||
import {h} from 'hastscript'
|
||||
import rehypeFormat from 'rehype-format'
|
||||
|
@ -135,7 +137,7 @@ console.log(String(file))
|
|||
// See below for others examples.
|
||||
function myRemarkPlugin() {
|
||||
/**
|
||||
* @param {import('mdast').Root} tree
|
||||
* @param {Root} tree
|
||||
* Tree.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
|
@ -173,13 +175,14 @@ function myRemarkPlugin() {
|
|||
This package exports no identifiers.
|
||||
The default export is [`remarkDirective`][api-remark-directive].
|
||||
|
||||
### `unified().use(remarkDirective)`
|
||||
### `unified().use(remarkDirective[, options])`
|
||||
|
||||
Add support for generic directives.
|
||||
|
||||
###### Parameters
|
||||
|
||||
There are no parameters.
|
||||
* `options` ([`Options`][api-options], optional)
|
||||
— configuration
|
||||
|
||||
###### Returns
|
||||
|
||||
|
@ -190,6 +193,29 @@ Nothing (`undefined`).
|
|||
Doesn’t handle the directives:
|
||||
[create your own plugin][unified-create-plugin] to do that.
|
||||
|
||||
### `Options`
|
||||
|
||||
Configuration (TypeScript type).
|
||||
|
||||
###### Fields
|
||||
|
||||
* `collapseEmptyAttributes`
|
||||
(`boolean`, default: `true`)
|
||||
— collapse empty attributes: get `title` instead of `title=""`
|
||||
* `preferShortcut`
|
||||
(`boolean`, default: `true`)
|
||||
— prefer `#` and `.` shortcuts for `id` and `class`
|
||||
* `preferUnquoted`
|
||||
(`boolean`, default: `false`)
|
||||
— leave attributes unquoted if that results in less bytes
|
||||
* `quoteSmart`
|
||||
(`boolean`, default: `false`)
|
||||
— use the other quote if that results in less bytes
|
||||
* `quote`
|
||||
(`'"'` or `"'"`,
|
||||
default: the [`quote`][quote] used by `remark-stringify` for titles)
|
||||
— preferred quote to use around attribute values
|
||||
|
||||
## Examples
|
||||
|
||||
### Example: YouTube
|
||||
|
@ -199,19 +225,21 @@ It’s based on the example in Use above.
|
|||
If `myRemarkPlugin` was replaced with this function:
|
||||
|
||||
```js
|
||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
||||
/// <reference types="mdast-util-to-hast" />
|
||||
// Register directive nodes in mdast:
|
||||
/// <reference types="mdast-util-directive" />
|
||||
/**
|
||||
* @import {} from 'mdast-util-directive'
|
||||
* @import {} from 'mdast-util-to-hast'
|
||||
* @import {Root} from 'mdast'
|
||||
* @import {VFile} from 'vfile'
|
||||
*/
|
||||
|
||||
import {visit} from 'unist-util-visit'
|
||||
|
||||
// This plugin is an example to turn `::youtube` into iframes.
|
||||
function myRemarkPlugin() {
|
||||
/**
|
||||
* @param {import('mdast').Root} tree
|
||||
* @param {Root} tree
|
||||
* Tree.
|
||||
* @param {import('vfile').VFile} file
|
||||
* @param {VFile} file
|
||||
* File.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
|
@ -279,20 +307,20 @@ It’s based on the example in Use above.
|
|||
If `myRemarkPlugin` was replaced with this function:
|
||||
|
||||
```js
|
||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
||||
/// <reference types="mdast-util-to-hast" />
|
||||
// Register directive nodes in mdast:
|
||||
/// <reference types="mdast-util-directive" />
|
||||
/**
|
||||
* @import {} from 'mdast-util-directive'
|
||||
* @import {} from 'mdast-util-to-hast'
|
||||
* @import {Root} from 'mdast'
|
||||
*/
|
||||
|
||||
import {h} from 'hastscript'
|
||||
import {visit} from 'unist-util-visit'
|
||||
|
||||
// This plugin is an example to turn `::youtube` into iframes.
|
||||
// This plugin is an example to turn `::note` into divs, passing arbitrary
|
||||
// attributes.
|
||||
function myRemarkPlugin() {
|
||||
/**
|
||||
* @param {import('mdast').Root} tree
|
||||
* @param {Root} tree
|
||||
* Tree.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
|
@ -373,14 +401,16 @@ If you’re working with the syntax tree, you can register the new node types
|
|||
with `@types/mdast` by adding a reference:
|
||||
|
||||
```js
|
||||
// Register directive nodes in mdast:
|
||||
/// <reference types="mdast-util-directive" />
|
||||
/**
|
||||
* @import {} from 'mdast-util-directive'
|
||||
* @import {Root} from 'mdast'
|
||||
*/
|
||||
|
||||
import {visit} from 'unist-util-visit'
|
||||
|
||||
function myRemarkPlugin() {
|
||||
/**
|
||||
* @param {import('mdast').Root} tree
|
||||
* @param {Root} tree
|
||||
* Tree.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
|
@ -495,6 +525,8 @@ abide by its terms.
|
|||
|
||||
[micromark-extending-markdown]: https://github.com/micromark/micromark#extending-markdown
|
||||
|
||||
[quote]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options
|
||||
|
||||
[rehype]: https://github.com/rehypejs/rehype
|
||||
|
||||
[remark]: https://github.com/remarkjs/remark
|
||||
|
@ -507,4 +539,6 @@ abide by its terms.
|
|||
|
||||
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
|
||||
|
||||
[api-remark-directive]: #unifieduseremarkdirective
|
||||
[api-remark-directive]: #unifieduseremarkdirective-options
|
||||
|
||||
[api-options]: #options
|
||||
|
|
|
@ -48,8 +48,8 @@ test('fixtures', async function (t) {
|
|||
/** @type {string} */
|
||||
let output
|
||||
|
||||
const proc = remark().use(remarkDirective)
|
||||
const actual = proc.parse(input)
|
||||
const processor = remark().use(remarkDirective)
|
||||
const actual = processor.parse(input)
|
||||
|
||||
try {
|
||||
output = String(await fs.readFile(outputUrl))
|
||||
|
@ -72,7 +72,7 @@ test('fixtures', async function (t) {
|
|||
|
||||
assert.deepEqual(actual, expected)
|
||||
|
||||
assert.equal(String(await proc.process(input)), String(output))
|
||||
assert.equal(String(await processor.process(input)), String(output))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
"customConditions": ["development"],
|
||||
"declarationMap": true,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"exactOptionalPropertyTypes": true,
|
||||
|
@ -11,5 +12,5 @@
|
|||
"target": "es2022"
|
||||
},
|
||||
"exclude": ["coverage/", "node_modules/"],
|
||||
"include": ["**/*.js"]
|
||||
"include": ["**/*.js", "index.d.ts"]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue