Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
}
export default function htmlEntitiesEncode(data) {
const encoder = new Html5Entities();
return encoder.encode(data);
}
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 };
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
}
})