Skip to content

chore: enable regex #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {visit} from 'unist-util-visit'
*
* @param {Nodes} node
* Tree to search.
* @param {string} name
* @param {string | RegExp} name
* Comment name to look for.
* @param {Handler} handler
* Handle a section.
Expand All @@ -57,7 +57,8 @@ export function zone(node, name, handler) {
visit(node, function (node, index, parent) {
const info = commentMarker(node)
const match =
info && info.name === name
info &&
(typeof name === 'string' ? info.name === name : info.name.match(name))
? info.attributes.match(/(start|end)\b/)
: undefined
const type = match ? match[0] : undefined
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/regexp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {zone} from 'mdast-zone'

/** @param {import('mdast').Root} tree */
export default function assertion(tree) {
zone(tree, /.*foo.*/, function (start, _, end) {
return [
start,
{
type: 'paragraph',
depth: 2,
children: [{type: 'text', value: 'changed'}]
},
end
]
})
}
5 changes: 5 additions & 0 deletions test/fixtures/regexp/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Foo

<!--foo with some extra words start-->

<!--foo end-->
7 changes: 7 additions & 0 deletions test/fixtures/regexp/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Foo

<!--foo with some extra words start-->

changed

<!--foo end-->