How to use hast-util-sanitize - 4 common examples

To help you get started, we’ve selected a few hast-util-sanitize 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 benawad / codeponder / packages / web / modules / post / shared / MarkdownEditor / MarkdownRenderer.tsx View on Github external
import { getHighlightedCode } from "../../../../utils/highlightCode";

const HighlightCode = ({ children }: { children: string }): JSX.Element => {
  try {
    const { value, lang, meta } = JSON.parse(children);
    return <code>{getHighlightedCode(value, lang, parseInt(meta))}</code>;
  } catch (ex) {
    return <code>{children}</code>;
  }
};

const sanitize = {
  ...schema,
  attributes: {
    ...schema.attributes,
    a: [...schema.attributes.a, ["class", "ping ping-link"]],
  },
};

const setCodeProps = (): ((ast: Node[]) =&gt; void) =&gt; {
  return (ast: Node[]): void =&gt;
    visit(
      ast,
      "code",
      (node: Node): void =&gt; {
        const { lang, meta, value } = node;
        node.value = JSON.stringify({ value, lang, meta });
      }
    );
};

const MarkdownContainer = styled("div")`
github benawad / codeponder / packages / web / modules / post / shared / MarkdownEditor / MarkdownRenderer.tsx View on Github external
import visit from "unist-util-visit";
import { getHighlightedCode } from "../../../../utils/highlightCode";

const HighlightCode = ({ children }: { children: string }): JSX.Element =&gt; {
  try {
    const { value, lang, meta } = JSON.parse(children);
    return <code>{getHighlightedCode(value, lang, parseInt(meta))}</code>;
  } catch (ex) {
    return <code>{children}</code>;
  }
};

const sanitize = {
  ...schema,
  attributes: {
    ...schema.attributes,
    a: [...schema.attributes.a, ["class", "ping ping-link"]],
  },
};

const setCodeProps = (): ((ast: Node[]) =&gt; void) =&gt; {
  return (ast: Node[]): void =&gt;
    visit(
      ast,
      "code",
      (node: Node): void =&gt; {
        const { lang, meta, value } = node;
        node.value = JSON.stringify({ value, lang, meta });
      }
    );
};
github popcodeorg / popcode / src / util / markdown.js View on Github external
const remarkWithHighlighting = memoize(() => {
  const schema = Object.assign({}, githubSchema, {
    attributes: Object.assign({}, githubSchema.attributes, {
      code: [...(githubSchema.attributes.code || []), 'className'],
    }),
  });

  return remark()
    .use(externalLinks)
    .use(remarkReact, {
      sanitize: schema,
      remarkReactComponents: {
        code: remarkLowlight({css, js, xml}),
      },
    });
});
github popcodeorg / popcode / src / util / markdown.js View on Github external
const remarkWithHighlighting = memoize(() => {
  const schema = Object.assign({}, githubSchema, {
    attributes: Object.assign({}, githubSchema.attributes, {
      code: [...(githubSchema.attributes.code || []), 'className'],
    }),
  });

  return remark()
    .use(externalLinks)
    .use(remarkReact, {
      sanitize: schema,
      remarkReactComponents: {
        code: remarkLowlight({css, js, xml}),
      },
    });
});

hast-util-sanitize

hast utility to sanitize nodes

MIT
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis

Popular hast-util-sanitize functions