Compare commits

..

No commits in common. "main" and "3.0.0" have entirely different histories.
main ... 3.0.0

13 changed files with 193 additions and 257 deletions

View file

@ -1,9 +1,9 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

View file

@ -1,3 +1,9 @@
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
@ -5,9 +11,3 @@ 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]

View file

@ -1,21 +1,21 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v5
- uses: codecov/codecov-action@v3
strategy:
matrix:
node:
- lts/hydrogen
- lts/gallium
- node
name: main
on:
- pull_request
- push

9
.gitignore vendored
View file

@ -1,9 +1,6 @@
*.d.ts
*.log
*.map
*.tsbuildinfo
.DS_Store
coverage/
node_modules/
.DS_Store
*.d.ts
*.log
yarn.lock
!/index.d.ts

View file

@ -1,2 +1,3 @@
*.md
coverage/
*.json
*.md

15
index.d.ts vendored
View file

@ -1,15 +0,0 @@
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 {}

View file

@ -1,2 +1 @@
// Note: types exposed from `index.d.ts`.
export {default} from './lib/index.js'

View file

@ -1,16 +1,14 @@
/// <reference types="remark-parse" />
/// <reference types="remark-stringify" />
/// <reference types="mdast-util-directive" />
/**
* @import {} from 'mdast-util-directive'
* @import {Root} from 'mdast'
* @import {} from 'remark-arse'
* @import {} from 'remark-stringify'
* @import {Processor} from 'unified'
* @typedef {import('mdast').Root} Root
* @typedef {import('unified').Processor<Root>} Processor
*/
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.
@ -23,16 +21,19 @@ import { directive } from "micromark-extension-directive";
* Nothing.
*/
export default function remarkDirective() {
const data = this.data();
// @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 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())
}

View file

@ -1,6 +1,6 @@
(The MIT License)
Copyright (c) Titus Wormer <tituswormer@gmail.com>
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

View file

@ -1,33 +1,8 @@
{
"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"
},
"name": "remark-directive",
"version": "3.0.0",
"description": "remark plugin to support directives",
"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"
},
"license": "MIT",
"keywords": [
"container",
"directive",
@ -35,12 +10,55 @@
"markdown",
"mdast",
"plugin",
"remark-plugin",
"remark",
"remark-plugin",
"unified"
],
"license": "MIT",
"name": "remark-directive",
"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"
},
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
@ -50,57 +68,27 @@
"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": ["**/*.d.ts"],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "generic"
}
"files": [
"test/**/*.js"
],
"@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,
"rules": {
"logical-assignment-operators": "off"
}
"prettier": true
}
}

View file

@ -19,8 +19,7 @@ proposal][commonmark-prop] (`:cite[smith04]`,
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkDirective[, options])`](#unifieduseremarkdirective-options)
* [`Options`](#options)
* [`unified().use(remarkDirective)`](#unifieduseremarkdirective)
* [Examples](#examples)
* [Example: YouTube](#example-youtube)
* [Example: Styled blocks](#example-styled-blocks)
@ -105,11 +104,10 @@ A :i[lovely] language know as :abbr[HTML]{title="HyperText Markup Language"}.
…and our module `example.js` contains:
```js
/**
* @import {} from 'mdast-util-directive'
* @import {} from 'mdast-util-to-hast'
* @import {Root} from 'mdast'
*/
// 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 {h} from 'hastscript'
import rehypeFormat from 'rehype-format'
@ -137,7 +135,7 @@ console.log(String(file))
// See below for others examples.
function myRemarkPlugin() {
/**
* @param {Root} tree
* @param {import('mdast').Root} tree
* Tree.
* @returns {undefined}
* Nothing.
@ -175,14 +173,13 @@ function myRemarkPlugin() {
This package exports no identifiers.
The default export is [`remarkDirective`][api-remark-directive].
### `unified().use(remarkDirective[, options])`
### `unified().use(remarkDirective)`
Add support for generic directives.
###### Parameters
* `options` ([`Options`][api-options], optional)
— configuration
There are no parameters.
###### Returns
@ -193,29 +190,6 @@ Nothing (`undefined`).
Doesnt 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
@ -225,21 +199,19 @@ Its based on the example in Use above.
If `myRemarkPlugin` was replaced with this function:
```js
/**
* @import {} from 'mdast-util-directive'
* @import {} from 'mdast-util-to-hast'
* @import {Root} from 'mdast'
* @import {VFile} from 'vfile'
*/
// 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 {visit} from 'unist-util-visit'
// This plugin is an example to turn `::youtube` into iframes.
function myRemarkPlugin() {
/**
* @param {Root} tree
* @param {import('mdast').Root} tree
* Tree.
* @param {VFile} file
* @param {import('vfile').VFile} file
* File.
* @returns {undefined}
* Nothing.
@ -307,20 +279,20 @@ Its based on the example in Use above.
If `myRemarkPlugin` was replaced with this function:
```js
/**
* @import {} from 'mdast-util-directive'
* @import {} from 'mdast-util-to-hast'
* @import {Root} from 'mdast'
*/
// 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 {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 {Root} tree
* @param {import('mdast').Root} tree
* Tree.
* @returns {undefined}
* Nothing.
@ -401,16 +373,14 @@ If youre working with the syntax tree, you can register the new node types
with `@types/mdast` by adding a reference:
```js
/**
* @import {} from 'mdast-util-directive'
* @import {Root} from 'mdast'
*/
// Register directive nodes in mdast:
/// <reference types="mdast-util-directive" />
import {visit} from 'unist-util-visit'
function myRemarkPlugin() {
/**
* @param {Root} tree
* @param {import('mdast').Root} tree
* Tree.
* @returns {undefined}
* Nothing.
@ -525,8 +495,6 @@ 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
@ -539,6 +507,4 @@ abide by its terms.
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[api-remark-directive]: #unifieduseremarkdirective-options
[api-options]: #options
[api-remark-directive]: #unifieduseremarkdirective

View file

@ -48,8 +48,8 @@ test('fixtures', async function (t) {
/** @type {string} */
let output
const processor = remark().use(remarkDirective)
const actual = processor.parse(input)
const proc = remark().use(remarkDirective)
const actual = proc.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 processor.process(input)), String(output))
assert.equal(String(await proc.process(input)), String(output))
})
}
})

View file

@ -2,7 +2,6 @@
"compilerOptions": {
"checkJs": true,
"customConditions": ["development"],
"declarationMap": true,
"declaration": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": true,
@ -12,5 +11,5 @@
"target": "es2022"
},
"exclude": ["coverage/", "node_modules/"],
"include": ["**/*.js", "index.d.ts"]
"include": ["**/*.js"]
}