How to use the hexo-util.escapeHTML function in hexo-util

To help you get started, we’ve selected a few hexo-util 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 hexojs / hexo / lib / plugins / helper / open_graph.js View on Github external
let description = options.description || page.description || page.excerpt || content || config.description;
  let keywords = page.keywords || (page.tags && page.tags.length ? page.tags : undefined) || config.keywords;
  const title = options.title || page.title || config.title;
  const type = options.type || (this.is_post() ? 'article' : 'website');
  let url = options.url || this.url;
  const siteName = options.site_name || config.title;
  const twitterCard = options.twitter_card || 'summary';
  const date = options.date !== false ? options.date || page.date : false;
  const updated = options.updated !== false ? options.updated || page.updated : false;
  let language = options.language || page.lang || page.language || config.language;
  const author = options.author || config.author;

  if (!Array.isArray(images)) images = [images];

  if (description) {
    description = escapeHTML(stripHTML(description).substring(0, 200)
      .trim() // Remove prefixing/trailing spaces
    ).replace(/\n/g, ' '); // Replace new lines by spaces
  }

  if (!images.length && content) {
    images = images.slice();

    if (content.includes(']*src=['"]([^'"]+)([^>]*>)/gi;
      while ((img = imgPattern.exec(content)) !== null) {
        images.push(img[1]);
      }
    }

  }
github hexojs / hexo / test / scripts / helpers / toc.js View on Github external
it('escape unsafe class name', () => {
    const className = 'f"b';
    const esClass = escapeHTML(className);
    const input = '<h1>bar</h1>';

    const expected = [
      `<ol class="${esClass}">`,
      `<li class="${esClass}-item ${esClass}-level-1">`,
      `<a class="${esClass}-link"><span class="${esClass}-text">bar</span></a>`,
      '</li></ol>'
    ].join('');

    toc(input, { list_number: false, class: className }).should.eql(expected);
  });
github hexojs / hexo-renderer-marked / test / index.js View on Github external
'# Hello world',
      '',
      '```',
      code,
      '```',
      '',
      '## Hello world',
      '',
      'hello'
    ].join('\n');

    const result = await r({text: body});

    result.should.eql([
      '<h1 id="Hello-world"><a title="Hello world" class="headerlink" href="#Hello-world"></a>Hello world</h1>',
      '<pre><code>' + escapeHTML(code) + '</code></pre>',
      '<h2 id="Hello-world-1"><a title="Hello world" class="headerlink" href="#Hello-world-1"></a>Hello world</h2>',
      '<p>hello</p>'
    ].join('') + '\n');
  });
github hexojs / hexo / lib / plugins / tag / code.js View on Github external
module.exports = ctx =&gt; function codeTag(args, content) {
  let arg = args.join(' ');
  const config = ctx.config.highlight || {};
  let enable = config.enable;

  if (rHighlight.test(arg)) {
    arg = arg.replace(rHighlight, (match, _enable) =&gt; {
      enable = _enable === 'true';
      return '';
    });
  }

  if (!enable) {
    content = escapeHTML(content);
    return `<pre><code>${content}</code></pre>`;
  }

  content = stripIndent(content);

  content = highlight(content, getHighlightOptions(config, arg));

  content = content.replace(/{/g, '{')
    .replace(/}/g, '}');

  return content;
};
github ppoffice / hexo-theme-icarus / layout / misc / open_graph.jsx View on Github external
googlePlus,
            facebookAdmins,
            facebookAppId
        } = this.props;
        let {
            description,
            language,
            images,
            keywords,
            twitterId
        } = this.props;

        const htmlTags = [];

        if (description) {
            description = escapeHTML(stripHTML(description).substring(0, 200).trim())
                .replace(/\n/g, ' ');
            htmlTags.push();
        }

        htmlTags.push();
        htmlTags.push();
        htmlTags.push();
        htmlTags.push();

        if (description) {
            htmlTags.push();
        }

        if (language) {
            if (language.length === 2) {
                language = language.replace(localeRegex, str =&gt; localeMap[str]);