How to use the html-entities.Html5Entities function in html-entities

To help you get started, we’ve selected a few html-entities 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 jschr / vscodethemes / backend / api / tokenize.ts View on Github external
import { Services } from '@vscodethemes/types'
import { Html5Entities } from 'html-entities'
import * as qs from 'querystring'
import * as stripComments from 'strip-json-comments'
import { BadRequestError, HttpError } from '../errors'

// Cache for a day.
export const cacheAge = 60 * 60 * 24

const entities = new Html5Entities()
const supportLanguages = ['javascript', 'css', 'html']

function addCorsHeaders(response: any) {
  response.headers = response.headers || {}
  response.headers['Access-Control-Allow-Origin'] = '*'
  response.headers['Access-Control-Allow-Methods'] = 'GET'
  response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
}

export default async function run(
  services: Services,
  event: any,
): Promise {
  const { fetch, logger, reportError, tokenizer } = services
  const request = event.Records[0].cf.request
  const response = event.Records[0].cf.response
github pmmmwh / react-refresh-webpack-plugin / src / overlay / components / CompileErrorTrace.js View on Github external
const ansiHTML = require('ansi-html');
const { Html5Entities } = require('html-entities');
const theme = require('../theme');
const formatFilename = require('../utils/formatFilename');

ansiHTML.setColors(theme);

const entities = new Html5Entities();

/**
 * @typedef {Object} CompileErrorTraceProps
 * @property {string} errorMessage
 */

/**
 * A formatter that turns Webpack compile error messages into highlighted HTML source traces.
 * @param {Document} document
 * @param {HTMLElement} root
 * @param {CompileErrorTraceProps} props
 * @returns {void}
 */
function CompileErrorTrace(document, root, props) {
  const errorParts = props.errorMessage.split('\n');
  const errorMessage = errorParts
github jschr / vscodethemes / frontend / components / ThemePreview / Code.tsx View on Github external
interface CodeProps {
  tokens: LineToken[][]
  editorForeground: string
}

const styles = {
  code: css({
    position: 'relative',
    height: '100%',
    padding: rem(theme.gutters.sm),
    fontFamily: theme.fonts.monospace,
  }),
}

const entities = new Html5Entities()

const viewbox = [354, 200]
const fontSize = 10
const lineHeight = 14.5

const Code: React.SFC = ({ tokens, editorForeground }) => {
  const texts: React.ReactNode[] = []

  tokens.forEach((lineTokens, lineIndex) => {
    const tspans: React.ReactNode[] = []

    lineTokens.forEach((styleToken, tokenIndex) => {
      if (!styleToken.token) {
        return
      }
github martijnversluis / ChordSheetJS / src / formatter / html_entities_encode.js View on Github external
export default function htmlEntitiesEncode(data) {
  const encoder = new Html5Entities();
  return encoder.encode(data);
}
github headless-ninja / hn-react-webform / src / Parser / index.js View on Github external
import Parser from 'react-html-parser';
import { Html5Entities } from 'html-entities';
import template from './template';

const entities = new Html5Entities();

export default function (string) {
  const decoded = entities.decode(string);
  return Parser(decoded);
}

export { template };
github tiffany352 / twitter-archive-browser / src / components / Tweet.js View on Github external
const formattedText = segmenter.array.map((segment, index) => {
    const text = data.full_text.slice(segment.start, segment.end + 1)
    switch (segment.value.style) {
      case 'normal':
        return (
          <span>
            {new Html5Entities().decode(text)}
          </span>
        )
      case 'link':
        return (
          {segment.value.display}
        )
      case 'hide':
      default:
        return null
    }
  })