Esempio n. 1
0
     }, function(error, response, body) {
         var matches = body.match(/\<span id=result_box(.*?)\<\/span><\/div>/g);
         var translation = matches[0];
         translation = entities.decode(translation);
         translation = striptags(translation);
         callback(translation);
 });
Esempio n. 2
0
 csv.transform(data, function(row) {
   var key, value;
   for (key in row) {
     value = row[key].replace(/<b>|<\/b>/g, '');
     row[key] = entities.decode(value, 2);
   }
   return row;
 }, callback.bind(this));
Esempio n. 3
0
 nodes.each(function () {
   var node = $(this)
   if (output.break) {
     node.html(node.html().replace(/<br[^\/>]*\/?>/ig, '\\n'))
   }
   var txt = node.text().trim()
   if (output.stripSpaces) {
     txt = txt.replace(/\s(\s+)/g, ' ').replace(/[\r\t]/g, '').replace(/\n(\n+)/g, '\\n')
   }
   text += (options.forceDecode ? entities.decode(txt) : txt) + ' '
 })
Esempio n. 4
0
    }, function(error, response, body) {
        var matches = body.match(/\<span id=result_box(.*?)\<\/span><\/div>/g);
        var translation = matches[0];
        translation = entities.decode(translation);
        translation = striptags(translation);

        /*var $ = cheerio.load(body);
        var translation = $("#result_box").text();*/
        opts.french[opts.prop] = translation;
        callback(translation, opts.french);
    });
			rss.forEach(function(item) {
				var description = cheerio.load(entities.decode(item.description));
				
				if(typeof description('p ul li')[0] == 'undefined')
					return;
							
				response += '<tr>';
				response += '<td style="line-height: 50%; padding: 5px 10px 3px 10px;">';
				response += 	'<div style="font-size: 14px; color: rgba(255, 255, 255, 0.7);">' + description('a')[1].children[0].data + '&nbsp;&nbsp;&nbsp;&nbsp;' + description('a')[0].children[0].data + '</div>';
				response += 	'<div style="font-size: 20px;">' + description('p ul li')[0].children[0].data.split(' - ')[1] + '</div>';
				response += '</td>';
				response += '</tr>';
			});
Esempio n. 6
0
 html: function ($, nodes, output, options) {
   var html = nodes.html()
   // strip tab symbols(\r\t\n)
   if (output.stripSpaces) {
     html = html.replace(/([\r\t\n]+)/g, ' ')
   }
   html = options.forceDecode ? entities.decode(html) : html
   if (options.tidyAttrs) {
     try {
       html = html.replace(/<([a-z][a-z0-9]*)(?:[^>]*(\s(?:src|href)=['\"][^'\"]*['\"]))?[^>]*?(\/?)>/ig, '<$1$2$3>')
     } catch (err) {}
   }
   return html
 },
Esempio n. 7
0
function analysis(string) {
    var all = string.match(reg),
        ret = [];
    if (all) {
        for (var i = 0; i < all.length; i++) {
            var content = reg.exec(all[i]);

            if (content) {
                content = _trim(content[3]);
                content = entities.decode(content, 0);
                content = entities.decode(content, 1);
                content = entities.decode(content, 2);

                for (var j = 0; j < repList.length; j++) {
                    content = content.replace(repList[j][0], repList[j][1]);
                }
                ret.push(content);
            }
        }

    }
    return ret;
}
	var smart_quote = function(match, name, equals, value) {
		if (!equals) { return match; }
		var decoded = entities.decode(value, 2);
		// try re-encoding with single-quotes escaped
		var encoded = decoded.replace(/[&'\u00A0]/g, function(c) {
			switch(c) {
			case '&': return '&amp;';
			case "'": return '&#39;';
			case '\u00A0': return '&nbsp;';
			}
		});
		if (encoded.length >= value.length) { return match; /* no change */ }
		return ' '+name+"='"+encoded+"'";
	};
Esempio n. 9
0
toc.anchor = function(s) {
  var slug = require('slug');
  var entities = require('entities');

  s = toc.untag(s);
  s = s.toLowerCase();
  s = entities.decode(s);
  s = s.replace(/['"!]|[\.]+$/g, '');
  s = slug(s);
  s = s.replace(/[:\(\)]+/gi, '-');
  s = s.replace(/[\s\-]*([\.])[\s\-]*/g, '$1');
  s = s.replace(/-+/g, '-');
  s = s.replace(/^-+|-+$/g, '');
  return s;
};
Esempio n. 10
0
        res.on('end', function () {
            var pos, pos2, title;

            pos = data.indexOf('<title>');
            if (pos !== -1) {
                pos2 = data.indexOf('</title>', pos);
                if (pos2 !== -1) {
                    title = data.substr(pos + 7, pos2 - (pos + 7));
                    // decode HTML entities
                    title = entities.decode(title, 2);
                    callback(title);
                } else {
                    callback(false);
                }
            } else {
                callback(false);
            }
        });
Esempio n. 11
0
    parse: function(dom, node, textFormat){
        var out;

        this.textFormat = (textFormat)? textFormat : this.textFormat;
        if(this.textFormat === 'normalised'){
            out = this.walkTreeForText( dom, node );
            if(out !== undefined){
                out = out.replace( /&nbsp;/g, ' ') ;    // exchanges html entity for space into space char
                out = utils.removeWhiteSpace( out );    // removes linefeeds, tabs and addtional spaces
                out = entities.decode( out, 2 );        // decode HTML entities
                out = out.replace( '–', '-' );          // correct dash decoding
                return utils.trim( out );
            }else{
                return undefined;
            }
        }else{
           return dom(node).text(); 
        }
    },
Esempio n. 12
0
		foundPost: function(data) {
			if (! data.title || ! data.url) {
				// console.log('no title or url');
				return;
			}

			data.title = entities.decode(RSSParser.trimChars(data.title));
			data.url = RSSParser.trimChars(data.url);

			// If not http or https is present, or some other weird protocol, just assume it's relative
			if (! data.url.match(/^(http|https):/) && ! data.url.match(/^[a-zA-Z0-9-]+:/)) {
				var domain = this.getDomain(this.path);
				data.url = RSSParser.trimChars(domain, '/') + data.url;
			}

			if (this.fixes.noGUID) {
				delete data.guid;
			}

			this.posts.push(data);
		},
Esempio n. 13
0
router.post('/typeset', function(req, res) {

  if (req.body.token !== SLACK_AUTH_TOKEN)
  {
    log.warn('Unrecongized or no token:',req.body.token);
    res.status(401).send();
    return;
  }

  var requestString = entities.decode(req.body.text);

  log.info('Request:',requestString);

  var typesetPromise = typeset.typeset(requestString, '');

  if (typesetPromise === null) {
    res.send('no text found to typeset');
    res.end(); 
    return;
  }

  var promiseSuccess = function(mathObjects) {
    var locals = {'mathObjects': mathObjects,
      'serverAddress': `http://${SERVER}/` }; // :${PORT}
    var htmlResult = pug.renderFile('./views/slack-response.pug', locals);
    res.json({'text' : htmlResult});
    res.end();
  };

  var promiseError = function(error) {
    log.info('Error in typesetting:');
    log.info(error);
    res.end(); // Empty 200 response.
  };

  typesetPromise.then(promiseSuccess, promiseError);

});
Esempio n. 14
0
    parse: function(dom, node){
      var out;
      // only take nodes not nodeLists
      if(node.length){
          node = node[0];
      }

      this.dom = dom;

      // find base tag to set baseUrl
      var baseTag = dom('base');
      if(baseTag.length > 0) {
        href = this.getAttribute(dom, baseTag, 'href');
        if(href){
          this.baseUrl = href;
        }
      }


      out = this.walkTreeForText( node );

      if(out !== undefined){
          out = out.replace( /&nbsp;/g, ' ');
          out = out.replace( '–', '-' ); 
          out = entities.decode( out, 2 );
          out = this.removeStartingWhitespace( out );
          if(this.options.collapsesLines){
            out = this.removeEmtpyLines(out);
          }
          out = utils.trim( out );
          return out;
      }else{
          return undefined;
      }
     
    },
Esempio n. 15
0
exports.decode = function(str) { return entities.decode(str, 2); };
Esempio n. 16
0
router.post('/slashtypeset', function(req, res) {

  if (req.body.token !== SLACK_AUTH_TOKEN)
  {
    log.warn('Unrecongized or no token:',req.body.token);
    res.status(401).send();
    return;
  }

  var requestString = entities.decode(req.body.text);

  var typesetPromise = typeset.typeset(requestString,'');

  if (typesetPromise === null) {
    res.send('no text found to typeset');
    res.end(); // Empty 200 response -- no text was found to typeset.
    return;
  }
  log.info("Recieved: " + JSON.stringify(req.body));
  var promiseSuccess = function(mathObjects) {
    var imgurl = 'http://' + SERVER + '/'+ mathObjects[0].output
      /*
    var post_data = {
      token: TOKEN,
      //token: req.body.token,
      channel: req.body.channel_id,
      //as_user: req.body.user_id,
      as_user: true,
      text: requestString, //"hello world",
      ts: req.ts,
      attachments: JSON.stringify([ { fallback: requestString, image_url: imgurl } ])
    };
    var curl = "https://slack.com/api/chat.update?" + querystring.stringify(post_data)

    fetch(curl).then(function(res) {
        log.info('Response: ' + res.ok);
        log.info('Response.error: ' + res.error);
    }); */


    res.json({
      response_type: 'in_channel',
      text: req.body.user_name + ":",
      replace_original: true,
      attachments: [
        {
          fallback: requestString,
          image_url: imgurl
        },
      ],
    });
    res.end();
  };

  var promiseError = function(error) {
    log.info('Error in typesetting:');
    log.info(error);
    res.end(); // Empty 200 response.
  };

  typesetPromise.then(promiseSuccess, promiseError);

});
Esempio n. 17
0
		parseAtomResponse: function(rootElement) {
			var titleEl = rootElement.find('title').first();

			this.data.link = this.parseLink(rootElement);
			this.data.title = RSSParser.trimChars(titleEl.length ? titleEl.text() : this.data.link);
			this.data.favicon = 'chrome://favicon/' + this.getDomain(this.data.link);

			this.path = this.data.link;

			var posts = rootElement.find('entry');
			for (var i = 0, post; (post = posts[i]); i++) {
				post = this.$(post);

				var titleElement = post.find('title').first();
				var linkElements = post.find('link');
				var guidElement = this.getGuid(post);

				if (! titleElement.length || ! linkElements.length)
					continue;

				var link = this.parsePostLink(linkElements);

				var content = post.find('content,content\\:encoded').text(),
					author = post.find('author').text(),
					description = post.find('summary').text();

				var $ = cheerio.load(content.trim()),
					img = this.getImage($('img').first()),
					props = {
						title: titleElement.text() || link,
						url: this.resolveURL(link),
						published_at: this.getDate(post),
						guid: guidElement.text() || '',

						// Strip out html tags and decode html entities
						description: entities.decode(
							sanitizeHtml(description, {
								allowedTags: [],
								allowedAttributes: []
							})
						),
						author: author
					};

				if (img.url) {
					props.image = img;
				}

				if (content && content !== '') {

					$('.feedflare').remove();
					var decoded = entities.decode($.html());  // Decode html entities
					var split = splitHtml(decoded, 'div');

					if (split.length) {
						if (split.length == 1) {
							split.push('<ad></ad>')
						} else {
							split.splice(split.length / 2, 0, '<ad></ad>');
						}
					}

					props.content = split.join('');
				}

				this.foundPost(props);
			}
		},
Esempio n. 18
0
    return function(resourceURL) {
       
        resourceURL = entities.decode(resourceURL, 2);

        var result = defer(),
            makeRequest = function() {

                var options = url.parse(resourceURL, false, true);

                options.headers = {};
                //options.headers['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
                options.headers['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0';

                requests++;

                (options.protocol == 'https:' ? https : http).get(options, function(response) {

                    var buffers = [],
                        length = 0;

                    response.on('data', function(data) {

                        buffers.push(data);
                        length += data.length;
                    });

                    response.on('end', function() {

                        var data = new Buffer(length),
                            index = 0;

                        buffers.forEach(function(buffer) {

                            buffer.copy(data, index, 0, buffer.length);
                            index += buffer.length;
                        });

                        result.resolve(data);
                    });

                    response.on('close', function() {

                        error('Request for ' + resourceURL + ' closed unexpectedly.');
                        result.resolve(new Buffer(''));
                    });

                }).on('error', function(e) {

                    error('Failed to fetch ' + resourceURL + '. ' + e.message);
                    result.resolve(new Buffer(''));
                });
            };

        if(!maxRequests || requests < maxRequests)
            makeRequest();
        else
            requestQueue.push(makeRequest);

        result.promise.fin(function() {

            requests--;

            if(requestQueue.length)
                requestQueue.pop()();
        });

        return result.promise;
    };
Util.decodeEntity = function ( entity ) {
    return entities.decode(entity, 2 /* html5 entities */ );
};
Esempio n. 20
0
Article.prototype.getTitle = function () {
  // if cache exists, return it directly.
  var title
  if (typeof (title = this.caches['article-title']) !== 'undefined') { // eslint-disable-line no-cond-assign
    debug('get title from cache')
    return title
  }
  if (this.options.selectors && this.options.selectors.title) {
    debug('get title with CSS selector')
    var sel = read.selector(this.options.selectors.title, 'text')
    if (sel) {
      var node = this.$(sel.selector)
      if (!node || node.length === 0) {
        return title
      }
      title = read.extract(this.$, node, sel, this.options)
      return (this.caches['article-title'] = title) // eslint-disable-line no-return-assign
    }
  } else {
    debug('get title with Reader')
  }

  var nodeTitle = this.$('title')
  // make sure title exists.
  title = (nodeTitle && nodeTitle.length > 0 ? nodeTitle.text().trim() : '')
  if (!title) {
    debug('∟ could not extract title from article, simply returned an empty String')
    return ''
  }

  debug('∟ find a better title if necessary')
  title = entities.decode(title)

  // split title by separators.
  var betterTitleFn
  var betterTitleOp = this.options.betterTitle
  var minTitleLength = 10

  if (typeof betterTitleOp === 'function') {
    betterTitleFn = betterTitleOp
  } else if (!isNaN(betterTitleOp)) {
    minTitleLength = parseInt(betterTitleOp)
  }

  var betterTitleExist = function (t) {
    return t && t.length >= minTitleLength
  }

  if (!betterTitleFn) {
    var betterTitle = ''
    var subTitles = title.split(/[\|–—\-_«»]/g)

    // when find better title, break the loop.
    subTitles.forEach(function (t) {
      if (betterTitleExist(betterTitle)) {
        return false
      }

      t = t.trim()
      if (t) {
        betterTitle += ' ' + t
      }
    })

    // length of better title must gte 10.
    if (betterTitleExist(betterTitle)) {
      title = betterTitle.trim()
    }
    // releasing...
    betterTitleExist = null
    betterTitle = null
  } else {
    title = betterTitleFn(title) || ''
  }
  debug('∟ caching title')
  return (this.caches['article-title'] = title) // eslint-disable-line no-return-assign
}