mdast-util-find-and-replace

WebJar for mdast-util-find-and-replace

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

mdast-util-find-and-replace
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

mdast-util-find-and-replace
WebJar for mdast-util-find-and-replace
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/syntax-tree/mdast-util-find-and-replace

Download mdast-util-find-and-replace

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-find-and-replace/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>mdast-util-find-and-replace</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-find-and-replace/
implementation 'org.webjars.npm:mdast-util-find-and-replace:1.1.1'
// https://jarcasting.com/artifacts/org.webjars.npm/mdast-util-find-and-replace/
implementation ("org.webjars.npm:mdast-util-find-and-replace:1.1.1")
'org.webjars.npm:mdast-util-find-and-replace:jar:1.1.1'
<dependency org="org.webjars.npm" name="mdast-util-find-and-replace" rev="1.1.1">
  <artifact name="mdast-util-find-and-replace" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='mdast-util-find-and-replace', version='1.1.1')
)
libraryDependencies += "org.webjars.npm" % "mdast-util-find-and-replace" % "1.1.1"
[org.webjars.npm/mdast-util-find-and-replace "1.1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.webjars.npm : escape-string-regexp jar [4.0.0,5)
org.webjars.npm : unist-util-is jar [4.0.0,5)
org.webjars.npm : unist-util-visit-parents jar [3.0.0,4)

Project Modules

There are no modules declared in this project.

mdast-util-find-and-replace

Build Coverage Downloads Size Sponsors Backers Chat

mdast utility to find and replace text in a tree.

Install

npm:

npm install mdast-util-find-and-replace

Use

var u = require('unist-builder')
var inspect = require('unist-util-inspect')
var findAndReplace = require('mdast-util-find-and-replace')

var tree = u('paragraph', [
  u('text', 'Some '),
  u('emphasis', [u('text', 'emphasis')]),
  u('text', ' and '),
  u('strong', [u('text', 'importance')]),
  u('text', '.')
])

findAndReplace(tree, 'and', 'or')

findAndReplace(tree, {emphasis: 'em', importance: 'strong'})

findAndReplace(tree, {
  Some: function ($0) {
    return u('link', {url: '//example.com#' + $0}, [u('text', $0)])
  }
})

console.log(inspect(tree))

Yields:

paragraph[8]
├─ link[1] [url="//example.com#Some"]
│  └─ text: "Some"
├─ text: " "
├─ emphasis[1]
│  └─ text: "em"
├─ text: " "
├─ text: "or"
├─ text: " "
├─ strong[1]
│  └─ text: "strong"
└─ text: "."

API

findAndReplace(tree, find[, replace][, options])

Find and replace text in mdast trees. The algorithm searches the tree in preorder for complete values in Text nodes. Partial matches are not supported.

Signatures
  • findAndReplace(tree, find, replace?[, options])
  • findAndReplace(tree, search[, options])
Parameters
  • tree (Node) — mdast tree
  • find (string or RegExp) — Value to find and remove. When string, escaped and made into a global RegExp
  • replace (string or Function) — Value to insert. When string, turned into a Text node. When Function, invoked with the results of calling RegExp.exec as arguments, in which case it can return a single or a list of Node, a string (which is wrapped in a Text node), or false to not replace
  • search (Object or Array) — Perform multiple find-and-replaces. When Array, each entry is a tuple (Array) of a find (at 0) and replace (at 1). When Object, each key is a find (in string form) and each value is a replace
  • options.ignore (Test, default: []) — Any unist-util-is compatible test.
Returns

The given, modified, tree.

Security

Use of mdast-util-find-and-replace does not involve hast or user content so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

org.webjars.npm
🌲🌲🌲🌳🌲🌳🌲🌲🌲🌳🌳🌲🌲🌳🌲🌲🎄🌲🌳🌲🌲🌳🐻🌳🌳🌳🌲🌲🌳🌲🎄🌲🌳🌲🌲🌳🌳🌳

Versions

Version
1.1.1