Diff
checker
Testo
Testo
Immagini
Documenti
Excel
Cartelle
Legal
Enterprise
Applicazione per desktop
Prezzi
Accedi
Scarica Diffchecker Desktop
Confronta il testo
Trova la differenza tra due file di testo
Strumenti
Cronologia
Visualizzazione
Layout
Diviso
Unificato
Editor live
Nascondi spazi bianchi
Comprimi invariate
Senza a capo
Livello di dettaglio
Intelligente
Sintassi
Nessuno
Modifica aspetto
Elaborazione
Ignora
Trasforma testo
Vai alla prima modifica
Modifica input
Diffchecker Desktop
Il modo più sicuro per usare Diffchecker. Ottieni l'app Diffchecker Desktop: i tuoi diff non lasciano mai il tuo computer!
Ottieni Desktop
MarkdownHelper
Creato
4 anni fa
Il diff non scade mai
Eliminare
Esporta
Condividere
Spiegare
23 rimozioni
Linee
Totale
Rimosso
Caratteri
Totale
Rimosso
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
250 linee
Copia tutti
29 aggiunte
Linee
Totale
Aggiunto
Caratteri
Totale
Aggiunto
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
252 linee
Copia tutti
<?php
<?php
namespace sij\humhub\modules\rss\components;
namespace sij\humhub\modules\rss\components;
/**
/**
* A collection of useful methods to assist working with Markdown text.
* A collection of useful methods to assist working with Markdown text.
*/
*/
class MarkdownHelper {
class MarkdownHelper {
private static $article;
private static $article;
private static $level;
private static $level;
public static $logFileHandle = false;
public static $logFileHandle = false;
public static $cfg_pictures = 'yes';
public static $cfg_pictures = 'yes';
public static $cfg_maxwidth = 500;
public static $cfg_maxwidth = 500;
public static $cfg_maxheight = 500;
public static $cfg_maxheight = 500;
/**
/**
* Makes the supplied text safe to use as Markdown.
* Makes the supplied text safe to use as Markdown.
*/
*/
public static function escape($text)
public static function escape($text)
{
{
return str_replace(
return str_replace(
[ '\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '<', '>', '_', '{', '}', ],
[ '\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '<', '>', '_', '{', '}', ],
[ '\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\<', '\>', '\_', '\{', '\}', ],
[ '\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\<', '\>', '\_', '\{', '\}', ],
$text
$text
);
);
}
}
private static function log($text) {
private static function log($text) {
Copia
Copiato
Copia
Copiato
if (
$this->
logFileHandle ) {
if (
self::$
logFileHandle ) {
fwrite(
$this->
logFileHandle, $text);
fwrite(
self::$
logFileHandle, $text);
}
}
}
}
/**
/**
* Translates a HTML document into Markdown syntax
* Translates a HTML document into Markdown syntax
*/
*/
public static function translateHTML($html) {
public static function translateHTML($html) {
Copia
Copiato
Copia
Copiato
$doc = new \DomDocument(
);
$doc = new \DomDocument(
'1.0', 'UTF-8'
);
$doc->loadHTML(
mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'),
LIBXML_NOCDATA
);
$doc->loadHTML(
mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'),
LIBXML_NOCDATA
);
$this->
article =
''
;
self::$
article =
""
;
$this->
level = 0;
self::$
level = 0;
self::translateNode($doc->documentElement);
self::translateNode($doc->documentElement);
Copia
Copiato
Copia
Copiato
$this->
article = preg_replace(
self::$
article = preg_replace(
['/ +/', '/ +\n/'],
['/ +/', '/ +\n/'],
[' ', "\n" ],
[' ', "\n" ],
Copia
Copiato
Copia
Copiato
$this->
article
self::$
article
);
);
Copia
Copiato
Copia
Copiato
return trim(
$this->
article);
return trim(
self::$
article);
}
}
/**
/**
* Translate the HTML body of the RSS new item into Markdown syntax
* Translate the HTML body of the RSS new item into Markdown syntax
*/
*/
private static function translateNode($node)
private static function translateNode($node)
{
{
switch ( $node->nodeType ) {
switch ( $node->nodeType ) {
case XML_TEXT_NODE:
case XML_TEXT_NODE:
$text = trim(preg_replace('/\s+/', ' ', $node->textContent));
$text = trim(preg_replace('/\s+/', ' ', $node->textContent));
self::log("\n### Text: |${text}|");
self::log("\n### Text: |${text}|");
Copia
Copiato
Copia
Copiato
$this->
article .= self::escape($text);
self::$
article .= self::escape($text);
break;
break;
case XML_ELEMENT_NODE:
case XML_ELEMENT_NODE:
Copia
Copiato
Copia
Copiato
self::log("\n### node " .
$this->
level . " " . strtolower($node->nodeName));
self::log("\n### node " .
self::$
level . " " . strtolower($node->nodeName));
switch ( strtolower($node->nodeName) ) {
switch ( strtolower($node->nodeName) ) {
case 'h1':
case 'h1':
$before = "\n# ";
$before = "\n# ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'h2':
case 'h2':
$before = "\n## ";
$before = "\n## ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'h3':
case 'h3':
$before = "\n### ";
$before = "\n### ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'h4':
case 'h4':
$before = "\n#### ";
$before = "\n#### ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'h5':
case 'h5':
$before = "\n##### ";
$before = "\n##### ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'h6':
case 'h6':
$before = "\n###### ";
$before = "\n###### ";
$after = "\n";
$after = "\n";
$enter = true;
$enter = true;
break;
break;
case 'center' :
case 'center' :
case 'article' :
case 'article' :
Diff salvati
Testo originale
Apri file
<?php namespace sij\humhub\modules\rss\components; /** * A collection of useful methods to assist working with Markdown text. */ class MarkdownHelper { private static $article; private static $level; public static $logFileHandle = false; public static $cfg_pictures = 'yes'; public static $cfg_maxwidth = 500; public static $cfg_maxheight = 500; /** * Makes the supplied text safe to use as Markdown. */ public static function escape($text) { return str_replace( [ '\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '<', '>', '_', '{', '}', ], [ '\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\<', '\>', '\_', '\{', '\}', ], $text ); } private static function log($text) { if ( $this->logFileHandle ) { fwrite($this->logFileHandle, $text); } } /** * Translates a HTML document into Markdown syntax */ public static function translateHTML($html) { $doc = new \DomDocument(); $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOCDATA); $this->article = ''; $this->level = 0; self::translateNode($doc->documentElement); $this->article = preg_replace( ['/ +/', '/ +\n/'], [' ', "\n" ], $this->article ); return trim($this->article); } /** * Translate the HTML body of the RSS new item into Markdown syntax */ private static function translateNode($node) { switch ( $node->nodeType ) { case XML_TEXT_NODE: $text = trim(preg_replace('/\s+/', ' ', $node->textContent)); self::log("\n### Text: |${text}|"); $this->article .= self::escape($text); break; case XML_ELEMENT_NODE: self::log("\n### node " . $this->level . " " . strtolower($node->nodeName)); switch ( strtolower($node->nodeName) ) { case 'h1': $before = "\n# "; $after = "\n"; $enter = true; break; case 'h2': $before = "\n## "; $after = "\n"; $enter = true; break; case 'h3': $before = "\n### "; $after = "\n"; $enter = true; break; case 'h4': $before = "\n#### "; $after = "\n"; $enter = true; break; case 'h5': $before = "\n##### "; $after = "\n"; $enter = true; break; case 'h6': $before = "\n###### "; $after = "\n"; $enter = true; break; case 'center' : case 'article' : case 'aside' : case 'div' : case 'footer' : case 'header' : case 'main' : case 'p': case 'section' : $before = "\n\n"; $after = "\n\n"; $enter = true; break; case 'br': $before = "\n"; $after = ""; $enter = false; break; case 'b': case 'kbd' : case 'mark' : case 'strong' : $before = "**"; $after = "**"; $enter = true; break; case 'dfn' : case 'em': case 'i': case 'var' : $before = "_"; $after = "_"; $enter = true; break; case 's': case 'strike': case 'del': $before = "~~"; $after = "~~"; $enter = true; break; case 'blockquote': case 'q' : $before = "\n> "; $after = "\n"; $enter = true; break; case 'a': $before = " ["; $after = "](" . $node->getAttribute('href') . ") "; $enter = true; break; case 'img': if ($this->cfg_pictures == 'yes' ) { $width = $node->getAttribute('width'); $height = $node->getAttribute('height'); if ( $width ) { if ( $width > $this->cfg_maxwidth ) { if ( $height ) { $height = floor($height * $this->cfg_maxwidth / $width); } $width = $this->cfg_maxwidth; } } if ( $height ) { if ( $height > $this->cfg_maxheight ) { if ( $width ) { $width = floor($width * $this->cfg_maxheight / $height); } $height = $this->cfg_maxheight; } } $size = ' =' . $width . 'x' . $height; if ( $size = ' =x' ) { $size = ''; } $before = " ![" . $node->getAttribute('alt') . "]"; $after = "(" . $node->getAttribute('src') . $size . ") "; } else { $before = ''; $after = ''; } $enter = false; break; case 'hr': $before = "\n\n---\n\n"; $after = ""; $enter = false; break; case 'abbr' : case 'acronym' : case 'address' : case 'big' : case 'body' : case 'cite' : case 'figcaption' : case 'figure' : case 'html' : case 'ins' : case 'small' : case 'span' : case 'sub' : case 'sup' : case 'time' : case 'u' : case 'wbr' : $before = ""; $after = ""; $enter = true; break; case 'table' : $before = "\n"; $after = "\n"; $enter = true; break; case 'tr' : case 'th' : case 'td' : case 'thead' : case 'tbody' : case 'tfoot' : case 'caption' : $before = " "; $after = " "; $enter = true; break; default : $before = ""; $after = ""; $enter = false; } self::log("\nBefore: |${before}|"); self::log("\nAfter: |${after}|"); $this->article .= $before; if ( $enter ) { $this->level++; self::log("\nEntering... " . $this->level); foreach ( $node->childNodes as $child ) { self::translateNode($child); } self::log("\nExiting... " . $this->level); $this->level--; } else { self::log("\nSkipping..."); } $this->article .= $after; } } }
Testo modificato
Apri file
<?php namespace sij\humhub\modules\rss\components; /** * A collection of useful methods to assist working with Markdown text. */ class MarkdownHelper { private static $article; private static $level; public static $logFileHandle = false; public static $cfg_pictures = 'yes'; public static $cfg_maxwidth = 500; public static $cfg_maxheight = 500; /** * Makes the supplied text safe to use as Markdown. */ public static function escape($text) { return str_replace( [ '\\', '-', '#', '*', '+', '`', '.', '[', ']', '(', ')', '!', '<', '>', '_', '{', '}', ], [ '\\\\', '\-', '\#', '\*', '\+', '\`', '\.', '\[', '\]', '\(', '\)', '\!', '\<', '\>', '\_', '\{', '\}', ], $text ); } private static function log($text) { if ( self::$logFileHandle ) { fwrite(self::$logFileHandle, $text); } } /** * Translates a HTML document into Markdown syntax */ public static function translateHTML($html) { $doc = new \DomDocument('1.0', 'UTF-8'); $doc->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOCDATA ); self::$article = ""; self::$level = 0; self::translateNode($doc->documentElement); self::$article = preg_replace( ['/ +/', '/ +\n/'], [' ', "\n" ], self::$article ); return trim(self::$article); } /** * Translate the HTML body of the RSS new item into Markdown syntax */ private static function translateNode($node) { switch ( $node->nodeType ) { case XML_TEXT_NODE: $text = trim(preg_replace('/\s+/', ' ', $node->textContent)); self::log("\n### Text: |${text}|"); self::$article .= self::escape($text); break; case XML_ELEMENT_NODE: self::log("\n### node " . self::$level . " " . strtolower($node->nodeName)); switch ( strtolower($node->nodeName) ) { case 'h1': $before = "\n# "; $after = "\n"; $enter = true; break; case 'h2': $before = "\n## "; $after = "\n"; $enter = true; break; case 'h3': $before = "\n### "; $after = "\n"; $enter = true; break; case 'h4': $before = "\n#### "; $after = "\n"; $enter = true; break; case 'h5': $before = "\n##### "; $after = "\n"; $enter = true; break; case 'h6': $before = "\n###### "; $after = "\n"; $enter = true; break; case 'center' : case 'article' : case 'aside' : case 'div' : case 'footer' : case 'header' : case 'main' : case 'p': case 'section' : $before = "\n\n"; $after = "\n\n"; $enter = true; break; case 'br': $before = "\n"; $after = ""; $enter = false; break; case 'b': case 'kbd' : case 'mark' : case 'strong' : $before = "**"; $after = "**"; $enter = true; break; case 'dfn' : case 'em': case 'i': case 'var' : $before = "_"; $after = "_"; $enter = true; break; case 's': case 'strike': case 'del': $before = "~~"; $after = "~~"; $enter = true; break; case 'blockquote': case 'q' : $before = "\n> "; $after = "\n"; $enter = true; break; case 'a': $before = " ["; $after = "](" . $node->getAttribute('href') . ") "; $enter = true; break; case 'img': if ( self::$cfg_pictures == 'yes' ) { $width = $node->getAttribute('width'); $height = $node->getAttribute('height'); if ( $width ) { if ( $width > self::$cfg_maxwidth ) { if ( $height ) { $height = floor($height * self::$cfg_maxwidth / $width); } $width = self::$cfg_maxwidth; } } if ( $height ) { if ( $height > self::$cfg_maxheight ) { if ( $width ) { $width = floor($width * self::$cfg_maxheight / $height); } $height = self::$cfg_maxheight; } } $size = ' =' . $width . 'x' . $height; if ( $size = ' =x' ) { $size = ''; } $before = " ![" . $node->getAttribute('alt') . "]"; $after = "(" . $node->getAttribute('src') . $size . ") "; } else { $before = ''; $after = ''; } $enter = false; break; case 'hr': $before = "\n\n---\n\n"; $after = ""; $enter = false; break; case 'abbr' : case 'acronym' : case 'address' : case 'big' : case 'body' : case 'cite' : case 'figcaption' : case 'figure' : case 'html' : case 'ins' : case 'small' : case 'span' : case 'sub' : case 'sup' : case 'time' : case 'u' : case 'wbr' : $before = ""; $after = ""; $enter = true; break; case 'table' : $before = "\n"; $after = "\n"; $enter = true; break; case 'tr' : case 'th' : case 'td' : case 'thead' : case 'tbody' : case 'tfoot' : case 'caption' : $before = " "; $after = " "; $enter = true; break; default : $before = ""; $after = ""; $enter = false; } self::log("\nBefore: |${before}|"); self::log("\nAfter: |${after}|"); self::$article .= $before; if ( $enter ) { self::$level++; self::log("\nEntering... " . self::$level); foreach ( $node->childNodes as $child ) { self::translateNode($child); } self::log("\nExiting... " . self::$level); self::$level--; } else { self::log("\nSkipping..."); } self::$article .= $after; } } }
Trovare la differenza