How to use the html-react-parser.domToReact function in html-react-parser

To help you get started, we’ve selected a few html-react-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github progital / gatsby-wpgraphql-inline-images / src / contentParser.js View on Github external
domNode,
        'attribs[data-gts-swapped-href]',
        null
      );

      // replaces local links with  element
      if (
        domNode.name === 'a' &&
        !wasLinkProcessed &&
        elementUrlNoProtocol.includes(wordPressUrlNoProtocol) &&
        !elementUrlNoProtocol.includes(uploadsUrlNoProtocol)
      ) {
        let url = urlParsed.path();
        return (
          
            {domToReact(domNode.children, parserOptions)}
          
        );
      }

      // cleans up internal processing attribute
      if (wasLinkProcessed) {
        delete domNode.attribs['data-gts-swapped-href'];
      }

      // data passed from sourceParser
      const fluidData =
        domNode.name === 'img' &&
        getByPath(domNode, 'attribs[data-gts-encfluid]', null);

      if (fluidData) {
        const fluidDataParsed = JSON.parse(fluidData);
github xtremespb / zoia2 / modules / pages / frontend / components / user / PageView.jsx View on Github external
replace: domNode => {
                            if (domNode.name === 'a' && domNode.attribs && domNode.attribs.href) {
                                return (
                                    {domToReact(domNode.children)}
                                );
                            }
                            return null;
                        }
                    });
github andrewscwei / aristotl / src / components / RichText.tsx View on Github external
replace: (node) => {
        if (node.name !== 'a' || node.type !== 'tag' || !node.children) return undefined;

        const href = _.get(node, 'attribs.href');

        if (!href) return undefined;

        if (href.startsWith('/#def-')) {
          const matches = href.match(/\/#def-(.*)/);
          const docId = _.get(matches, '1');

          if (!docId) return undefined;

          return (
            <a>{domToReact(node.children)}</a>
          );
        }
        else if (href.startsWith('/#')) {
          const matches = href.match(/\/#(.*)/);
          const docId = _.get(matches, '1');
          if (!docId) return undefined;

          return (
            <a>{domToReact(node.children)}</a>
          );
        }
      },
    });

html-react-parser

HTML to React parser.

MIT
Latest version published 1 month ago

Package Health Score

91 / 100
Full package analysis