How to use he - 10 common examples

To help you get started, we’ve selected a few he 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 jfhbrook / node-ecstatic / lib / ecstatic / show-dir / index.js View on Github external
const writeRow = (file) => {
            // render a row given a [name, stat] tuple
            const isDir = file[1].isDirectory && file[1].isDirectory();
            let href = `${parsed.pathname.replace(/\/$/, '')}/${encodeURIComponent(file[0])}`;

            // append trailing slash and query for dir entry
            if (isDir) {
              href += `/${he.encode((parsed.search) ? parsed.search : '')}`;
            }

            const displayName = he.encode(file[0]) + ((isDir) ? '/' : '');
            const ext = file[0].split('.').pop();
            const classForNonDir = supportedIcons[ext] ? ext : '_page';
            const iconClass = `icon-${isDir ? '_blank' : classForNonDir}`;

            // TODO: use stylessheets?
            html += `${'' +
              '<i class="icon '}${iconClass}"></i>`;
            if (!hidePermissions) {
              html += `<code>(${permsToString(file[1])})</code>`;
            }
            html +=
              `<code>${sizeToString(file[1], humanReadable, si)}</code>` +
              `<a href="${href}">${displayName}</a>` +
github opencollective / opencollective-api / server / lib / email.js View on Github external
const render = (template, data) => {
  let text;
  data.imageNotSvg = data.collective && data.collective.image && !data.collective.image.endsWith('.svg');
  data = merge({}, data);
  delete data.config;
  data.config = { host: config.host };

  // sets paypalEmail for purpose of email templates
  if (data.user) {
    data.user.paypalEmail = data.user.paypalEmail || data.user.email;
  }

  if (templates[`${template}.text`]) {
    text = templates[`${template}.text`](data);
  }
  const html = juice(he.decode(templates[template](data)));

  // When in development mode, we log the data used to compile the template
  // (useful to get login token without sending an email)
  debugLib('data')(`Rendering ${template} with data`, data);

  return { text, html };
};
github Bright-Tech / Yii2-Ace-Admin / js / markdown / to-markdown.js View on Github external
string = string.replace(/]*&gt;`([\s\S]*?)`&lt;\/pre&gt;/gi, function(str, innerHTML) {
    var text = he.decode(innerHTML);
    text = text.replace(/^\t+/g, '  '); // convert tabs to spaces (you know it makes sense)
    text = text.replace(/\n/g, '\n    ');
    return '\n\n    ' + text + '\n';
  });
github DIYgod / RSSHub / lib / middleware / parameter.js View on Github external
'Cache-Control': `public, max-age=${config.cache.routeExpire * 100}`,
        });
        throw Error('wrong path');
    }

    if (ctx.state.data) {
        if ((!ctx.state.data.item || ctx.state.data.item.length === 0) &amp;&amp; !ctx.state.data.allowEmpty) {
            throw Error('this route is empty, please check the original site or <a href="https://github.com/DIYgod/RSSHub/issues/new/choose">create an issue</a>');
        }

        // fix allowEmpty
        ctx.state.data.item = ctx.state.data.item || [];

        // decode HTML entities
        ctx.state.data.title &amp;&amp; (ctx.state.data.title = he.decode(ctx.state.data.title + ''));
        ctx.state.data.description &amp;&amp; (ctx.state.data.description = he.decode(ctx.state.data.description + ''));

        // sort items
        ctx.state.data.item = ctx.state.data.item.sort((a, b) =&gt; +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));

        ctx.state.data.item.forEach((item) =&gt; {
            item.title &amp;&amp; (item.title = he.decode(item.title + ''));

            // handle pubDate
            if (item.pubDate) {
                item.pubDate = new Date(item.pubDate).toUTCString();
            }

            // handle link
            if (item.link) {
                let baseUrl = ctx.state.data.link;
                if (baseUrl &amp;&amp; !baseUrl.match(/^https?:\/\//)) {
github F1LT3R / ansi-to-svg / index.js View on Github external
const yOffset = font.height * 0.3
			const ys = y - yOffset
			const xw = x + w
			const d = `M${x},${ys} L${xw},${ys} Z`
			const color = foregroundColor || baseForegroundColor
			content += decorators.path({d, color})
		}

		const attrStr = attrs.join(' ')

		// Do not output elements containing whitespace with no style
		if (value.replace(/ /g, '').length === 0 && attrStr.length === 0) {
			return
		}

		const entified = he.encode(value, {decimal: false})
		content += decorators.text({
			value: entified,
			x, y, fontStyle, attrStr
		})
	})
github voltraco / mineral / compilers / html.js View on Github external
// if this attribute is a boolean, make its value its key
        if (typeof value === 'boolean') {
          return [key, '=', `"${key}"`].join('')
        }

        if (value) {
          // all values are expressions
          value = common.scopedExpression(data, locationData, value)

          // a class should not be empty
          if (key === 'class' && !value) return ''

          // data-* attributes should be escaped
          if (key.indexOf('data-') === 0) {
            if (typeof value !== 'string' && typeof value !== 'number') {
              value = he.escape(JSON.stringify(value) + '')
            } else {
              value = '"' + value + '"'
            }
          } else {
            value = JSON.stringify(value)
          }
        }
        return [key, '=', value].join('')
      })
      attrs = attrs.filter(a => !!a)
github propelml / propel / website / nb.tsx View on Github external
function createIframe(rpcChannelId): HTMLIFrameElement {
  const base = new URL("/sandbox", window.document.baseURI).href;
  const html = `
    
      
        
        
        
        
      
      
      
    `;

  const iframe = document.createElement("iframe");
  iframe.setAttribute("sandbox", "allow-scripts");
  iframe.setAttribute("srcdoc", `${html}`);
  // Edge doesn't support "srcdoc", it'll use a data url instead.
  iframe.setAttribute("src", `data:text/html,${html}`);
  iframe.style.display = "none";
  document.body.appendChild(iframe);

  return iframe;
github microsoft / BotFramework-WebChat / built / FormattedText.js View on Github external
return '';
            });
            if (text.length == 0)
                break;
            // Consume leak sequences until string end or an id sequence is encountered
            var next = text.indexOf('{{');
            while (next > 0) {
                var subst = text.substr(0, next);
                subst = He.unescape(subst);
                elements.push(React.createElement("span", { key: this.key++ }, subst));
                text = text.substr(next);
                next = text.indexOf('{{');
            }
            // Return remainder leak sequence
            if (len == text.length) {
                text = He.unescape(text);
                elements.push(React.createElement("span", { key: this.key++ }, text));
                break;
            }
        }
        return elements.filter(function (el) { return !!el; });
    };
    /// MarkedRenderer overrides
github microsoft / BotFramework-WebChat / built / FormattedText.js View on Github external
while (true) {
            var len = text.length;
            // Consume elementIds until string end or a leak sequence is encountered
            text = text.replace(re, function (match) {
                var index = Number(match.match(/\d+/)[0]);
                elements.push(_this.elements[index]);
                _this.elements[index] = null;
                return '';
            });
            if (text.length == 0)
                break;
            // Consume leak sequences until string end or an id sequence is encountered
            var next = text.indexOf('{{');
            while (next > 0) {
                var subst = text.substr(0, next);
                subst = He.unescape(subst);
                elements.push(React.createElement("span", { key: this.key++ }, subst));
                text = text.substr(next);
                next = text.indexOf('{{');
            }
            // Return remainder leak sequence
            if (len == text.length) {
                text = He.unescape(text);
                elements.push(React.createElement("span", { key: this.key++ }, text));
                break;
            }
        }
        return elements.filter(function (el) { return !!el; });
    };
    /// MarkedRenderer overrides
github philipwalton / blog / tasks / utils / markdown.js View on Github external
highlight: function(code, lang) {
      // TODO(philipwalton): come up with a better way to do code marking.
      let mark = true;
      if (lang.includes(':no-mark')) {
        mark = false;
        lang = lang.replace(':no-mark', '');
      }

      code = lang ? hljs.highlight(lang, code).value :
          // Since we're not using highlight.js here, we need to
          // espace the html, but we have to unescape first in order
          // to avoid double escaping.
          he.escape(he.unescape(code));

      // Allow for highlighting portions of code blocks
      // using `**` before and after
      if (mark) {
        code = code.replace(/\*\*(.+)?\*\*/g, '<mark>$1</mark>');
      }

      return code;
    },
  }).use(markdownItAnchor);

he

A robust HTML entities encoder/decoder with full Unicode support.

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis