Coder Social home page Coder Social logo

Comments (3)

jaywcjlove avatar jaywcjlove commented on June 20, 2024 1

@bardic

rewrite: (node: any, index: any, parent: any) => {
  if (node.type === "element") {
    let text = getCodeString(node.children);
    if (REG.test(text)) {
      node.tagName = "a";
      node.properties = {
        href: "https://example.com",
      };
    }
  }
},

from react-md-editor.

bardic avatar bardic commented on June 20, 2024

Codesandbox of the problem:

https://codesandbox.io/p/sandbox/uiwjs-react-md-editor-issues-366-forked-3qx3l7?file=%2Findex.js

from react-md-editor.

bardic avatar bardic commented on June 20, 2024

For completeness sake, here's what I've settled with after some tweaking

rehypeRewrite,
{
  rewrite: (node: any, index: any, parent: any) => {
    if (node.type === "element" && node.tagName != "a") {
      let text = getCodeString(node.children);
      let m;
      let parts: any[] = [];
      if (REG.test(text)) {
        m = text.split(" ") 

        for (let element of m) {
          if (REG.test(element)) {
            parts.push(
              {
                type: "element",
                tagName: "a",
                properties: {
                  href: "https://google.ca",
                },
                children: [{ type: "text", value: " " + element + " " }],
              })
          } else {
            parts.push(
              {
                type: 'element',
                tagName: 'span',
                properties: {},
                children: [
                  { type: 'text', value: element }
                ]
              })
          }
        }
      }
      console.log(parts)
      if (parts.length > 0) {
        node.children = parts;
      }
    }
  },
}

from react-md-editor.

Related Issues (20)

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.