How to use the @contentful/rich-text-types.INLINES.ENTRY_HYPERLINK function in @contentful/rich-text-types

To help you get started, we’ve selected a few @contentful/rich-text-types 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 connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.spec.js View on Github external
it('should render an entry hyperlink override', () => {
      const overrides = {
        [INLINES.ENTRY_HYPERLINK]: { page: Override }
      };
      const actual = RichTextService.entryNodeToJsx(entryHyperlink, {
        ...options,
        overrides
      });
      expect(actual).toMatchSnapshot();
    });
github connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.js View on Github external
[BLOCKS.PARAGRAPH]: 'p',
  [BLOCKS.UL_LIST]: 'ul',
  [BLOCKS.OL_LIST]: 'ol',
  [BLOCKS.LIST_ITEM]: 'li',
  [BLOCKS.QUOTE]: 'blockquote',
  [BLOCKS.HR]: 'hr',
  [INLINES.HYPERLINK]: 'a',
  [MARKS.BOLD]: 'strong',
  [MARKS.ITALIC]: 'em',
  [MARKS.UNDERLINE]: 'u',
  [MARKS.CODE]: 'code'
};

const entryMap = {
  [BLOCKS.EMBEDDED_ENTRY]: true,
  [INLINES.ENTRY_HYPERLINK]: true,
  [INLINES.EMBEDDED_ENTRY]: true
};

const assetMap = {
  [BLOCKS.EMBEDDED_ASSET]: true,
  [INLINES.ASSET_HYPERLINK]: true
};

function isEntryNode(node) {
  return entryMap[node.nodeType];
}

function isAssetNode(node) {
  return assetMap[node.nodeType];
}
github contentful / rich-text / packages / rich-text-react-renderer / src / index.tsx View on Github external
  [INLINES.ENTRY_HYPERLINK]: node => defaultInline(INLINES.ENTRY_HYPERLINK, node as Inline),
  [INLINES.EMBEDDED_ENTRY]: node => defaultInline(INLINES.EMBEDDED_ENTRY, node as Inline),
github connor-baer / rich-text-to-jsx / src / __fixtures__ / index.js View on Github external
}
};

export const entryHyperlink = {
  data: {
    target: entry
  },
  content: [
    {
      data: {},
      marks: [],
      value: 'This is a link to an entry.',
      nodeType: 'text'
    }
  ],
  nodeType: INLINES.ENTRY_HYPERLINK
};

export const embeddedEntryInline = {
  data: {
    target: entry
  },
  content: [],
  nodeType: INLINES.EMBEDDED_ENTRY
};

export const embeddedEntryBlock = {
  data: {
    target: entry
  },
  content: [],
  nodeType: BLOCKS.EMBEDDED_ENTRY
github contentful / rich-text / packages / rich-text-html-renderer / src / index.ts View on Github external
const defaultNodeRenderers: RenderNode = {
  [BLOCKS.PARAGRAPH]: (node, next) =&gt; `<p>${next(node.content)}</p>`,
  [BLOCKS.HEADING_1]: (node, next) =&gt; `<h1>${next(node.content)}</h1>`,
  [BLOCKS.HEADING_2]: (node, next) =&gt; `<h2>${next(node.content)}</h2>`,
  [BLOCKS.HEADING_3]: (node, next) =&gt; `<h3>${next(node.content)}</h3>`,
  [BLOCKS.HEADING_4]: (node, next) =&gt; `<h4>${next(node.content)}</h4>`,
  [BLOCKS.HEADING_5]: (node, next) =&gt; `<h5>${next(node.content)}</h5>`,
  [BLOCKS.HEADING_6]: (node, next) =&gt; `<h6>${next(node.content)}</h6>`,
  [BLOCKS.EMBEDDED_ENTRY]: (node, next) =&gt; `<div>${next(node.content)}</div>`,
  [BLOCKS.UL_LIST]: (node, next) =&gt; `<ul>${next(node.content)}</ul>`,
  [BLOCKS.OL_LIST]: (node, next) =&gt; `<ol>${next(node.content)}</ol>`,
  [BLOCKS.LIST_ITEM]: (node, next) =&gt; `<li>${next(node.content)}</li>`,
  [BLOCKS.QUOTE]: (node, next) =&gt; `<blockquote>${next(node.content)}</blockquote>`,
  [BLOCKS.HR]: () =&gt; '<hr>',
  [INLINES.ASSET_HYPERLINK]: node =&gt; defaultInline(INLINES.ASSET_HYPERLINK, node as Inline),
  [INLINES.ENTRY_HYPERLINK]: node =&gt; defaultInline(INLINES.ENTRY_HYPERLINK, node as Inline),
  [INLINES.EMBEDDED_ENTRY]: node =&gt; defaultInline(INLINES.EMBEDDED_ENTRY, node as Inline),
  [INLINES.HYPERLINK]: (node, next) =&gt; `<a href="${node.data.uri}">${next(node.content)}</a>`,
};

const defaultMarkRenderers: RenderMark = {
  [MARKS.BOLD]: text =&gt; `<b>${text}</b>`,
  [MARKS.ITALIC]: text =&gt; `<i>${text}</i>`,
  [MARKS.UNDERLINE]: text =&gt; `<u>${text}</u>`,
  [MARKS.CODE]: text =&gt; `<code>${text}</code>`,
};

const defaultInline = (type: string, node: Inline) =&gt;
  `<span>type: ${type} id: ${node.data.target.sys.id}</span>`;

export type CommonNode = Text | Block | Inline;
github boylesoftware / stacy / lib / stacy-runtime.js View on Github external
}
  }
  templatesEngine.registerHelper("markdown", markdownHelper);

  //////////////////////////////////////////////////////////////////////////////
  const documentToHtmlStringOptions = {
    renderNode: {
      [BLOCKS.EMBEDDED_ASSET]: node =&gt; assetHelper(node.data.target),
      [INLINES.ASSET_HYPERLINK]: node =&gt; (
        `<a href="${assetSrcHelper(node.data.target)}">` +
        `${documentToHtmlString(node, documentToHtmlStringOptions)}` +
        `</a>`
      ),
      [BLOCKS.EMBEDDED_ENTRY]: node =&gt; moduleHelper(node.data.target),
      [INLINES.EMBEDDED_ENTRY]: node =&gt; moduleHelper(node.data.target),
      [INLINES.ENTRY_HYPERLINK]: () =&gt; ""
    }
  };
  function richTextHelper(document) {
    if (!document.nodeType || document.nodeType !== "document") {
      throw new Error("Invalid template: helper \"richText\" was passed" +
        " an invalid rich text document.");
    }
    return documentToHtmlString(document, documentToHtmlStringOptions);
  }
  templatesEngine.registerHelper("richText", richTextHelper);

  //////////////////////////////////////////////////////////////////////////////
  templatesEngine.registerHelper("json", function(data) {
    return JSON.stringify(data, null, "  ");
  });
}
github storybynumbers / rich-text-to-react / src / index.js View on Github external
  [INLINES.ENTRY_HYPERLINK]: (node, key) => defaultInline(INLINES.ENTRY_HYPERLINK, node, key),
  [INLINES.EMBEDDED_ENTRY]: (node, key) => defaultInline(INLINES.EMBEDDED_ENTRY, node, key),