Refactor to use @import
s
This commit is contained in:
parent
8f29f1e456
commit
7ca8974f14
2 changed files with 31 additions and 26 deletions
13
lib/index.js
13
lib/index.js
|
@ -1,10 +1,9 @@
|
||||||
/// <reference types="remark-parse" />
|
|
||||||
/// <reference types="remark-stringify" />
|
|
||||||
/// <reference types="mdast-util-directive" />
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('mdast').Root} Root
|
* @import {} from 'mdast-util-directive'
|
||||||
* @typedef {import('unified').Processor<Root>} Processor
|
* @import {Root} from 'mdast'
|
||||||
|
* @import {} from 'remark-arse'
|
||||||
|
* @import {} from 'remark-stringify'
|
||||||
|
* @import {Processor} from 'unified'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
import {directiveFromMarkdown, directiveToMarkdown} from 'mdast-util-directive'
|
||||||
|
@ -23,7 +22,7 @@ import {directive} from 'micromark-extension-directive'
|
||||||
export default function remarkDirective() {
|
export default function remarkDirective() {
|
||||||
// @ts-expect-error: TS is wrong about `this`.
|
// @ts-expect-error: TS is wrong about `this`.
|
||||||
// eslint-disable-next-line unicorn/no-this-assignment
|
// eslint-disable-next-line unicorn/no-this-assignment
|
||||||
const self = /** @type {Processor} */ (this)
|
const self = /** @type {Processor<Root>} */ (this)
|
||||||
const data = self.data()
|
const data = self.data()
|
||||||
|
|
||||||
const micromarkExtensions =
|
const micromarkExtensions =
|
||||||
|
|
44
readme.md
44
readme.md
|
@ -104,10 +104,11 @@ A :i[lovely] language know as :abbr[HTML]{title="HyperText Markup Language"}.
|
||||||
…and our module `example.js` contains:
|
…and our module `example.js` contains:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
/**
|
||||||
/// <reference types="mdast-util-to-hast" />
|
* @import {} from 'mdast-util-directive'
|
||||||
// Register directive nodes in mdast:
|
* @import {} from 'mdast-util-to-hast'
|
||||||
/// <reference types="mdast-util-directive" />
|
* @import {Root} from 'mdast'
|
||||||
|
*/
|
||||||
|
|
||||||
import {h} from 'hastscript'
|
import {h} from 'hastscript'
|
||||||
import rehypeFormat from 'rehype-format'
|
import rehypeFormat from 'rehype-format'
|
||||||
|
@ -135,7 +136,7 @@ console.log(String(file))
|
||||||
// See below for others examples.
|
// See below for others examples.
|
||||||
function myRemarkPlugin() {
|
function myRemarkPlugin() {
|
||||||
/**
|
/**
|
||||||
* @param {import('mdast').Root} tree
|
* @param {Root} tree
|
||||||
* Tree.
|
* Tree.
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
* Nothing.
|
* Nothing.
|
||||||
|
@ -199,19 +200,21 @@ It’s based on the example in Use above.
|
||||||
If `myRemarkPlugin` was replaced with this function:
|
If `myRemarkPlugin` was replaced with this function:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
/**
|
||||||
/// <reference types="mdast-util-to-hast" />
|
* @import {} from 'mdast-util-directive'
|
||||||
// Register directive nodes in mdast:
|
* @import {} from 'mdast-util-to-hast'
|
||||||
/// <reference types="mdast-util-directive" />
|
* @import {Root} from 'mdast'
|
||||||
|
* @import {VFile} from 'vfile'
|
||||||
|
*/
|
||||||
|
|
||||||
import {visit} from 'unist-util-visit'
|
import {visit} from 'unist-util-visit'
|
||||||
|
|
||||||
// This plugin is an example to turn `::youtube` into iframes.
|
// This plugin is an example to turn `::youtube` into iframes.
|
||||||
function myRemarkPlugin() {
|
function myRemarkPlugin() {
|
||||||
/**
|
/**
|
||||||
* @param {import('mdast').Root} tree
|
* @param {Root} tree
|
||||||
* Tree.
|
* Tree.
|
||||||
* @param {import('vfile').VFile} file
|
* @param {VFile} file
|
||||||
* File.
|
* File.
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
* Nothing.
|
* Nothing.
|
||||||
|
@ -279,10 +282,11 @@ It’s based on the example in Use above.
|
||||||
If `myRemarkPlugin` was replaced with this function:
|
If `myRemarkPlugin` was replaced with this function:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Register `hName`, `hProperties` types, used when turning markdown to HTML:
|
/**
|
||||||
/// <reference types="mdast-util-to-hast" />
|
* @import {} from 'mdast-util-directive'
|
||||||
// Register directive nodes in mdast:
|
* @import {} from 'mdast-util-to-hast'
|
||||||
/// <reference types="mdast-util-directive" />
|
* @import {Root} from 'mdast'
|
||||||
|
*/
|
||||||
|
|
||||||
import {h} from 'hastscript'
|
import {h} from 'hastscript'
|
||||||
import {visit} from 'unist-util-visit'
|
import {visit} from 'unist-util-visit'
|
||||||
|
@ -291,7 +295,7 @@ import {visit} from 'unist-util-visit'
|
||||||
// attributes.
|
// attributes.
|
||||||
function myRemarkPlugin() {
|
function myRemarkPlugin() {
|
||||||
/**
|
/**
|
||||||
* @param {import('mdast').Root} tree
|
* @param {Root} tree
|
||||||
* Tree.
|
* Tree.
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
* Nothing.
|
* Nothing.
|
||||||
|
@ -372,14 +376,16 @@ If you’re working with the syntax tree, you can register the new node types
|
||||||
with `@types/mdast` by adding a reference:
|
with `@types/mdast` by adding a reference:
|
||||||
|
|
||||||
```js
|
```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'
|
import {visit} from 'unist-util-visit'
|
||||||
|
|
||||||
function myRemarkPlugin() {
|
function myRemarkPlugin() {
|
||||||
/**
|
/**
|
||||||
* @param {import('mdast').Root} tree
|
* @param {Root} tree
|
||||||
* Tree.
|
* Tree.
|
||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
* Nothing.
|
* Nothing.
|
||||||
|
|
Loading…
Add table
Reference in a new issue