Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Affichage
Vue
Divisé
Unifié
Éditeur live
Masquer les espaces
Cacher identiques
Sans retour à la ligne
Niveau de précision
Intelligent
Syntaxe
Aucun
Modifier l’apparence
Traitement
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
MarkdownHelper
Créé
il y a 4 ans
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
23 suppressions
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
250 lignes
Copier tout
29 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
252 lignes
Copier tout
<?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) {
Copier
Copié
Copier
Copié
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) {
Copier
Copié
Copier
Copié
$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);
Copier
Copié
Copier
Copié
$this->
article = preg_replace(
self::$
article = preg_replace(
['/ +/', '/ +\n/'],
['/ +/', '/ +\n/'],
[' ', "\n" ],
[' ', "\n" ],
Copier
Copié
Copier
Copié
$this->
article
self::$
article
);
);
Copier
Copié
Copier
Copié
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}|");
Copier
Copié
Copier
Copié
$this->
article .= self::escape($text);
self::$
article .= self::escape($text);
break;
break;
case XML_ELEMENT_NODE:
case XML_ELEMENT_NODE:
Copier
Copié
Copier
Copié
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érences enregistrées
Texte d'origine
Ouvrir un fichier
<?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; } } }
Texte modifié
Ouvrir un fichier
<?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; } } }
Trouver la différence