Compare commits

...

15 commits
3.0.0 ... main

Author SHA1 Message Date
f67c8452ab 🔧 fix (bun.lockb)
Some checks failed
main / lts/hydrogen (push) Has been cancelled
main / node (push) Has been cancelled
2025-02-07 02:44:11 +09:00
5e61c16964 🔧 fix (lib/index.js, package.json)
Some checks are pending
main / lts/hydrogen (push) Waiting to run
main / node (push) Waiting to run
2025-02-07 02:43:00 +09:00
722e6bee28 🔧 directive looks like zenn (bun.lockb, package.json)
Some checks are pending
main / lts/hydrogen (push) Waiting to run
main / node (push) Waiting to run
2025-02-06 21:57:28 +09:00
Titus Wormer
103c85adba
3.0.1 2025-01-22 16:14:39 +01:00
Titus Wormer
b685b00060
Add types, docs for options 2025-01-22 16:13:18 +01:00
Titus Wormer
7ca8974f14
Refactor to use @imports 2025-01-22 16:05:40 +01:00
Titus Wormer
8f29f1e456
Add declaration maps 2025-01-22 16:02:33 +01:00
Titus Wormer
7e9a5a78b8
Refactor package.json 2025-01-22 16:01:59 +01:00
Titus Wormer
f2eefc2418
Remove license year 2025-01-22 15:59:40 +01:00
Titus Wormer
a29bc053db
Refactor .prettierignore 2025-01-22 15:59:30 +01:00
Titus Wormer
9f8e165510
Refactor .editorconfig 2025-01-22 15:59:02 +01:00
Titus Wormer
6fe12e7771
Add .tsbuildinfo to .gitignore 2025-01-22 15:58:44 +01:00
Titus Wormer
320c56aacf
Update Actions 2025-01-22 15:58:22 +01:00
Titus Wormer
7831904974
Update dev-dependencies 2025-01-22 15:57:52 +01:00
Riley Tomasek
876a45ad4c
Fix typo
Closes GH-15.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
2023-11-06 11:17:48 +01:00
13 changed files with 257 additions and 193 deletions

View file

@ -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

View file

@ -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]

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@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
View file

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

View file

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

15
index.d.ts vendored Normal file
View 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 {}

View file

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

View file

@ -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 = [])
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = [])
const toMarkdownExtensions =
data.toMarkdownExtensions || (data.toMarkdownExtensions = [])
const micromarkExtensions =
data.micromarkExtensions || (data.micromarkExtensions = []);
const fromMarkdownExtensions =
data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
const 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) 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

View file

@ -1,94 +1,106 @@
{
"name": "remark-directive",
"version": "3.0.0",
"description": "remark plugin to support directives",
"license": "MIT",
"keywords": [
"container",
"directive",
"generic",
"markdown",
"mdast",
"plugin",
"remark",
"remark-plugin",
"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"
},
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
"semi": false,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"no-await-in-loop": "off"
}
}
],
"prettier": true
}
"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",
"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",
"generic",
"markdown",
"mdast",
"plugin",
"remark-plugin",
"remark",
"unified"
],
"license": "MIT",
"name": "remark-directive",
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
"semi": false,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"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,
"strict": true
},
"type": "module",
"version": "3.0.1",
"xo": {
"overrides": [
{
"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,
"rules": {
"logical-assignment-operators": "off"
}
}
}

138
readme.md
View file

@ -14,26 +14,27 @@ proposal][commonmark-prop] (`:cite[smith04]`,
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkDirective)`](#unifieduseremarkdirective)
* [Examples](#examples)
* [Example: YouTube](#example-youtube)
* [Example: Styled blocks](#example-styled-blocks)
* [Authoring](#authoring)
* [HTML](#html)
* [CSS](#css)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkDirective[, options])`](#unifieduseremarkdirective-options)
* [`Options`](#options)
* [Examples](#examples)
* [Example: YouTube](#example-youtube)
* [Example: Styled blocks](#example-styled-blocks)
* [Authoring](#authoring)
* [HTML](#html)
* [CSS](#css)
* [Syntax](#syntax)
* [Syntax tree](#syntax-tree)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
@ -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`).
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
@ -199,19 +225,21 @@ Its 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 @@ Its 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 youre 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.
@ -411,15 +441,15 @@ attacks.
## Related
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm)
— support GFM (autolink literals, footnotes, strikethrough, tables,
tasklists)
* [`remark-frontmatter`](https://github.com/remarkjs/remark-frontmatter)
— support frontmatter (YAML, TOML, and more)
* [`remark-math`](https://github.com/remarkjs/remark-math)
— support math
* [`remark-mdx`](https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx)
— support MDX (ESM, JSX, expressions)
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm)
— support GFM (autolink literals, footnotes, strikethrough, tables,
tasklists)
* [`remark-frontmatter`](https://github.com/remarkjs/remark-frontmatter)
— support frontmatter (YAML, TOML, and more)
* [`remark-math`](https://github.com/remarkjs/remark-math)
— support math
* [`remark-mdx`](https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx)
— support MDX (ESM, JSX, expressions)
## Contribute
@ -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

View file

@ -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))
})
}
})

View file

@ -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"]
}