Giter Club home page Giter Club logo

mdast-util-find-and-replace's Issues

In a node containing multiple matches of the search string or regex, only the first occurrence is replaced

Initial checklist

Affected packages and versions

[email protected]

Link to runnable example

#4

Steps to reproduce

See new unit test in PR above. The search string is the regular expression /(emph|sis)/ and the replacement text is 'foo'. So the text node with the content 'emphasis' should be replaced with three new text nodes, with the contents 'foo', 'a', and 'foo', respectively.

Expected behavior

The test should pass.

Actual behavior

The test fails because only the first match is replaced, resulting in only two nodes with the contents 'foo' and 'asis', respectively.

Affected runtime and version

[email protected]

Affected package manager and version

[email protected]

Affected OS and version

macOS Ventura 13.5.2

Build and bundle tools

No response

Infer `position` info for replaced nodes

Initial checklist

Problem

That the nodes generated via remark-breaks do not contain position information. This might be something that this underlying library could take care of.

Solution

I'm not 100% sure how much the remark-breaks represents a typical usage of this library, but for the remark-break case this library should be able to automatically infer the position of the break and subsequent text nodes.

Alternatives

Otherwise the replace() callback could contain some context which allows the caller to infer the correct position information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.