Ejemplo n.º 1
0
 /**
  * Converts HTML to Markdown
  */
 function Markdownify($Html)
 {
     $Html = Gdn_Format::To($Html, 'xHtml');
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('input' => $Html, 'keepHTML' => 1);
     $Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
     $Doc = PqDocument($Snoopy->results);
     $Code = Pq('pre > code:eq(0)')->Text();
     $Result = $Code;
     return $Result;
 }
 /**
  * Converts HTML to Markdown
  */
 function Markdownify($Html)
 {
     if (function_exists('Debug') && Debug()) {
         trigger_error(sprintf('%s is deprecated, use HtmlToMarkdown() instead.', __FUNCTION__), E_USER_DEPRECATED);
     }
     $Html = Gdn_Format::To($Html, 'xHtml');
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('input' => $Html, 'keepHTML' => 1);
     $Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
     $Doc = PqDocument($Snoopy->results);
     $Code = Pq('pre > code:eq(0)')->Text();
     $Result = $Code;
     return $Result;
 }
Ejemplo n.º 3
0
 function RemoteHtmlToMarkdown($Html, $FormatHtml = False)
 {
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('html' => $Html, 'submit' => 1);
     $Snoopy->Submit('http://modnerd.com/html2markdown/', $Vars);
     $Doc = PqDocument($Snoopy->results, array('FixHtml' => False));
     $Result = Pq('#markdown')->Val();
     $Result = htmlspecialchars_decode($Result, ENT_QUOTES);
     // I don't have a clue why need do htmlspecialchars_decode second time
     $Result = htmlspecialchars_decode($Result, ENT_QUOTES);
     $Result = str_replace('
', "\r", $Result);
     $Result = trim($Result);
     return $Result;
 }
Ejemplo n.º 4
0
 protected static function StaticPhpQueryReplace(&$String)
 {
     $ImageDimensions = self::ImageDimensions();
     $Domain = Gdn::Request()->Domain();
     $Doc = PqDocument($String, array('FixHtml' => False));
     foreach (Pq('img[src]') as $ImgNode) {
         $PqImg = Pq($ImgNode);
         if (!$PqImg->Attr('width') && !$PqImg->Attr('height')) {
             // TODO: DONT USE AbsoluteSource() for relative paths
             $Src = AbsoluteSource(trim($PqImg->Attr('src'), '/'), $Domain);
             $CrcKey = crc32($Src);
             if (!array_key_exists($CrcKey, $ImageDimensions)) {
                 $ImageSize = getimagesize($Src);
                 $ImageDimensions[$CrcKey] = array($ImageSize[0], $ImageSize[1], '_src' => $Src);
             } else {
                 $ImageSize = $ImageDimensions[$CrcKey];
             }
             $PqImg->Attr('width', $ImageSize[0]);
             $PqImg->Attr('height', $ImageSize[1]);
         }
     }
     // Save cache.
     self::ImageDimensions($ImageDimensions);
     $String = $Doc->document->saveXML();
 }
Ejemplo n.º 5
-1
 function LingvoTranslate($Word, $Options = array())
 {
     LoadPhpQuery();
     static $Result, $LanguageCode;
     if (is_null($LanguageCode)) {
         $LanguageCode = LocaleLanguageCode();
     }
     $ResetCache = ArrayValue('ResetCache', $Options, False);
     $From = ArrayValue('From', $Options, $LanguageCode);
     $To = ArrayValue('To', $Options, $LanguageCode);
     if (!isset($Result[$Word]) || $ResetCache) {
         $Direction = $From . '-' . $To;
         $Url = 'http://lingvo.abbyyonline.com/en/' . $Direction . '/' . rawurlencode($Word);
         $Doc = PhpQuery::NewDocumentFile($Url);
         /*$Translation = Pq('div.card-short > span.Bold')->Text();
         		if($Translation != ''){
         			$Translation = preg_replace('/\n/', '', $Translation);
         			if(!preg_match('/^[а-я ]+$/iu', $Translation)){
         				$Translation = Pq('span.translation:eq(0)')->Text();
         			}
         		}*/
         Pq('span.translation:eq(0)')->Children()->Remove();
         $Translation = Pq('span.translation:eq(0)')->Text();
         $Translation = trim($Translation);
         $Result[$Word] = $Translation;
     }
     return $Result[$Word];
 }