Skip to content

Commit

Permalink
Refactor to move implementation to lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 26, 2023
1 parent 730e56e commit 29e486f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
24 changes: 2 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 1,5 @@
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast-util-raw').Options} RawOptions
* @typedef {import('hast-util-raw')} DoNotTouchAsThisImportIncludesRawInTree
* @typedef {import('./lib/index.js').Options} Options
*/

/**
* @typedef {Omit<RawOptions, 'file'>} Options
*/

import {raw} from 'hast-util-raw'

/**
* Plugin to parse the tree again (and raw nodes).
* Keeping positional info OK. 🙌
*
* @type {import('unified').Plugin<[Options?] | Array<void>, Root>}
*/
export default function rehypeRaw(options = {}) {
return (tree, file) => {
// Assume that when a root was given, it’s also returned.
const result = /** @type {Root} */ (raw(tree, {...options, file}))
return result
}
}
export {default} from './lib/index.js'
25 changes: 25 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 1,25 @@
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast-util-raw').Options} RawOptions
* @typedef {import('hast-util-raw')} DoNotTouchAsThisImportIncludesRawInTree
*/

/**
* @typedef {Omit<RawOptions, 'file'>} Options
*/

import {raw} from 'hast-util-raw'

/**
* Plugin to parse the tree again (and raw nodes).
* Keeping positional info OK. 🙌
*
* @type {import('unified').Plugin<[Options?] | Array<void>, Root>}
*/
export default function rehypeRaw(options = {}) {
return (tree, file) => {
// Assume that when a root was given, it’s also returned.
const result = /** @type {Root} */ (raw(tree, {...options, file}))
return result
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,7 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
Expand Down

0 comments on commit 29e486f

Please sign in to comment.