Diff
checker
Text
Text
Images
Documents
Excel
Folders
Legal
Enterprise
Desktop
Pricing
Sign in
Download Diffchecker Desktop
Compare text
Find the difference between two text files
Tools
History
Display
Layout
Split
Unified
Real-time editor
Hide whitespace changes
Hide unchanged lines
Disable line wrap
Diff precision
Smart
Syntax
None
Change appearance
Process
Ignore
Transform text
Go to first change
Edit input
Diffchecker Desktop
The most secure way to run Diffchecker. Get the Diffchecker Desktop app: your diffs never leave your computer!
Get Desktop
MarkdownHelper
Created
4 years ago
Diff never expires
Clear
Export
Share
Explain
23 removals
Lines
Total
Removed
Characters
Total
Removed
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
250 lines
Copy
29 additions
Lines
Total
Added
Characters
Total
Added
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
252 lines
Copy
<?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) {
Copy
Copied
Copy
Copied
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) {
Copy
Copied
Copy
Copied
$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);
Copy
Copied
Copy
Copied
$this->
article = preg_replace(
self::$
article = preg_replace(
['/ +/', '/ +\n/'],
['/ +/', '/ +\n/'],
[' ', "\n" ],
[' ', "\n" ],
Copy
Copied
Copy
Copied
$this->
article
self::$
article
);
);
Copy
Copied
Copy
Copied
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}|");
Copy
Copied
Copy
Copied
$this->
article .= self::escape($text);
self::$
article .= self::escape($text);
break;
break;
case XML_ELEMENT_NODE:
case XML_ELEMENT_NODE:
Copy
Copied
Copy
Copied
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' :
Saved diffs
Original text
Open 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; } } }
Changed text
Open 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; } } }
Find difference