├── .gitattributes ├── .gitignore ├── composer.json ├── composer.lock ├── convert.php ├── readme.md └── vendor ├── autoload.php ├── bin └── html-to-markdown ├── composer ├── ClassLoader.php ├── LICENSE ├── autoload_classmap.php ├── autoload_namespaces.php ├── autoload_psr4.php ├── autoload_real.php ├── autoload_static.php └── installed.json └── league └── html-to-markdown ├── .github ├── FUNDING.yml └── stale.yml ├── CHANGELOG.md ├── CONDUCT.md ├── LICENSE ├── README.md ├── bin └── html-to-markdown ├── composer.json └── src ├── Configuration.php ├── ConfigurationAwareInterface.php ├── Converter ├── BlockquoteConverter.php ├── CodeConverter.php ├── CommentConverter.php ├── ConverterInterface.php ├── DefaultConverter.php ├── DivConverter.php ├── EmphasisConverter.php ├── HardBreakConverter.php ├── HeaderConverter.php ├── HorizontalRuleConverter.php ├── ImageConverter.php ├── LinkConverter.php ├── ListBlockConverter.php ├── ListItemConverter.php ├── ParagraphConverter.php ├── PreformattedConverter.php └── TextConverter.php ├── Element.php ├── ElementInterface.php ├── Environment.php ├── HtmlConverter.php └── HtmlConverterInterface.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "league/html-to-markdown": "^4.9" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "c422c69f74e9129c382716c129add662", 8 | "packages": [ 9 | { 10 | "name": "league/html-to-markdown", 11 | "version": "4.10.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/thephpleague/html-to-markdown.git", 15 | "reference": "0868ae7a552e809e5cd8f93ba022071640408e88" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/0868ae7a552e809e5cd8f93ba022071640408e88", 20 | "reference": "0868ae7a552e809e5cd8f93ba022071640408e88", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "ext-dom": "*", 25 | "ext-xml": "*", 26 | "php": ">=5.3.3" 27 | }, 28 | "require-dev": { 29 | "mikehaertl/php-shellcommand": "~1.1.0", 30 | "phpunit/phpunit": "^4.8|^5.7", 31 | "scrutinizer/ocular": "~1.1" 32 | }, 33 | "bin": [ 34 | "bin/html-to-markdown" 35 | ], 36 | "type": "library", 37 | "extra": { 38 | "branch-alias": { 39 | "dev-master": "4.10-dev" 40 | } 41 | }, 42 | "autoload": { 43 | "psr-4": { 44 | "League\\HTMLToMarkdown\\": "src/" 45 | } 46 | }, 47 | "notification-url": "https://packagist.org/downloads/", 48 | "license": [ 49 | "MIT" 50 | ], 51 | "authors": [ 52 | { 53 | "name": "Colin O'Dell", 54 | "email": "colinodell@gmail.com", 55 | "homepage": "https://www.colinodell.com", 56 | "role": "Lead Developer" 57 | }, 58 | { 59 | "name": "Nick Cernis", 60 | "email": "nick@cern.is", 61 | "homepage": "http://modernnerd.net", 62 | "role": "Original Author" 63 | } 64 | ], 65 | "description": "An HTML-to-markdown conversion helper for PHP", 66 | "homepage": "https://github.com/thephpleague/html-to-markdown", 67 | "keywords": [ 68 | "html", 69 | "markdown" 70 | ], 71 | "funding": [ 72 | { 73 | "url": "https://www.colinodell.com/sponsor", 74 | "type": "custom" 75 | }, 76 | { 77 | "url": "https://www.paypal.me/colinpodell/10.00", 78 | "type": "custom" 79 | }, 80 | { 81 | "url": "https://github.com/colinodell", 82 | "type": "github" 83 | }, 84 | { 85 | "url": "https://www.patreon.com/colinodell", 86 | "type": "patreon" 87 | } 88 | ], 89 | "time": "2020-07-01T00:34:03+00:00" 90 | } 91 | ], 92 | "packages-dev": [], 93 | "aliases": [], 94 | "minimum-stability": "stable", 95 | "stability-flags": [], 96 | "prefer-stable": false, 97 | "prefer-lowest": false, 98 | "platform": [], 99 | "platform-dev": [], 100 | "plugin-api-version": "1.1.0" 101 | } 102 | -------------------------------------------------------------------------------- /convert.php: -------------------------------------------------------------------------------- 1 | "http://wordpress.org/export/1.2/excerpt/", 22 | 'content' => "http://purl.org/rss/1.0/modules/content/", 23 | 'wfw' => "http://wellformedweb.org/CommentAPI/", 24 | 'dc' => "http://purl.org/dc/elements/1.1/", 25 | 'wp' => "http://wordpress.org/export/1.2/" 26 | ); 27 | 28 | // Specify the source XML file 29 | 30 | $importfile = 'data.xml'; 31 | 32 | // Specify the directory where files will be exported, including a trailing slash 33 | 34 | $exportdir = 'export/'; 35 | 36 | // Get the contents of the XML file 37 | 38 | $xml = file_get_contents($importfile); 39 | $xml = new SimpleXmlElement($xml); 40 | 41 | // Grab all the things! 42 | 43 | foreach ($xml->channel->item as $item) { 44 | $article = array(); 45 | $article['title'] = $item->title; 46 | $article['link'] = $item->link; 47 | $article['datestamp'] = $item->pubDate; 48 | $article['timestamp'] = strtotime($item->pubDate); 49 | $article['description'] = (string) trim($item->description); 50 | $article['image'] = (string) trim($item->children($ns['wp'])->attachment_url); 51 | if ($article['image']) { 52 | $article['imagedata'] = file_get_contents($article['image']); 53 | } 54 | 55 | // Grab categories and tags for each post 56 | 57 | $tags = array(); 58 | $categories = array(); 59 | foreach ($item->category as $cat) { 60 | $cattype = $cat['domain']; 61 | 62 | if($cattype == "post_tag") { 63 | array_push($tags,$cat); 64 | } 65 | elseif($cattype == "category") { 66 | array_push($categories,$cat); 67 | } 68 | } 69 | 70 | // Grab data within specific namespaces 71 | 72 | $content = $item->children($ns['content']); 73 | $wfw = $item->children($ns['wfw']); 74 | $wp = $item->children($ns['wp']); 75 | 76 | $article['postid'] = $wp->post_id; 77 | $article['content'] = (string) trim($content->encoded); 78 | $article['content'] = str_replace(PHP_EOL . PHP_EOL, '

', $article['content']); 79 | $article['content'] = mb_convert_encoding($article['content'], 'HTML-ENTITIES', "UTF-8"); 80 | 81 | // Convert HTML to Markdown, set optional parameters 82 | 83 | $converter = new HtmlConverter(); 84 | $converter->getConfig()->setOption('hard_break', true); 85 | $converter->getConfig()->setOption('strip_tags', true); 86 | $markdown = $converter->convert($article['content']); 87 | 88 | // Strip WordPress caption shortcodes, optional 89 | 90 | $markdown = preg_replace("/\[caption(.*?)\]/", "", $markdown); 91 | $markdown = preg_replace("/\[\/caption\]/", "", $markdown); 92 | 93 | // Prepare various bits of content for the export 94 | 95 | if ($article['title'] != '') 96 | { $tmptitle = str_replace(' ', '-', $article['title']) ; } 97 | else 98 | { $tmptitle = $article['postid'] ; } 99 | 100 | // Convert accented characters to plain ASCII 101 | $tmptitle = iconv('utf-8', 'ascii//TRANSLIT', $tmptitle); 102 | // Remove slashes 103 | $tmptitle = preg_replace('/[^A-Za-z0-9\-]/', '', $tmptitle); 104 | // Convert to lowercase 105 | $tmptitle = strtolower($tmptitle); 106 | $imagename = basename($article['image']); 107 | $tmpyear = date('Y', strtotime($article['datestamp'])); 108 | $tmpdate = date('Y/Ymd', strtotime($article['datestamp'])); 109 | $file = $exportdir . $tmpdate . '-' . $tmptitle . '/post.txt'; 110 | $fileimage = $exportdir . $tmpdate . '-' . $tmptitle . '/' . $imagename; 111 | $folder = $exportdir . $tmpdate . '-' . $tmptitle; 112 | 113 | // Create the directory for the export 114 | 115 | if (!mkdir($folder, 0777, true)) { 116 | die('Failed to create folders...'. $folder); 117 | } 118 | 119 | // Compile the content for the export 120 | 121 | $strtowrite = "Title: " . $article['title'] 122 | . PHP_EOL . PHP_EOL . "----" . PHP_EOL . PHP_EOL 123 | . "Date: " . $article['datestamp'] 124 | . PHP_EOL. PHP_EOL . "----" . PHP_EOL . PHP_EOL 125 | . "Post ID: " . $article['postid'] 126 | . PHP_EOL. PHP_EOL . "----" . PHP_EOL . PHP_EOL 127 | . "Category: " . implode(', ', $categories) 128 | . PHP_EOL. PHP_EOL . "----" . PHP_EOL . PHP_EOL 129 | . "Tags: " . implode(', ', $tags) 130 | . PHP_EOL. PHP_EOL . "----" . PHP_EOL . PHP_EOL 131 | . ( $imagename ? 132 | "Featured: " . $imagename 133 | . PHP_EOL. PHP_EOL . "----" . PHP_EOL . PHP_EOL : '' ) 134 | . "Text: " . PHP_EOL. PHP_EOL . $markdown; 135 | 136 | // Save the article.txt file 137 | 138 | file_put_contents($file, $strtowrite); 139 | 140 | // Save the image file associated with the post, if there is one 141 | 142 | if ($article['image']) { 143 | file_put_contents($fileimage, $article['imagedata']); 144 | } 145 | 146 | // Report what happened 147 | 148 | echo 'File written: ' . $file . ' at ' . date('Y-m-d H:i:s') . PHP_EOL; 149 | 150 | } 151 | 152 | ?> 153 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # WordPress XML to Kirby 2 | 3 | This script converts an XML file that has been exported in [WordPress eXtended RSS (WXR)](https://wordpress.org/support/article/tools-export-screen/) format to a flat file YAML structure for use with [Kirby](https://getkirby.com/). 4 | 5 | This version of the code is based on the original [WPXML to Kirby](https://github.com/greywillfade/wpxml-to-kirby) script by [Sally Lait](https://sallylait.com/) with further modifications made by [Stay Regular Media](https://github.com/stayregular/wpxml-to-kirby). 6 | 7 | 8 | ## Requirements 9 | 10 | + [PHP](https://www.php.net/) 7.2 or later 11 | + [Composer](https://getcomposer.org/) 12 | + [HTML To Markdown for PHP](https://github.com/thephpleague/html-to-markdown) 13 | 14 | 15 | ## Usage 16 | 17 | + Download this repository and extract the contents to a working directory 18 | 19 | ``` 20 | /wordpress-xml-to-kirby 21 | ``` 22 | 23 | + Install the [Composer](https://getcomposer.org/) dependency manager 24 | + Require the [HTML To Markdown for PHP](https://github.com/thephpleague/html-to-markdown) library 25 | 26 | ``` 27 | composer require league/html-to-markdown 28 | ``` 29 | 30 | + [Export the content of your WordPress site](https://wordpress.org/documentation/article/tools-export-screen/) to an XML file 31 | + To include featured image metadata in the XML file, [see below](#include-featured-image-metadata) 32 | + Move to XML file to the working directory 33 | + Create an export directory in the working directory with full permissions 34 | 35 | ``` 36 | mkdir /wordpress-xml-to-kirby/export` 37 | chmod 777 /wordpress-xml-to-kirby/export 38 | ``` 39 | 40 | + Edit `convert.php` to add the name of the XML file and the export directory 41 | 42 | ```php 43 | $importfile = 'data.xml'; 44 | $exportdir = 'export/'; 45 | ``` 46 | 47 | + Convert all the things! 48 | 49 | ``` 50 | php convert.php 51 | ``` 52 | 53 | 54 | ## Include Featured Image Metadata 55 | 56 | To include the featured image metadata in the XML file, the WordPress core `export.php` file must be modified. 57 | 58 | + Open `wp-admin/includes/export.php` in your favourite text editor 59 | + Locate the following code block: 60 | 61 | ```php 62 | post_type ); ?> 63 | post_password ); ?> 64 | 65 | ``` 66 | + Add the following code directly following the aforementioned code block: 67 | 68 | ```php 69 | ID) ) : ?> 70 | ID), 'full') ?> 71 | 72 | 73 | ``` 74 | 75 | After this modification, the exported XML data will include links to any full sized featured images attached to pages or posts. 76 | 77 | You can also modify the `get_post_thumbnail_id` function to retrieve a link to another image size or include additional XML objects for multiple image sizes. 78 | 79 | 80 | ## Release Notes 81 | 82 | ### 20230122 — The “Clean Up In Aisle Five” Release 83 | 84 | + Better handling of posts with empty `` fields 85 | + Better handling of posts with `<title>` fields containing accented characters 86 | + Paragraph breaks are now maintained when processing `<content:encoded>` 87 | + Renamed several named array keys for clarity and consistency 88 | + Tweaked formatting of exported files because pretty 89 | + Renamed script from `index.php` to `convert.php` because that’s what it does 90 | 91 | ### 20200630 — The “Little Bump” Release 92 | 93 | + Updated [HTML to Markdown for PHP](https://github.com/thephpleague/html-to-markdown) to version [4.10.0](https://github.com/thephpleague/html-to-markdown/releases/tag/4.10.0) 94 | 95 | ### 20200309 — The “Compositionally Challenged” Release 96 | 97 | + Updated [HTML to Markdown for PHP](https://github.com/thephpleague/html-to-markdown) to version [4.9.1](https://github.com/thephpleague/html-to-markdown/releases/tag/4.9.1) 98 | + Added checks for items that do not have associated `attachment_url` data 99 | + Fixed missing space preceding `Text:` content 100 | 101 | ### 20200308 — The “Word Up” Release 102 | 103 | + Initial release based on the [WPXML to Kirby](https://github.com/stayregular/wpxml-to-kirby) script 104 | + Removed `index-events.php` for Modern Tribe’s [The Event Calendar](https://theeventscalendar.com/product/wordpress-events-calendar/) exports 105 | + Updated read me to describe this version of the script 106 | -------------------------------------------------------------------------------- /vendor/autoload.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload.php @generated by Composer 4 | 5 | require_once __DIR__ . '/composer/autoload_real.php'; 6 | 7 | return ComposerAutoloaderInit5cc9d137075d45987019c435aa52b510::getLoader(); 8 | -------------------------------------------------------------------------------- /vendor/bin/html-to-markdown: -------------------------------------------------------------------------------- 1 | ../league/html-to-markdown/bin/html-to-markdown -------------------------------------------------------------------------------- /vendor/composer/ClassLoader.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /* 4 | * This file is part of Composer. 5 | * 6 | * (c) Nils Adermann <naderman@naderman.de> 7 | * Jordi Boggiano <j.boggiano@seld.be> 8 | * 9 | * For the full copyright and license information, please view the LICENSE 10 | * file that was distributed with this source code. 11 | */ 12 | 13 | namespace Composer\Autoload; 14 | 15 | /** 16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. 17 | * 18 | * $loader = new \Composer\Autoload\ClassLoader(); 19 | * 20 | * // register classes with namespaces 21 | * $loader->add('Symfony\Component', __DIR__.'/component'); 22 | * $loader->add('Symfony', __DIR__.'/framework'); 23 | * 24 | * // activate the autoloader 25 | * $loader->register(); 26 | * 27 | * // to enable searching the include path (eg. for PEAR packages) 28 | * $loader->setUseIncludePath(true); 29 | * 30 | * In this example, if you try to use a class in the Symfony\Component 31 | * namespace or one of its children (Symfony\Component\Console for instance), 32 | * the autoloader will first look for the class under the component/ 33 | * directory, and it will then fallback to the framework/ directory if not 34 | * found before giving up. 35 | * 36 | * This class is loosely based on the Symfony UniversalClassLoader. 37 | * 38 | * @author Fabien Potencier <fabien@symfony.com> 39 | * @author Jordi Boggiano <j.boggiano@seld.be> 40 | * @see http://www.php-fig.org/psr/psr-0/ 41 | * @see http://www.php-fig.org/psr/psr-4/ 42 | */ 43 | class ClassLoader 44 | { 45 | // PSR-4 46 | private $prefixLengthsPsr4 = array(); 47 | private $prefixDirsPsr4 = array(); 48 | private $fallbackDirsPsr4 = array(); 49 | 50 | // PSR-0 51 | private $prefixesPsr0 = array(); 52 | private $fallbackDirsPsr0 = array(); 53 | 54 | private $useIncludePath = false; 55 | private $classMap = array(); 56 | private $classMapAuthoritative = false; 57 | private $missingClasses = array(); 58 | private $apcuPrefix; 59 | 60 | public function getPrefixes() 61 | { 62 | if (!empty($this->prefixesPsr0)) { 63 | return call_user_func_array('array_merge', $this->prefixesPsr0); 64 | } 65 | 66 | return array(); 67 | } 68 | 69 | public function getPrefixesPsr4() 70 | { 71 | return $this->prefixDirsPsr4; 72 | } 73 | 74 | public function getFallbackDirs() 75 | { 76 | return $this->fallbackDirsPsr0; 77 | } 78 | 79 | public function getFallbackDirsPsr4() 80 | { 81 | return $this->fallbackDirsPsr4; 82 | } 83 | 84 | public function getClassMap() 85 | { 86 | return $this->classMap; 87 | } 88 | 89 | /** 90 | * @param array $classMap Class to filename map 91 | */ 92 | public function addClassMap(array $classMap) 93 | { 94 | if ($this->classMap) { 95 | $this->classMap = array_merge($this->classMap, $classMap); 96 | } else { 97 | $this->classMap = $classMap; 98 | } 99 | } 100 | 101 | /** 102 | * Registers a set of PSR-0 directories for a given prefix, either 103 | * appending or prepending to the ones previously set for this prefix. 104 | * 105 | * @param string $prefix The prefix 106 | * @param array|string $paths The PSR-0 root directories 107 | * @param bool $prepend Whether to prepend the directories 108 | */ 109 | public function add($prefix, $paths, $prepend = false) 110 | { 111 | if (!$prefix) { 112 | if ($prepend) { 113 | $this->fallbackDirsPsr0 = array_merge( 114 | (array) $paths, 115 | $this->fallbackDirsPsr0 116 | ); 117 | } else { 118 | $this->fallbackDirsPsr0 = array_merge( 119 | $this->fallbackDirsPsr0, 120 | (array) $paths 121 | ); 122 | } 123 | 124 | return; 125 | } 126 | 127 | $first = $prefix[0]; 128 | if (!isset($this->prefixesPsr0[$first][$prefix])) { 129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; 130 | 131 | return; 132 | } 133 | if ($prepend) { 134 | $this->prefixesPsr0[$first][$prefix] = array_merge( 135 | (array) $paths, 136 | $this->prefixesPsr0[$first][$prefix] 137 | ); 138 | } else { 139 | $this->prefixesPsr0[$first][$prefix] = array_merge( 140 | $this->prefixesPsr0[$first][$prefix], 141 | (array) $paths 142 | ); 143 | } 144 | } 145 | 146 | /** 147 | * Registers a set of PSR-4 directories for a given namespace, either 148 | * appending or prepending to the ones previously set for this namespace. 149 | * 150 | * @param string $prefix The prefix/namespace, with trailing '\\' 151 | * @param array|string $paths The PSR-4 base directories 152 | * @param bool $prepend Whether to prepend the directories 153 | * 154 | * @throws \InvalidArgumentException 155 | */ 156 | public function addPsr4($prefix, $paths, $prepend = false) 157 | { 158 | if (!$prefix) { 159 | // Register directories for the root namespace. 160 | if ($prepend) { 161 | $this->fallbackDirsPsr4 = array_merge( 162 | (array) $paths, 163 | $this->fallbackDirsPsr4 164 | ); 165 | } else { 166 | $this->fallbackDirsPsr4 = array_merge( 167 | $this->fallbackDirsPsr4, 168 | (array) $paths 169 | ); 170 | } 171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) { 172 | // Register directories for a new namespace. 173 | $length = strlen($prefix); 174 | if ('\\' !== $prefix[$length - 1]) { 175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 176 | } 177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 178 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 179 | } elseif ($prepend) { 180 | // Prepend directories for an already registered namespace. 181 | $this->prefixDirsPsr4[$prefix] = array_merge( 182 | (array) $paths, 183 | $this->prefixDirsPsr4[$prefix] 184 | ); 185 | } else { 186 | // Append directories for an already registered namespace. 187 | $this->prefixDirsPsr4[$prefix] = array_merge( 188 | $this->prefixDirsPsr4[$prefix], 189 | (array) $paths 190 | ); 191 | } 192 | } 193 | 194 | /** 195 | * Registers a set of PSR-0 directories for a given prefix, 196 | * replacing any others previously set for this prefix. 197 | * 198 | * @param string $prefix The prefix 199 | * @param array|string $paths The PSR-0 base directories 200 | */ 201 | public function set($prefix, $paths) 202 | { 203 | if (!$prefix) { 204 | $this->fallbackDirsPsr0 = (array) $paths; 205 | } else { 206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; 207 | } 208 | } 209 | 210 | /** 211 | * Registers a set of PSR-4 directories for a given namespace, 212 | * replacing any others previously set for this namespace. 213 | * 214 | * @param string $prefix The prefix/namespace, with trailing '\\' 215 | * @param array|string $paths The PSR-4 base directories 216 | * 217 | * @throws \InvalidArgumentException 218 | */ 219 | public function setPsr4($prefix, $paths) 220 | { 221 | if (!$prefix) { 222 | $this->fallbackDirsPsr4 = (array) $paths; 223 | } else { 224 | $length = strlen($prefix); 225 | if ('\\' !== $prefix[$length - 1]) { 226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); 227 | } 228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; 229 | $this->prefixDirsPsr4[$prefix] = (array) $paths; 230 | } 231 | } 232 | 233 | /** 234 | * Turns on searching the include path for class files. 235 | * 236 | * @param bool $useIncludePath 237 | */ 238 | public function setUseIncludePath($useIncludePath) 239 | { 240 | $this->useIncludePath = $useIncludePath; 241 | } 242 | 243 | /** 244 | * Can be used to check if the autoloader uses the include path to check 245 | * for classes. 246 | * 247 | * @return bool 248 | */ 249 | public function getUseIncludePath() 250 | { 251 | return $this->useIncludePath; 252 | } 253 | 254 | /** 255 | * Turns off searching the prefix and fallback directories for classes 256 | * that have not been registered with the class map. 257 | * 258 | * @param bool $classMapAuthoritative 259 | */ 260 | public function setClassMapAuthoritative($classMapAuthoritative) 261 | { 262 | $this->classMapAuthoritative = $classMapAuthoritative; 263 | } 264 | 265 | /** 266 | * Should class lookup fail if not found in the current class map? 267 | * 268 | * @return bool 269 | */ 270 | public function isClassMapAuthoritative() 271 | { 272 | return $this->classMapAuthoritative; 273 | } 274 | 275 | /** 276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled. 277 | * 278 | * @param string|null $apcuPrefix 279 | */ 280 | public function setApcuPrefix($apcuPrefix) 281 | { 282 | $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; 283 | } 284 | 285 | /** 286 | * The APCu prefix in use, or null if APCu caching is not enabled. 287 | * 288 | * @return string|null 289 | */ 290 | public function getApcuPrefix() 291 | { 292 | return $this->apcuPrefix; 293 | } 294 | 295 | /** 296 | * Registers this instance as an autoloader. 297 | * 298 | * @param bool $prepend Whether to prepend the autoloader or not 299 | */ 300 | public function register($prepend = false) 301 | { 302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend); 303 | } 304 | 305 | /** 306 | * Unregisters this instance as an autoloader. 307 | */ 308 | public function unregister() 309 | { 310 | spl_autoload_unregister(array($this, 'loadClass')); 311 | } 312 | 313 | /** 314 | * Loads the given class or interface. 315 | * 316 | * @param string $class The name of the class 317 | * @return bool|null True if loaded, null otherwise 318 | */ 319 | public function loadClass($class) 320 | { 321 | if ($file = $this->findFile($class)) { 322 | includeFile($file); 323 | 324 | return true; 325 | } 326 | } 327 | 328 | /** 329 | * Finds the path to the file where the class is defined. 330 | * 331 | * @param string $class The name of the class 332 | * 333 | * @return string|false The path if found, false otherwise 334 | */ 335 | public function findFile($class) 336 | { 337 | // class map lookup 338 | if (isset($this->classMap[$class])) { 339 | return $this->classMap[$class]; 340 | } 341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { 342 | return false; 343 | } 344 | if (null !== $this->apcuPrefix) { 345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit); 346 | if ($hit) { 347 | return $file; 348 | } 349 | } 350 | 351 | $file = $this->findFileWithExtension($class, '.php'); 352 | 353 | // Search for Hack files if we are running on HHVM 354 | if (false === $file && defined('HHVM_VERSION')) { 355 | $file = $this->findFileWithExtension($class, '.hh'); 356 | } 357 | 358 | if (null !== $this->apcuPrefix) { 359 | apcu_add($this->apcuPrefix.$class, $file); 360 | } 361 | 362 | if (false === $file) { 363 | // Remember that this class does not exist. 364 | $this->missingClasses[$class] = true; 365 | } 366 | 367 | return $file; 368 | } 369 | 370 | private function findFileWithExtension($class, $ext) 371 | { 372 | // PSR-4 lookup 373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; 374 | 375 | $first = $class[0]; 376 | if (isset($this->prefixLengthsPsr4[$first])) { 377 | $subPath = $class; 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { 379 | $subPath = substr($subPath, 0, $lastPos); 380 | $search = $subPath . '\\'; 381 | if (isset($this->prefixDirsPsr4[$search])) { 382 | $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { 384 | if (file_exists($file = $dir . $pathEnd)) { 385 | return $file; 386 | } 387 | } 388 | } 389 | } 390 | } 391 | 392 | // PSR-4 fallback dirs 393 | foreach ($this->fallbackDirsPsr4 as $dir) { 394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 395 | return $file; 396 | } 397 | } 398 | 399 | // PSR-0 lookup 400 | if (false !== $pos = strrpos($class, '\\')) { 401 | // namespaced class name 402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); 404 | } else { 405 | // PEAR-like class name 406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; 407 | } 408 | 409 | if (isset($this->prefixesPsr0[$first])) { 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { 411 | if (0 === strpos($class, $prefix)) { 412 | foreach ($dirs as $dir) { 413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 414 | return $file; 415 | } 416 | } 417 | } 418 | } 419 | } 420 | 421 | // PSR-0 fallback dirs 422 | foreach ($this->fallbackDirsPsr0 as $dir) { 423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 424 | return $file; 425 | } 426 | } 427 | 428 | // PSR-0 include paths. 429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { 430 | return $file; 431 | } 432 | 433 | return false; 434 | } 435 | } 436 | 437 | /** 438 | * Scope isolated include. 439 | * 440 | * Prevents access to $this/self from included files. 441 | */ 442 | function includeFile($file) 443 | { 444 | include $file; 445 | } 446 | -------------------------------------------------------------------------------- /vendor/composer/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) Nils Adermann, Jordi Boggiano 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is furnished 9 | to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /vendor/composer/autoload_classmap.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload_classmap.php @generated by Composer 4 | 5 | $vendorDir = dirname(dirname(__FILE__)); 6 | $baseDir = dirname($vendorDir); 7 | 8 | return array( 9 | ); 10 | -------------------------------------------------------------------------------- /vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload_namespaces.php @generated by Composer 4 | 5 | $vendorDir = dirname(dirname(__FILE__)); 6 | $baseDir = dirname($vendorDir); 7 | 8 | return array( 9 | ); 10 | -------------------------------------------------------------------------------- /vendor/composer/autoload_psr4.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload_psr4.php @generated by Composer 4 | 5 | $vendorDir = dirname(dirname(__FILE__)); 6 | $baseDir = dirname($vendorDir); 7 | 8 | return array( 9 | 'League\\HTMLToMarkdown\\' => array($vendorDir . '/league/html-to-markdown/src'), 10 | ); 11 | -------------------------------------------------------------------------------- /vendor/composer/autoload_real.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload_real.php @generated by Composer 4 | 5 | class ComposerAutoloaderInit5cc9d137075d45987019c435aa52b510 6 | { 7 | private static $loader; 8 | 9 | public static function loadClassLoader($class) 10 | { 11 | if ('Composer\Autoload\ClassLoader' === $class) { 12 | require __DIR__ . '/ClassLoader.php'; 13 | } 14 | } 15 | 16 | /** 17 | * @return \Composer\Autoload\ClassLoader 18 | */ 19 | public static function getLoader() 20 | { 21 | if (null !== self::$loader) { 22 | return self::$loader; 23 | } 24 | 25 | spl_autoload_register(array('ComposerAutoloaderInit5cc9d137075d45987019c435aa52b510', 'loadClassLoader'), true, true); 26 | self::$loader = $loader = new \Composer\Autoload\ClassLoader(); 27 | spl_autoload_unregister(array('ComposerAutoloaderInit5cc9d137075d45987019c435aa52b510', 'loadClassLoader')); 28 | 29 | $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); 30 | if ($useStaticLoader) { 31 | require_once __DIR__ . '/autoload_static.php'; 32 | 33 | call_user_func(\Composer\Autoload\ComposerStaticInit5cc9d137075d45987019c435aa52b510::getInitializer($loader)); 34 | } else { 35 | $map = require __DIR__ . '/autoload_namespaces.php'; 36 | foreach ($map as $namespace => $path) { 37 | $loader->set($namespace, $path); 38 | } 39 | 40 | $map = require __DIR__ . '/autoload_psr4.php'; 41 | foreach ($map as $namespace => $path) { 42 | $loader->setPsr4($namespace, $path); 43 | } 44 | 45 | $classMap = require __DIR__ . '/autoload_classmap.php'; 46 | if ($classMap) { 47 | $loader->addClassMap($classMap); 48 | } 49 | } 50 | 51 | $loader->register(true); 52 | 53 | return $loader; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // autoload_static.php @generated by Composer 4 | 5 | namespace Composer\Autoload; 6 | 7 | class ComposerStaticInit5cc9d137075d45987019c435aa52b510 8 | { 9 | public static $prefixLengthsPsr4 = array ( 10 | 'L' => 11 | array ( 12 | 'League\\HTMLToMarkdown\\' => 22, 13 | ), 14 | ); 15 | 16 | public static $prefixDirsPsr4 = array ( 17 | 'League\\HTMLToMarkdown\\' => 18 | array ( 19 | 0 => __DIR__ . '/..' . '/league/html-to-markdown/src', 20 | ), 21 | ); 22 | 23 | public static function getInitializer(ClassLoader $loader) 24 | { 25 | return \Closure::bind(function () use ($loader) { 26 | $loader->prefixLengthsPsr4 = ComposerStaticInit5cc9d137075d45987019c435aa52b510::$prefixLengthsPsr4; 27 | $loader->prefixDirsPsr4 = ComposerStaticInit5cc9d137075d45987019c435aa52b510::$prefixDirsPsr4; 28 | 29 | }, null, ClassLoader::class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/composer/installed.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "league/html-to-markdown", 4 | "version": "4.10.0", 5 | "version_normalized": "4.10.0.0", 6 | "source": { 7 | "type": "git", 8 | "url": "https://github.com/thephpleague/html-to-markdown.git", 9 | "reference": "0868ae7a552e809e5cd8f93ba022071640408e88" 10 | }, 11 | "dist": { 12 | "type": "zip", 13 | "url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/0868ae7a552e809e5cd8f93ba022071640408e88", 14 | "reference": "0868ae7a552e809e5cd8f93ba022071640408e88", 15 | "shasum": "" 16 | }, 17 | "require": { 18 | "ext-dom": "*", 19 | "ext-xml": "*", 20 | "php": ">=5.3.3" 21 | }, 22 | "require-dev": { 23 | "mikehaertl/php-shellcommand": "~1.1.0", 24 | "phpunit/phpunit": "^4.8|^5.7", 25 | "scrutinizer/ocular": "~1.1" 26 | }, 27 | "time": "2020-07-01T00:34:03+00:00", 28 | "bin": [ 29 | "bin/html-to-markdown" 30 | ], 31 | "type": "library", 32 | "extra": { 33 | "branch-alias": { 34 | "dev-master": "4.10-dev" 35 | } 36 | }, 37 | "installation-source": "dist", 38 | "autoload": { 39 | "psr-4": { 40 | "League\\HTMLToMarkdown\\": "src/" 41 | } 42 | }, 43 | "notification-url": "https://packagist.org/downloads/", 44 | "license": [ 45 | "MIT" 46 | ], 47 | "authors": [ 48 | { 49 | "name": "Colin O'Dell", 50 | "email": "colinodell@gmail.com", 51 | "homepage": "https://www.colinodell.com", 52 | "role": "Lead Developer" 53 | }, 54 | { 55 | "name": "Nick Cernis", 56 | "email": "nick@cern.is", 57 | "homepage": "http://modernnerd.net", 58 | "role": "Original Author" 59 | } 60 | ], 61 | "description": "An HTML-to-markdown conversion helper for PHP", 62 | "homepage": "https://github.com/thephpleague/html-to-markdown", 63 | "keywords": [ 64 | "html", 65 | "markdown" 66 | ], 67 | "funding": [ 68 | { 69 | "url": "https://www.colinodell.com/sponsor", 70 | "type": "custom" 71 | }, 72 | { 73 | "url": "https://www.paypal.me/colinpodell/10.00", 74 | "type": "custom" 75 | }, 76 | { 77 | "url": "https://github.com/colinodell", 78 | "type": "github" 79 | }, 80 | { 81 | "url": "https://www.patreon.com/colinodell", 82 | "type": "patreon" 83 | } 84 | ] 85 | } 86 | ] 87 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: colinodell 2 | patreon: colinodell 3 | custom: ["https://www.colinodell.com/sponsor", "https://www.paypal.me/colinpodell/10.00"] 4 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 90 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 30 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - on hold 9 | - security 10 | # Label to use when marking an issue as stale 11 | staleLabel: stale 12 | # Comment to post when marking an issue as stale. Set to `false` to disable 13 | markComment: > 14 | This issue has been automatically marked as stale because it has not had 15 | recent activity. It will be closed if no further activity occurs. Thank you 16 | for your contributions. 17 | # Comment to post when closing a stale issue. Set to `false` to disable 18 | closeComment: false 19 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. 4 | 5 | ## [Unreleased][unreleased] 6 | 7 | ## [4.10.0] - 2020-06-30 8 | ### Added 9 | 10 | - Added the ability to disable autolinking with a configuration option (#187, #188) 11 | 12 | ## [4.9.1] - 2019-12-27 13 | ### Fixed 14 | - Fixed issue with HTML entity escaping in text (#184) 15 | 16 | ## [4.9.0] - 2019-11-02 17 | ### Added 18 | - Added new option to preserve comments (#177, #179) 19 | 20 | ## [4.8.3] - 2019-10-31 21 | ### Fixed 22 | - Fixed whitespace preservation around `<code>` tags (#174, #178) 23 | 24 | ## [4.8.2] - 2019-08-02 25 | ### Fixed 26 | - Fixed headers not being placed onto a new line in some cases (#172) 27 | - Fixed handling of links containing spaces (#175) 28 | 29 | ### Removed 30 | - Removed support for HHVM 31 | 32 | ## [4.8.1] - 2018-12-24 33 | ### Added 34 | - Added support for PHP 7.3 35 | 36 | ### Fixed 37 | - Fixed paragraphs following tables (#165, #166) 38 | - Fixed incorrect list item escaping (#168, #169) 39 | 40 | ## [4.8.0] - 2018-09-18 41 | ### Added 42 | - Added support for email auto-linking 43 | - Added a new interface (`HtmlConverterInterface`) for the main `HtmlConverter` class 44 | - Added additional test cases (#14) 45 | 46 | ### Changed 47 | - The `italic_style` option now defaults to `'*'` so that in-word emphasis is handled properly (#75) 48 | 49 | ### Fixed 50 | - Fixed several issues of `<code>` and `<pre>` tags not converting to blocks or inlines properly (#26, #70, #102, #140, #161, #162) 51 | - Fixed in-word emphasis using underscores as delimiter (#75) 52 | - Fixed character escaping inside of `<div>` elements 53 | - Fixed header edge cases 54 | 55 | ### Deprecated 56 | - The `bold_style` and `italic_style` options have been deprecated (#75) 57 | 58 | ## [4.7.0] - 2018-05-19 59 | ### Added 60 | - Added `setOptions()` function for chainable calling (#149) 61 | - Added new `list_item_style_alternate` option for converting every-other list with a different character (#155) 62 | 63 | ### Fixed 64 | - Fixed insufficient newlines after code blocks (#144, #148) 65 | - Fixed trailing spaces not being preserved in link anchors (#157) 66 | - Fixed list-like lines not being escaped inside of lists items (#159) 67 | 68 | ## [4.6.2] 69 | ### Fixed 70 | - Fixed issue with emphasized spaces (#146) 71 | 72 | ## [4.6.1] 73 | ### Fixed 74 | - Fixed conversion of `<pre>` tags (#145) 75 | 76 | ## [4.6.0] 77 | ### Added 78 | - Added support for ordered lists starting at numbers other than 1 79 | 80 | ### Fixed 81 | - Fixed overly-eager escaping of list-like text (#141) 82 | 83 | ## [4.5.0] 84 | ### Added 85 | - Added configuration option for list item style (#135, #136) 86 | 87 | ## [4.4.1] 88 | 89 | ### Fixed 90 | - Fixed autolinking of invalid URLs (#129) 91 | 92 | ## [4.4.0] 93 | 94 | ### Added 95 | - Added `hard_break` configuration option (#112, #115) 96 | - The `HtmlConverter` can now be instantiated with an `Environment` (#118) 97 | 98 | ### Fixed 99 | - Fixed handling of paragraphs in list item elements (#47, #110) 100 | - Fixed phantom spaces when newlines follow `br` elements (#116, #117) 101 | - Fixed link converter not sanitizing inner spaces properly (#119, #120) 102 | 103 | ## [4.3.1] 104 | ### Changed 105 | - Revised the sanitization implementation (#109) 106 | 107 | ### Fixed 108 | - Fixed tag-like content not being escaped (#67, #109) 109 | - Fixed thematic break-like content not being escaped (#65, #109) 110 | - Fixed codefence-like content not being escaped (#64, #109) 111 | 112 | ## [4.3.0] 113 | ### Added 114 | - Added full support for PHP 7.0 and 7.1 115 | 116 | ### Changed 117 | - Changed `<pre>` and `<pre><code>` conversions to use backticks instead of indendation (#102) 118 | 119 | ### Fixed 120 | - Fixed issue where specified code language was not preserved (#70, #102) 121 | - Fixed issue where `<code>` tags nested in `<pre>` was not converted properly (#70, #102) 122 | - Fixed header-like content not being escaped (#76, #105) 123 | - Fixed blockquote-like content not being escaped (#77, #103) 124 | - Fixed ordered list-like content not being escaped (#73, #106) 125 | - Fixed unordered list-like content not being escaped (#71, #107) 126 | 127 | ## [4.2.2] 128 | ### Fixed 129 | - Fixed sanitization bug which sometimes removes desired content (#63, #101) 130 | 131 | ## [4.2.1] 132 | ### Fixed 133 | - Fixed path to autoload.php when used as a library (#98) 134 | - Fixed edge case for tags containing only whitespace (#99) 135 | 136 | ### Removed 137 | - Removed double HTML entity decoding, as this is not desireable (#60) 138 | 139 | ## [4.2.0] 140 | 141 | ### Added 142 | - Added the ability to invoke HtmlConverter objects as functions (#85) 143 | 144 | ### Fixed 145 | - Fixed improper handling of nested list items (#19 and #84) 146 | - Fixed preceeding or trailing spaces within emphasis tags (#83) 147 | 148 | ## [4.1.1] 149 | 150 | ### Fixed 151 | - Fixed conversion of empty paragraphs (#78) 152 | - Fixed `preg_replace` so it wouldn't break UTF-8 characters (#79) 153 | 154 | ## [4.1.0] 155 | 156 | ### Added 157 | - Added `bin/html-to-markdown` script 158 | 159 | ### Changed 160 | - Changed default italic character to `_` (#58) 161 | 162 | ## [4.0.1] 163 | 164 | ### Fixed 165 | - Added escaping to avoid * and _ in a text being rendered as emphasis (#48) 166 | 167 | ### Removed 168 | - Removed the demo (#51) 169 | - `.styleci.yml` and `CONTRIBUTING.md` are no longer included in distributions (#50) 170 | 171 | ## [4.0.0] 172 | 173 | This release changes the visibility of several methods/properties. #42 and #43 brought to light that some visiblities were 174 | not ideally set, so this releases fixes that. Moving forwards this should reduce the chance of introducing BC-breaking changes. 175 | 176 | ### Added 177 | - Added new `HtmlConverter::getEnvironment()` method to expose the `Environment` (#42, #43) 178 | 179 | ### Changed 180 | - Changed `Environment::addConverter()` from `protected` to `public`, enabling custom converters to be added (#42, #43) 181 | - Changed `HtmlConverter::createDOMDocument()` from `protected` to `private` 182 | - Changed `Element::nextCached` from `protected` to `private` 183 | - Made the `Environment` class `final` 184 | 185 | ## [3.1.1] 186 | ### Fixed 187 | - Empty HTML strings now result in empty Markdown documents (#40, #41) 188 | 189 | ## [3.1.0] 190 | ### Added 191 | - Added new `equals` method to `Element` to check for equality 192 | 193 | ### Changes 194 | - Use Linux line endings consistently instead of plaform-specific line endings (#36) 195 | 196 | ### Fixed 197 | - Cleaned up code style 198 | 199 | ## [3.0.0] 200 | ### Changed 201 | - Changed namespace to `League\HTMLToMarkdown` 202 | - Changed packagist name to `league/html-to-markdown` 203 | - Re-organized code into several separate classes 204 | - `<a>` tags with identical href and inner text are now rendered using angular bracket syntax (#31) 205 | - `<div>` elements are now treated as block-level elements (#33) 206 | 207 | ## [2.2.2] 208 | ### Added 209 | - Added support for PHP 5.6 and HHVM 210 | - Enabled testing against PHP 7 nightlies 211 | - Added this CHANGELOG.md 212 | 213 | ### Fixed 214 | - Fixed whitespace preservation between inline elements (#9 and #10) 215 | 216 | ## [2.2.1] 217 | ### Fixed 218 | - Preserve placeholder links (#22) 219 | 220 | ## [2.2.0] 221 | ### Added 222 | - Added CircleCI config 223 | 224 | ### Changed 225 | - `<pre>` blocks are now treated as code elements 226 | 227 | ### Removed 228 | - Dropped support for PHP 5.2 229 | - Removed incorrect README comment regarding `#text` nodes (#17) 230 | 231 | ## [2.1.2] 232 | ### Added 233 | - Added the ability to blacklist/remove specific node types (#11) 234 | 235 | ### Changed 236 | - Line breaks are now placed after divs instead of before them 237 | - Newlines inside of link texts are now removed 238 | - Updated the minimum PHPUnit version to 4.* 239 | 240 | ## [2.1.1] 241 | ### Added 242 | - Added options to customize emphasis characters 243 | 244 | ## [2.1.0] 245 | ### Added 246 | - Added option to strip HTML tags without Markdown equivalents 247 | - Added `convert()` method for converter reuse 248 | - Added ability to set options after instance construction 249 | - Documented the required PHP extensions (#4) 250 | 251 | ### Changed 252 | - ATX style now used for h1 and h2 tags inside blockquotes 253 | 254 | ### Fixed 255 | - Newlines inside blockquotes are now started with a bracket 256 | - Fixed some incorrect docblocks 257 | - `__toString()` now returns an empty string if input is empty 258 | - Convert head tag if body tag is empty (#7) 259 | - Preserve special characters inside tags without md equivalents (#6) 260 | 261 | 262 | ## [2.0.1] 263 | ### Fixed 264 | - Fixed first line indentation for multi-line code blocks 265 | - Fixed consecutive anchors get separating spaces stripped (#3) 266 | 267 | ## [2.0.0] 268 | ### Added 269 | - Initial release 270 | 271 | [unreleased]: https://github.com/thephpleague/html-to-markdown/compare/4.10.0...master 272 | [4.10.0]: https://github.com/thephpleague/html-to-markdown/compare/4.9.1...4.10.0 273 | [4.9.1]: https://github.com/thephpleague/html-to-markdown/compare/4.9.0...4.9.1 274 | [4.9.0]: https://github.com/thephpleague/html-to-markdown/compare/4.8.3...4.9.0 275 | [4.8.3]: https://github.com/thephpleague/html-to-markdown/compare/4.8.2...4.8.3 276 | [4.8.2]: https://github.com/thephpleague/html-to-markdown/compare/4.8.1...4.8.2 277 | [4.8.1]: https://github.com/thephpleague/html-to-markdown/compare/4.8.0...4.8.1 278 | [4.8.0]: https://github.com/thephpleague/html-to-markdown/compare/4.7.0...4.8.0 279 | [4.7.0]: https://github.com/thephpleague/html-to-markdown/compare/4.6.2...4.7.0 280 | [4.6.2]: https://github.com/thephpleague/html-to-markdown/compare/4.6.1...4.6.2 281 | [4.6.1]: https://github.com/thephpleague/html-to-markdown/compare/4.6.0...4.6.1 282 | [4.6.0]: https://github.com/thephpleague/html-to-markdown/compare/4.5.0...4.6.0 283 | [4.5.0]: https://github.com/thephpleague/html-to-markdown/compare/4.4.1...4.5.0 284 | [4.4.1]: https://github.com/thephpleague/html-to-markdown/compare/4.4.0...4.4.1 285 | [4.4.0]: https://github.com/thephpleague/html-to-markdown/compare/4.3.1...4.4.0 286 | [4.3.1]: https://github.com/thephpleague/html-to-markdown/compare/4.3.0...4.3.1 287 | [4.3.0]: https://github.com/thephpleague/html-to-markdown/compare/4.2.2...4.3.0 288 | [4.2.2]: https://github.com/thephpleague/html-to-markdown/compare/4.2.1...4.2.2 289 | [4.2.1]: https://github.com/thephpleague/html-to-markdown/compare/4.2.0...4.2.1 290 | [4.2.0]: https://github.com/thephpleague/html-to-markdown/compare/4.1.1...4.2.0 291 | [4.1.1]: https://github.com/thephpleague/html-to-markdown/compare/4.1.0...4.1.1 292 | [4.1.0]: https://github.com/thephpleague/html-to-markdown/compare/4.0.1...4.1.0 293 | [4.0.1]: https://github.com/thephpleague/html-to-markdown/compare/4.0.0...4.0.1 294 | [4.0.0]: https://github.com/thephpleague/html-to-markdown/compare/3.1.1...4.0.0 295 | [3.1.1]: https://github.com/thephpleague/html-to-markdown/compare/3.1.0...3.1.1 296 | [3.1.0]: https://github.com/thephpleague/html-to-markdown/compare/3.0.0...3.1.0 297 | [3.0.0]: https://github.com/thephpleague/html-to-markdown/compare/2.2.2...3.0.0 298 | [2.2.2]: https://github.com/thephpleague/html-to-markdown/compare/2.2.1...2.2.2 299 | [2.2.1]: https://github.com/thephpleague/html-to-markdown/compare/2.2.0...2.2.1 300 | [2.2.0]: https://github.com/thephpleague/html-to-markdown/compare/2.1.2...2.2.0 301 | [2.1.2]: https://github.com/thephpleague/html-to-markdown/compare/2.1.1...2.1.2 302 | [2.1.1]: https://github.com/thephpleague/html-to-markdown/compare/2.1.0...2.1.1 303 | [2.1.0]: https://github.com/thephpleague/html-to-markdown/compare/2.0.1...2.1.0 304 | [2.0.1]: https://github.com/thephpleague/html-to-markdown/compare/2.0.0...2.0.1 305 | [2.0.0]: https://github.com/thephpleague/html-to-markdown/compare/775f91e...2.0.0 306 | 307 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 6 | 7 | Examples of unacceptable behavior by participants include: 8 | 9 | * The use of sexualized language or imagery 10 | * Personal attacks 11 | * Trolling or insulting/derogatory comments 12 | * Public or private harassment 13 | * Publishing other's private information, such as physical or electronic addresses, without explicit permission 14 | * Other unethical or unprofessional conduct. 15 | 16 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. 17 | 18 | This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 21 | 22 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) 23 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Colin O'Dell 4 | 5 | Originally created by Nick Cernis 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the "Software"), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | the Software, and to permit persons to whom the Software is furnished to do so, 12 | subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/README.md: -------------------------------------------------------------------------------- 1 | HTML To Markdown for PHP 2 | ======================== 3 | 4 | [![Join the chat at https://gitter.im/thephpleague/html-to-markdown](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/thephpleague/html-to-markdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 5 | 6 | [![Latest Version](https://img.shields.io/packagist/v/league/html-to-markdown.svg?style=flat-square)](https://packagist.org/packages/league/html-to-markdown) 7 | [![Software License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) 8 | [![Build Status](https://img.shields.io/travis/thephpleague/html-to-markdown/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/html-to-markdown) 9 | [![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/html-to-markdown.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/html-to-markdown/code-structure) 10 | [![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/html-to-markdown.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/html-to-markdown) 11 | [![Total Downloads](https://img.shields.io/packagist/dt/league/html-to-markdown.svg?style=flat-square)](https://packagist.org/packages/league/html-to-markdown) 12 | 13 | Library which converts HTML to [Markdown](http://daringfireball.net/projects/markdown/) for your sanity and convenience. 14 | 15 | 16 | **Requires**: PHP 5.3+ or PHP 7.0+ 17 | 18 | **Lead Developer**: [@colinodell](http://twitter.com/colinodell) 19 | 20 | **Original Author**: [@nickcernis](http://twitter.com/nickcernis) 21 | 22 | 23 | ### Why convert HTML to Markdown? 24 | 25 | *"What alchemy is this?"* you mutter. *"I can see why you'd convert [Markdown to HTML](https://github.com/thephpleague/commonmark),"* you continue, already labouring the question somewhat, *"but why go the other way?"* 26 | 27 | Typically you would convert HTML to Markdown if: 28 | 29 | 1. You have an existing HTML document that needs to be edited by people with good taste. 30 | 2. You want to store new content in HTML format but edit it as Markdown. 31 | 3. You want to convert HTML email to plain text email. 32 | 4. You know a guy who's been converting HTML to Markdown for years, and now he can speak Elvish. You'd quite like to be able to speak Elvish. 33 | 5. You just really like Markdown. 34 | 35 | ### How to use it 36 | 37 | Require the library by issuing this command: 38 | 39 | ```bash 40 | composer require league/html-to-markdown 41 | ``` 42 | 43 | Add `require 'vendor/autoload.php';` to the top of your script. 44 | 45 | Next, create a new HtmlConverter instance, passing in your valid HTML code to its `convert()` function: 46 | 47 | ```php 48 | use League\HTMLToMarkdown\HtmlConverter; 49 | 50 | $converter = new HtmlConverter(); 51 | 52 | $html = "<h3>Quick, to the Batpoles!</h3>"; 53 | $markdown = $converter->convert($html); 54 | ``` 55 | 56 | The `$markdown` variable now contains the Markdown version of your HTML as a string: 57 | 58 | ```php 59 | echo $markdown; // ==> ### Quick, to the Batpoles! 60 | ``` 61 | 62 | The included `demo` directory contains an HTML->Markdown conversion form to try out. 63 | 64 | ### Conversion options 65 | 66 | By default, HTML To Markdown preserves HTML tags without Markdown equivalents, like `<span>` and `<div>`. 67 | 68 | To strip HTML tags that don't have a Markdown equivalent while preserving the content inside them, set `strip_tags` to true, like this: 69 | 70 | ```php 71 | $converter = new HtmlConverter(array('strip_tags' => true)); 72 | 73 | $html = '<span>Turnips!</span>'; 74 | $markdown = $converter->convert($html); // $markdown now contains "Turnips!" 75 | ``` 76 | 77 | Or more explicitly, like this: 78 | 79 | ```php 80 | $converter = new HtmlConverter(); 81 | $converter->getConfig()->setOption('strip_tags', true); 82 | 83 | $html = '<span>Turnips!</span>'; 84 | $markdown = $converter->convert($html); // $markdown now contains "Turnips!" 85 | ``` 86 | 87 | Note that only the tags themselves are stripped, not the content they hold. 88 | 89 | To strip tags and their content, pass a space-separated list of tags in `remove_nodes`, like this: 90 | 91 | ```php 92 | $converter = new HtmlConverter(array('remove_nodes' => 'span div')); 93 | 94 | $html = '<span>Turnips!</span><div>Monkeys!</div>'; 95 | $markdown = $converter->convert($html); // $markdown now contains "" 96 | ``` 97 | 98 | By default, all comments are stripped from the content. To preserve them, use the `preserve_comments` option, like this: 99 | 100 | ```php 101 | $converter = new HtmlConverter(array('preserve_comments' => true)); 102 | 103 | $html = '<span>Turnips!</span><!-- Monkeys! -->'; 104 | $markdown = $converter->convert($html); // $markdown now contains "Turnips!<!-- Monkeys! -->" 105 | ``` 106 | 107 | To preserve only specific comments, set `preserve_comments` with an array of strings, like this: 108 | 109 | ```php 110 | $converter = new HtmlConverter(array('preserve_comments' => array('Eggs!'))); 111 | 112 | $html = '<span>Turnips!</span><!-- Monkeys! --><!-- Eggs! -->'; 113 | $markdown = $converter->convert($html); // $markdown now contains "Turnips!<!-- Eggs! -->" 114 | ``` 115 | 116 | ### Style options 117 | 118 | By default bold tags are converted using the asterisk syntax, and italic tags are converted using the underlined syntax. Change these by using the `bold_style` and `italic_style` options. 119 | 120 | ```php 121 | $converter = new HtmlConverter(); 122 | $converter->getConfig()->setOption('italic_style', '*'); 123 | $converter->getConfig()->setOption('bold_style', '__'); 124 | 125 | $html = '<em>Italic</em> and a <strong>bold</strong>'; 126 | $markdown = $converter->convert($html); // $markdown now contains "*Italic* and a __bold__" 127 | ``` 128 | 129 | ### Line break options 130 | 131 | By default, `br` tags are converted to two spaces followed by a newline character as per [traditional Markdown](https://daringfireball.net/projects/markdown/syntax#p). Set `hard_break` to `true` to omit the two spaces, as per GitHub Flavored Markdown (GFM). 132 | 133 | ```php 134 | $converter = new HtmlConverter(); 135 | $html = '<p>test<br>line break</p>'; 136 | 137 | $converter->getConfig()->setOption('hard_break', true); 138 | $markdown = $converter->convert($html); // $markdown now contains "test\nline break" 139 | 140 | $converter->getConfig()->setOption('hard_break', false); // default 141 | $markdown = $converter->convert($html); // $markdown now contains "test \nline break" 142 | ``` 143 | 144 | ### Autolinking options 145 | 146 | By default, `a` tags are converted to the easiest possible link syntax, i.e. if no text or title is available, then the `<url>` syntax will be used rather than the full `[url](url)` syntax. Set `use_autolinks` to `false` to change this behavior to always use the full link syntax. 147 | 148 | ```php 149 | $converter = new HtmlConverter(); 150 | $html = '<p><a href="https://thephpleague.com">https://thephpleague.com</a></p>'; 151 | 152 | $converter->getConfig()->setOption('use_autolinks', true); 153 | $markdown = $converter->convert($html); // $markdown now contains "<https://thephpleague.com>" 154 | 155 | $converter->getConfig()->setOption('use_autolinks', false); // default 156 | $markdown = $converter->convert($html); // $markdown now contains "[https://google.com](https://google.com)" 157 | ``` 158 | 159 | ### Passing custom Environment object 160 | 161 | You can pass current `Environment` object to customize i.e. which converters should be used. 162 | 163 | ```php 164 | $environment = new Environment(array( 165 | // your configuration here 166 | )); 167 | $environment->addConverter(new HeaderConverter()); // optionally - add converter manually 168 | 169 | $converter = new HtmlConverter($environment); 170 | 171 | $html = '<h3>Header</h3> 172 | <img src="" /> 173 | '; 174 | $markdown = $converter->convert($html); // $markdown now contains "### Header" and "<img src="" />" 175 | ``` 176 | 177 | ### Limitations 178 | 179 | - Markdown Extra, MultiMarkdown and other variants aren't supported – just Markdown. 180 | 181 | ### Known issues 182 | 183 | - Nested lists and lists containing multiple paragraphs aren't converted correctly. 184 | - Lists inside blockquotes aren't converted correctly. 185 | - Any reported [open issues here](https://github.com/thephpleague/html-to-markdown/issues?state=open). 186 | 187 | [Report your issue or request a feature here.](https://github.com/thephpleague/html-to-markdown/issues/new) Issues with patches or failing tests are especially welcome. 188 | 189 | ### Style notes 190 | 191 | - Setext (underlined) headers are the default for H1 and H2. If you prefer the ATX style for H1 and H2 (# Header 1 and ## Header 2), set `header_style` to 'atx' in the options array when you instantiate the object: 192 | 193 | `$converter = new HtmlConverter(array('header_style'=>'atx'));` 194 | 195 | Headers of H3 priority and lower always use atx style. 196 | 197 | - Links and images are referenced inline. Footnote references (where image src and anchor href attributes are listed in the footnotes) are not used. 198 | - Blockquotes aren't line wrapped – it makes the converted Markdown easier to edit. 199 | 200 | ### Dependencies 201 | 202 | HTML To Markdown requires PHP's [xml](http://www.php.net/manual/en/xml.installation.php), [lib-xml](http://www.php.net/manual/en/libxml.installation.php), and [dom](http://www.php.net/manual/en/dom.installation.php) extensions, all of which are enabled by default on most distributions. 203 | 204 | Errors such as "Fatal error: Class 'DOMDocument' not found" on distributions such as CentOS that disable PHP's xml extension can be resolved by installing php-xml. 205 | 206 | ### Contributors 207 | 208 | Many thanks to all [contributors](https://github.com/thephpleague/html-to-markdown/graphs/contributors) so far. Further improvements and feature suggestions are very welcome. 209 | 210 | ### How it works 211 | 212 | HTML To Markdown creates a DOMDocument from the supplied HTML, walks through the tree, and converts each node to a text node containing the equivalent markdown, starting from the most deeply nested node and working inwards towards the root node. 213 | 214 | ### To-do 215 | 216 | - Support for nested lists and lists inside blockquotes. 217 | - Offer an option to preserve tags as HTML if they contain attributes that can't be represented with Markdown (e.g. `style`). 218 | 219 | ### Trying to convert Markdown to HTML? 220 | 221 | Use one of these great libraries: 222 | 223 | - [league/commonmark](https://github.com/thephpleague/commonmark) (recommended) 224 | - [cebe/markdown](https://github.com/cebe/markdown) 225 | - [PHP Markdown](https://michelf.ca/projects/php-markdown/) 226 | - [Parsedown](https://github.com/erusev/parsedown) 227 | 228 | No guarantees about the Elvish, though. 229 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/bin/html-to-markdown: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | <?php 3 | 4 | requireAutoloader(); 5 | 6 | ini_set('display_errors', 'stderr'); 7 | 8 | foreach ($argv as $i => $arg) { 9 | if ($i === 0) { 10 | continue; 11 | } 12 | 13 | if (substr($arg, 0, 1) === '-') { 14 | switch ($arg) { 15 | case '-h': 16 | case '--help': 17 | echo getHelpText(); 18 | exit(0); 19 | default: 20 | fail('Unknown option: ' . $arg); 21 | } 22 | } else { 23 | $src = $argv[1]; 24 | } 25 | } 26 | 27 | if (isset($src)) { 28 | if (!file_exists($src)) { 29 | fail('File not found: ' . $src); 30 | } 31 | 32 | $html = file_get_contents($src); 33 | } else { 34 | $stdin = fopen('php://stdin', 'r'); 35 | stream_set_blocking($stdin, false); 36 | $html = stream_get_contents($stdin); 37 | fclose($stdin); 38 | 39 | if (empty($html)) { 40 | fail(getHelpText()); 41 | } 42 | } 43 | 44 | 45 | $converter = new League\HTMLToMarkdown\HtmlConverter(); 46 | echo $converter->convert($html); 47 | 48 | /** 49 | * Get help and usage info 50 | * 51 | * @return string 52 | */ 53 | function getHelpText() 54 | { 55 | return <<<HELP 56 | HTML To Markdown 57 | 58 | Usage: html-to-markdown [OPTIONS] [FILE] 59 | 60 | -h, --help Shows help and usage information 61 | 62 | If no file is given, input will be read from STDIN 63 | 64 | Examples: 65 | 66 | Converting a file named document.html: 67 | 68 | html-to-markdown document.html 69 | 70 | Converting a file and saving its output: 71 | 72 | html-to-markdown document.html > output.md 73 | 74 | Converting from STDIN: 75 | 76 | echo -e '<h1>Hello World!</h1>' | html-to-markdown 77 | 78 | Converting from STDIN and saving the output: 79 | 80 | echo -e '<h1>Hello World!</h1>' | html-to-markdown > output.md 81 | 82 | HELP; 83 | } 84 | 85 | /** 86 | * @param string $message Error message 87 | */ 88 | function fail($message) 89 | { 90 | fwrite(STDERR, $message . "\n"); 91 | exit(1); 92 | } 93 | 94 | function requireAutoloader() 95 | { 96 | $autoloadPaths = array( 97 | // Local package usage 98 | __DIR__ . '/../vendor/autoload.php', 99 | // Package was included as a library 100 | __DIR__ . '/../../../autoload.php', 101 | ); 102 | foreach ($autoloadPaths as $path) { 103 | if (file_exists($path)) { 104 | require_once $path; 105 | break; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "league/html-to-markdown", 3 | "type": "library", 4 | "description": "An HTML-to-markdown conversion helper for PHP", 5 | "keywords": ["markdown", "html"], 6 | "homepage": "https://github.com/thephpleague/html-to-markdown", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Colin O'Dell", 11 | "email": "colinodell@gmail.com", 12 | "homepage": "https://www.colinodell.com", 13 | "role": "Lead Developer" 14 | }, 15 | { 16 | "name": "Nick Cernis", 17 | "email": "nick@cern.is", 18 | "homepage": "http://modernnerd.net", 19 | "role": "Original Author" 20 | } 21 | ], 22 | "autoload": { 23 | "psr-4": { 24 | "League\\HTMLToMarkdown\\": "src/" 25 | } 26 | }, 27 | "autoload-dev": { 28 | "psr-4": { 29 | "League\\HTMLToMarkdown\\Test\\": "tests" 30 | } 31 | }, 32 | "require": { 33 | "php": ">=5.3.3", 34 | "ext-dom": "*", 35 | "ext-xml": "*" 36 | }, 37 | "require-dev": { 38 | "mikehaertl/php-shellcommand": "~1.1.0", 39 | "phpunit/phpunit": "^4.8|^5.7", 40 | "scrutinizer/ocular": "~1.1" 41 | }, 42 | "bin": ["bin/html-to-markdown"], 43 | "extra": { 44 | "branch-alias": { 45 | "dev-master": "4.10-dev" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Configuration.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | class Configuration 6 | { 7 | protected $config; 8 | 9 | /** 10 | * @param array $config 11 | */ 12 | public function __construct(array $config = array()) 13 | { 14 | $this->config = $config; 15 | 16 | $this->checkForDeprecatedOptions($config); 17 | } 18 | 19 | /** 20 | * @param array $config 21 | */ 22 | public function merge(array $config = array()) 23 | { 24 | $this->checkForDeprecatedOptions($config); 25 | $this->config = array_replace_recursive($this->config, $config); 26 | } 27 | 28 | /** 29 | * @param array $config 30 | */ 31 | public function replace(array $config = array()) 32 | { 33 | $this->checkForDeprecatedOptions($config); 34 | $this->config = $config; 35 | } 36 | 37 | /** 38 | * @param string $key 39 | * @param mixed $value 40 | */ 41 | public function setOption($key, $value) 42 | { 43 | $this->checkForDeprecatedOptions(array($key => $value)); 44 | $this->config[$key] = $value; 45 | } 46 | 47 | /** 48 | * @param string|null $key 49 | * @param mixed|null $default 50 | * 51 | * @return mixed|null 52 | */ 53 | public function getOption($key = null, $default = null) 54 | { 55 | if ($key === null) { 56 | return $this->config; 57 | } 58 | 59 | if (!isset($this->config[$key])) { 60 | return $default; 61 | } 62 | 63 | return $this->config[$key]; 64 | } 65 | 66 | private function checkForDeprecatedOptions(array $config) 67 | { 68 | foreach ($config as $key => $value) { 69 | if ($key === 'bold_style' && $value !== '**') { 70 | @trigger_error('Customizing the bold_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED); 71 | } elseif ($key === 'italic_style' && $value !== '*') { 72 | @trigger_error('Customizing the italic_style option is deprecated and may be removed in the next major version', E_USER_DEPRECATED); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/ConfigurationAwareInterface.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | interface ConfigurationAwareInterface 6 | { 7 | /** 8 | * @param Configuration $config 9 | */ 10 | public function setConfig(Configuration $config); 11 | } 12 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/BlockquoteConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class BlockquoteConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | // Contents should have already been converted to Markdown by this point, 17 | // so we just need to add '>' symbols to each line. 18 | 19 | $markdown = ''; 20 | 21 | $quote_content = trim($element->getValue()); 22 | 23 | $lines = preg_split('/\r\n|\r|\n/', $quote_content); 24 | 25 | $total_lines = count($lines); 26 | 27 | foreach ($lines as $i => $line) { 28 | $markdown .= '> ' . $line . "\n"; 29 | if ($i + 1 === $total_lines) { 30 | $markdown .= "\n"; 31 | } 32 | } 33 | 34 | return $markdown; 35 | } 36 | 37 | /** 38 | * @return string[] 39 | */ 40 | public function getSupportedTags() 41 | { 42 | return array('blockquote'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/CodeConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class CodeConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | $language = ''; 17 | 18 | // Checking for language class on the code block 19 | $classes = $element->getAttribute('class'); 20 | 21 | if ($classes) { 22 | // Since tags can have more than one class, we need to find the one that starts with 'language-' 23 | $classes = explode(' ', $classes); 24 | foreach ($classes as $class) { 25 | if (strpos($class, 'language-') !== false) { 26 | // Found one, save it as the selected language and stop looping over the classes. 27 | $language = str_replace('language-', '', $class); 28 | break; 29 | } 30 | } 31 | } 32 | 33 | $markdown = ''; 34 | $code = html_entity_decode($element->getChildrenAsString()); 35 | 36 | // In order to remove the code tags we need to search for them and, in the case of the opening tag 37 | // use a regular expression to find the tag and the other attributes it might have 38 | $code = preg_replace('/<code\b[^>]*>/', '', $code); 39 | $code = str_replace('</code>', '', $code); 40 | 41 | // Checking if it's a code block or span 42 | if ($this->shouldBeBlock($element, $code)) { 43 | // Code block detected, newlines will be added in parent 44 | $markdown .= '```' . $language . "\n" . $code . "\n" . '```'; 45 | } else { 46 | // One line of code, wrapping it on one backtick, removing new lines 47 | $markdown .= '`' . preg_replace('/\r\n|\r|\n/', '', $code) . '`'; 48 | } 49 | 50 | return $markdown; 51 | } 52 | 53 | /** 54 | * @return string[] 55 | */ 56 | public function getSupportedTags() 57 | { 58 | return array('code'); 59 | } 60 | 61 | /** 62 | * @param ElementInterface $element 63 | * @param string $code 64 | * 65 | * @return bool 66 | */ 67 | private function shouldBeBlock(ElementInterface $element, $code) 68 | { 69 | if ($element->getParent()->getTagName() == 'pre') { 70 | return true; 71 | } 72 | 73 | if (preg_match('/[^\s]` `/', $code)) { 74 | return true; 75 | } 76 | 77 | return false; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/CommentConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class CommentConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @param Configuration $config 18 | */ 19 | public function setConfig(Configuration $config) 20 | { 21 | $this->config = $config; 22 | } 23 | 24 | /** 25 | * @param ElementInterface $element 26 | * 27 | * @return string 28 | */ 29 | public function convert(ElementInterface $element) 30 | { 31 | if ($this->shouldPreserve($element)) { 32 | return '<!--' . $element->getValue() . '-->'; 33 | } 34 | return ''; 35 | } 36 | 37 | /** 38 | * @return string[] 39 | */ 40 | public function getSupportedTags() 41 | { 42 | return array('#comment'); 43 | } 44 | 45 | /** 46 | * @param ElementInterface $element 47 | * 48 | * @return bool 49 | */ 50 | private function shouldPreserve(ElementInterface $element) 51 | { 52 | $preserve = $this->config->getOption('preserve_comments'); 53 | if ($preserve === true) { 54 | return true; 55 | } 56 | if (is_array($preserve)) { 57 | $value = trim($element->getValue()); 58 | return in_array($value, $preserve); 59 | } 60 | return false; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/ConverterInterface.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | interface ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element); 15 | 16 | /** 17 | * @return string[] 18 | */ 19 | public function getSupportedTags(); 20 | } 21 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/DefaultConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class DefaultConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | const DEFAULT_CONVERTER = '_default'; 12 | 13 | /** 14 | * @var Configuration 15 | */ 16 | protected $config; 17 | 18 | /** 19 | * @param Configuration $config 20 | */ 21 | public function setConfig(Configuration $config) 22 | { 23 | $this->config = $config; 24 | } 25 | 26 | /** 27 | * @param ElementInterface $element 28 | * 29 | * @return string 30 | */ 31 | public function convert(ElementInterface $element) 32 | { 33 | // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents, 34 | // such as <span> nodes on their own. C14N() canonicalizes the node to a string. 35 | // See: http://www.php.net/manual/en/domnode.c14n.php 36 | if ($this->config->getOption('strip_tags', false)) { 37 | return $element->getValue(); 38 | } 39 | 40 | $markdown = html_entity_decode($element->getChildrenAsString()); 41 | 42 | if ($element->getTagName() === 'table') { 43 | $markdown .= "\n\n"; 44 | } 45 | 46 | return $markdown; 47 | } 48 | 49 | /** 50 | * @return string[] 51 | */ 52 | public function getSupportedTags() 53 | { 54 | return array(self::DEFAULT_CONVERTER); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/DivConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class DivConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @param Configuration $config 18 | */ 19 | public function setConfig(Configuration $config) 20 | { 21 | $this->config = $config; 22 | } 23 | 24 | /** 25 | * @param ElementInterface $element 26 | * 27 | * @return string 28 | */ 29 | public function convert(ElementInterface $element) 30 | { 31 | if ($this->config->getOption('strip_tags', false)) { 32 | return $element->getValue() . "\n\n"; 33 | } 34 | 35 | return html_entity_decode($element->getChildrenAsString()); 36 | } 37 | 38 | /** 39 | * @return string[] 40 | */ 41 | public function getSupportedTags() 42 | { 43 | return array('div'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/EmphasisConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class EmphasisConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @param Configuration $config 18 | */ 19 | public function setConfig(Configuration $config) 20 | { 21 | $this->config = $config; 22 | } 23 | 24 | /** 25 | * @param ElementInterface $element 26 | * 27 | * @return string 28 | */ 29 | public function convert(ElementInterface $element) 30 | { 31 | $tag = $element->getTagName(); 32 | $value = $element->getValue(); 33 | 34 | if (!trim($value)) { 35 | return $value; 36 | } 37 | 38 | if ($tag === 'i' || $tag === 'em') { 39 | $style = $this->config->getOption('italic_style'); 40 | } else { 41 | $style = $this->config->getOption('bold_style'); 42 | } 43 | 44 | $prefix = ltrim($value) !== $value ? ' ' : ''; 45 | $suffix = rtrim($value) !== $value ? ' ' : ''; 46 | 47 | return $prefix . $style . trim($value) . $style . $suffix; 48 | } 49 | 50 | /** 51 | * @return string[] 52 | */ 53 | public function getSupportedTags() 54 | { 55 | return array('em', 'i', 'strong', 'b'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/HardBreakConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class HardBreakConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @param Configuration $config 18 | */ 19 | public function setConfig(Configuration $config) 20 | { 21 | $this->config = $config; 22 | } 23 | 24 | /** 25 | * @param ElementInterface $element 26 | * 27 | * @return string 28 | */ 29 | public function convert(ElementInterface $element) 30 | { 31 | $return = $this->config->getOption('hard_break') ? "\n" : " \n"; 32 | 33 | $next = $element->getNext(); 34 | if ($next) { 35 | $next_value = $next->getValue(); 36 | if ($next_value) { 37 | if (in_array(substr($next_value, 0, 2), array('- ', '* ', '+ '))) { 38 | $parent = $element->getParent(); 39 | if ($parent && $parent->getTagName() == 'li') { 40 | $return .= '\\'; 41 | } 42 | } 43 | } 44 | } 45 | 46 | return $return; 47 | } 48 | 49 | /** 50 | * @return string[] 51 | */ 52 | public function getSupportedTags() 53 | { 54 | return array('br'); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/HeaderConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class HeaderConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | const STYLE_ATX = 'atx'; 12 | const STYLE_SETEXT = 'setext'; 13 | 14 | /** 15 | * @var Configuration 16 | */ 17 | protected $config; 18 | 19 | /** 20 | * @param Configuration $config 21 | */ 22 | public function setConfig(Configuration $config) 23 | { 24 | $this->config = $config; 25 | } 26 | 27 | /** 28 | * @param ElementInterface $element 29 | * 30 | * @return string 31 | */ 32 | public function convert(ElementInterface $element) 33 | { 34 | $level = (int) substr($element->getTagName(), 1, 1); 35 | $style = $this->config->getOption('header_style', self::STYLE_SETEXT); 36 | 37 | if (strlen($element->getValue()) === 0) { 38 | return "\n"; 39 | } 40 | 41 | if (($level === 1 || $level === 2) && !$element->isDescendantOf('blockquote') && $style === self::STYLE_SETEXT) { 42 | return $this->createSetextHeader($level, $element->getValue()); 43 | } 44 | 45 | return $this->createAtxHeader($level, $element->getValue()); 46 | } 47 | 48 | /** 49 | * @return string[] 50 | */ 51 | public function getSupportedTags() 52 | { 53 | return array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'); 54 | } 55 | 56 | /** 57 | * @param int $level 58 | * @param string $content 59 | * 60 | * @return string 61 | */ 62 | private function createSetextHeader($level, $content) 63 | { 64 | $length = function_exists('mb_strlen') ? mb_strlen($content, 'utf-8') : strlen($content); 65 | $underline = ($level === 1) ? '=' : '-'; 66 | 67 | return $content . "\n" . str_repeat($underline, $length) . "\n\n"; 68 | } 69 | 70 | /** 71 | * @param int $level 72 | * @param string $content 73 | * 74 | * @return string 75 | */ 76 | private function createAtxHeader($level, $content) 77 | { 78 | $prefix = str_repeat('#', $level) . ' '; 79 | 80 | return $prefix . $content . "\n\n"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/HorizontalRuleConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class HorizontalRuleConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | return "- - - - - -\n\n"; 17 | } 18 | 19 | /** 20 | * @return string[] 21 | */ 22 | public function getSupportedTags() 23 | { 24 | return array('hr'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/ImageConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class ImageConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | $src = $element->getAttribute('src'); 17 | $alt = $element->getAttribute('alt'); 18 | $title = $element->getAttribute('title'); 19 | 20 | if ($title !== '') { 21 | // No newlines added. <img> should be in a block-level element. 22 | return '![' . $alt . '](' . $src . ' "' . $title . '")'; 23 | } 24 | 25 | return '![' . $alt . '](' . $src . ')'; 26 | } 27 | 28 | /** 29 | * @return string[] 30 | */ 31 | public function getSupportedTags() 32 | { 33 | return array('img'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/LinkConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class LinkConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @param Configuration $config 18 | */ 19 | public function setConfig(Configuration $config) { 20 | $this->config = $config; 21 | } 22 | 23 | /** 24 | * @param ElementInterface $element 25 | * 26 | * @return string 27 | */ 28 | public function convert(ElementInterface $element) 29 | { 30 | $href = $element->getAttribute('href'); 31 | $title = $element->getAttribute('title'); 32 | $text = trim($element->getValue(), "\t\n\r\0\x0B"); 33 | 34 | if ($title !== '') { 35 | $markdown = '[' . $text . '](' . $href . ' "' . $title . '")'; 36 | } elseif ($href === $text && $this->isValidAutolink($href)) { 37 | $markdown = '<' . $href . '>'; 38 | } elseif ($href === 'mailto:' . $text && $this->isValidEmail($text)) { 39 | $markdown = '<' . $text . '>'; 40 | } else { 41 | if (stristr($href, ' ')) { 42 | $href = '<'.$href.'>'; 43 | } 44 | $markdown = '[' . $text . '](' . $href . ')'; 45 | } 46 | 47 | if (!$href) { 48 | $markdown = html_entity_decode($element->getChildrenAsString()); 49 | } 50 | 51 | return $markdown; 52 | } 53 | 54 | /** 55 | * @return string[] 56 | */ 57 | public function getSupportedTags() 58 | { 59 | return array('a'); 60 | } 61 | 62 | /** 63 | * @param string $href 64 | * 65 | * @return bool 66 | */ 67 | private function isValidAutolink($href) 68 | { 69 | $useAutolinks = $this->config->getOption('use_autolinks'); 70 | return $useAutolinks && (preg_match('/^[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*/i', $href) === 1); 71 | } 72 | 73 | /** 74 | * @param string $email 75 | * 76 | * @return bool 77 | */ 78 | private function isValidEmail($email) 79 | { 80 | // Email validation is messy business, but this should cover most cases 81 | return filter_var($email, FILTER_VALIDATE_EMAIL); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/ListBlockConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class ListBlockConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | return $element->getValue() . "\n"; 17 | } 18 | 19 | /** 20 | * @return string[] 21 | */ 22 | public function getSupportedTags() 23 | { 24 | return array('ol', 'ul'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/ListItemConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\Configuration; 6 | use League\HTMLToMarkdown\ConfigurationAwareInterface; 7 | use League\HTMLToMarkdown\ElementInterface; 8 | 9 | class ListItemConverter implements ConverterInterface, ConfigurationAwareInterface 10 | { 11 | /** 12 | * @var Configuration 13 | */ 14 | protected $config; 15 | 16 | /** 17 | * @var string 18 | */ 19 | protected $listItemStyle; 20 | 21 | /** 22 | * @param Configuration $config 23 | */ 24 | public function setConfig(Configuration $config) 25 | { 26 | $this->config = $config; 27 | } 28 | 29 | /** 30 | * @param ElementInterface $element 31 | * 32 | * @return string 33 | */ 34 | public function convert(ElementInterface $element) 35 | { 36 | // If parent is an ol, use numbers, otherwise, use dashes 37 | $list_type = $element->getParent()->getTagName(); 38 | 39 | // Add spaces to start for nested list items 40 | $level = $element->getListItemLevel($element); 41 | 42 | $prefixForParagraph = str_repeat(' ', $level + 1); 43 | $value = trim(implode("\n" . $prefixForParagraph, explode("\n", trim($element->getValue())))); 44 | 45 | // If list item is the first in a nested list, add a newline before it 46 | $prefix = ''; 47 | if ($level > 0 && $element->getSiblingPosition() === 1) { 48 | $prefix = "\n"; 49 | } 50 | 51 | if ($list_type === 'ul') { 52 | $list_item_style = $this->config->getOption('list_item_style', '-'); 53 | $list_item_style_alternate = $this->config->getOption('list_item_style_alternate'); 54 | if (!isset($this->listItemStyle)) { 55 | $this->listItemStyle = $list_item_style_alternate ? $list_item_style_alternate : $list_item_style; 56 | } 57 | 58 | if ($list_item_style_alternate && $level == 0 && $element->getSiblingPosition() === 1) { 59 | $this->listItemStyle = $this->listItemStyle == $list_item_style ? $list_item_style_alternate : $list_item_style; 60 | } 61 | 62 | return $prefix . $this->listItemStyle . ' ' . $value . "\n"; 63 | } 64 | 65 | if ($list_type === 'ol' && $start = $element->getParent()->getAttribute('start')) { 66 | $number = $start + $element->getSiblingPosition() - 1; 67 | } else { 68 | $number = $element->getSiblingPosition(); 69 | } 70 | 71 | return $prefix . $number . '. ' . $value . "\n"; 72 | } 73 | 74 | /** 75 | * @return string[] 76 | */ 77 | public function getSupportedTags() 78 | { 79 | return array('li'); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class ParagraphConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | $value = $element->getValue(); 17 | 18 | $markdown = ''; 19 | 20 | $lines = preg_split('/\r\n|\r|\n/', $value); 21 | foreach ($lines as $line) { 22 | /* 23 | * Some special characters need to be escaped based on the position that they appear 24 | * The following function will deal with those special cases. 25 | */ 26 | $markdown .= $this->escapeSpecialCharacters($line); 27 | $markdown .= "\n"; 28 | } 29 | 30 | return trim($markdown) !== '' ? rtrim($markdown) . "\n\n" : ''; 31 | } 32 | 33 | /** 34 | * @return string[] 35 | */ 36 | public function getSupportedTags() 37 | { 38 | return array('p'); 39 | } 40 | 41 | /** 42 | * @param string $line 43 | * 44 | * @return string 45 | */ 46 | private function escapeSpecialCharacters($line) 47 | { 48 | $line = $this->escapeFirstCharacters($line); 49 | $line = $this->escapeOtherCharacters($line); 50 | $line = $this->escapeOtherCharactersRegex($line); 51 | 52 | return $line; 53 | } 54 | 55 | /** 56 | * @param string $line 57 | * 58 | * @return string 59 | */ 60 | private function escapeFirstCharacters($line) 61 | { 62 | $escapable = array( 63 | '>', 64 | '- ', 65 | '+ ', 66 | '--', 67 | '~~~', 68 | '---', 69 | '- - -' 70 | ); 71 | 72 | foreach ($escapable as $i) { 73 | if (strpos(ltrim($line), $i) === 0) { 74 | // Found a character that must be escaped, adding a backslash before 75 | return '\\' . ltrim($line); 76 | } 77 | } 78 | 79 | return $line; 80 | } 81 | 82 | /** 83 | * @param string $line 84 | * 85 | * @return string 86 | */ 87 | private function escapeOtherCharacters($line) 88 | { 89 | $escapable = array( 90 | '<!--' 91 | ); 92 | 93 | foreach ($escapable as $i) { 94 | if (strpos($line, $i) !== false) { 95 | // Found an escapable character, escaping it 96 | $line = substr_replace($line, '\\', strpos($line, $i), 0); 97 | } 98 | } 99 | 100 | return $line; 101 | } 102 | 103 | /** 104 | * @param string $line 105 | * 106 | * @return string 107 | */ 108 | private function escapeOtherCharactersRegex($line) 109 | { 110 | $regExs = array( 111 | // Match numbers ending on ')' or '.' that are at the beginning of the line. 112 | // They will be escaped if immediately followed by a space or newline. 113 | '/^[0-9]+(?=(\)|\.)( |$))/' 114 | ); 115 | 116 | foreach ($regExs as $i) { 117 | if (preg_match($i, $line, $match)) { 118 | // Matched an escapable character, adding a backslash on the string before the offending character 119 | $line = substr_replace($line, '\\', strlen($match[0]), 0); 120 | } 121 | } 122 | 123 | return $line; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class PreformattedConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | $pre_content = html_entity_decode($element->getChildrenAsString()); 17 | $pre_content = str_replace(array('<pre>', '</pre>'), '', $pre_content); 18 | 19 | /* 20 | * Checking for the code tag. 21 | * Usually pre tags are used along with code tags. This conditional will check for already converted code tags, 22 | * which use backticks, and if those backticks are at the beginning and at the end of the string it means 23 | * there's no more information to convert. 24 | */ 25 | 26 | $firstBacktick = strpos(trim($pre_content), '`'); 27 | $lastBacktick = strrpos(trim($pre_content), '`'); 28 | if ($firstBacktick === 0 && $lastBacktick === strlen(trim($pre_content)) - 1) { 29 | return $pre_content . "\n\n"; 30 | } 31 | 32 | // If the execution reaches this point it means it's just a pre tag, with no code tag nested 33 | 34 | // Empty lines are a special case 35 | if ($pre_content === '') { 36 | return "```\n```\n\n"; 37 | } 38 | 39 | // Normalizing new lines 40 | $pre_content = preg_replace('/\r\n|\r|\n/', "\n", $pre_content); 41 | 42 | // Ensure there's a newline at the end 43 | if (strrpos($pre_content, "\n") !== strlen($pre_content) - strlen("\n")) { 44 | $pre_content .= "\n"; 45 | } 46 | 47 | // Use three backticks 48 | return "```\n" . $pre_content . "```\n\n"; 49 | } 50 | 51 | /** 52 | * @return string[] 53 | */ 54 | public function getSupportedTags() 55 | { 56 | return array('pre'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Converter/TextConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown\Converter; 4 | 5 | use League\HTMLToMarkdown\ElementInterface; 6 | 7 | class TextConverter implements ConverterInterface 8 | { 9 | /** 10 | * @param ElementInterface $element 11 | * 12 | * @return string 13 | */ 14 | public function convert(ElementInterface $element) 15 | { 16 | $markdown = $element->getValue(); 17 | 18 | // Remove leftover \n at the beginning of the line 19 | $markdown = ltrim($markdown, "\n"); 20 | 21 | // Replace sequences of invisible characters with spaces 22 | $markdown = preg_replace('~\s+~u', ' ', $markdown); 23 | 24 | // Escape the following characters: '*', '_', '[', ']' and '\' 25 | if ($element->getParent() && $element->getParent()->getTagName() !== 'div') { 26 | $markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown); 27 | } 28 | 29 | $markdown = preg_replace('~^#~u', '\\\\#', $markdown); 30 | 31 | if ($markdown === ' ') { 32 | $next = $element->getNext(); 33 | if (!$next || $next->isBlock()) { 34 | $markdown = ''; 35 | } 36 | } 37 | 38 | return htmlspecialchars($markdown, ENT_NOQUOTES, 'UTF-8'); 39 | } 40 | 41 | /** 42 | * @return string[] 43 | */ 44 | public function getSupportedTags() 45 | { 46 | return array('#text'); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Element.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | class Element implements ElementInterface 6 | { 7 | /** 8 | * @var \DOMNode 9 | */ 10 | protected $node; 11 | 12 | /** 13 | * @var ElementInterface|null 14 | */ 15 | private $nextCached; 16 | 17 | public function __construct(\DOMNode $node) 18 | { 19 | $this->node = $node; 20 | } 21 | 22 | /** 23 | * @return bool 24 | */ 25 | public function isBlock() 26 | { 27 | switch ($this->getTagName()) { 28 | case 'blockquote': 29 | case 'body': 30 | case 'div': 31 | case 'h1': 32 | case 'h2': 33 | case 'h3': 34 | case 'h4': 35 | case 'h5': 36 | case 'h6': 37 | case 'hr': 38 | case 'html': 39 | case 'li': 40 | case 'p': 41 | case 'ol': 42 | case 'ul': 43 | return true; 44 | default: 45 | return false; 46 | } 47 | } 48 | 49 | /** 50 | * @return bool 51 | */ 52 | public function isText() 53 | { 54 | return $this->getTagName() === '#text'; 55 | } 56 | 57 | /** 58 | * @return bool 59 | */ 60 | public function isWhitespace() 61 | { 62 | return $this->getTagName() === '#text' && trim($this->getValue()) === ''; 63 | } 64 | 65 | /** 66 | * @return string 67 | */ 68 | public function getTagName() 69 | { 70 | return $this->node->nodeName; 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function getValue() 77 | { 78 | return $this->node->nodeValue; 79 | } 80 | 81 | /** 82 | * @return ElementInterface|null 83 | */ 84 | public function getParent() 85 | { 86 | return new static($this->node->parentNode) ?: null; 87 | } 88 | 89 | /** 90 | * @return bool 91 | */ 92 | public function hasChildren() 93 | { 94 | return $this->node->hasChildNodes(); 95 | } 96 | 97 | /** 98 | * @return ElementInterface[] 99 | */ 100 | public function getChildren() 101 | { 102 | $ret = array(); 103 | /** @var \DOMNode $node */ 104 | foreach ($this->node->childNodes as $node) { 105 | $ret[] = new static($node); 106 | } 107 | 108 | return $ret; 109 | } 110 | 111 | /** 112 | * @return ElementInterface|null 113 | */ 114 | public function getNext() 115 | { 116 | if ($this->nextCached === null) { 117 | $nextNode = $this->getNextNode($this->node); 118 | if ($nextNode !== null) { 119 | $this->nextCached = new static($nextNode); 120 | } 121 | } 122 | 123 | return $this->nextCached; 124 | } 125 | 126 | /** 127 | * @param \DomNode $node 128 | * @param bool $checkChildren 129 | * 130 | * @return \DomNode|null 131 | */ 132 | private function getNextNode($node, $checkChildren = true) 133 | { 134 | if ($checkChildren && $node->firstChild) { 135 | return $node->firstChild; 136 | } 137 | 138 | if ($node->nextSibling) { 139 | return $node->nextSibling; 140 | } 141 | 142 | if ($node->parentNode) { 143 | return $this->getNextNode($node->parentNode, false); 144 | } 145 | } 146 | 147 | /** 148 | * @param string[]|string $tagNames 149 | * 150 | * @return bool 151 | */ 152 | public function isDescendantOf($tagNames) 153 | { 154 | if (!is_array($tagNames)) { 155 | $tagNames = array($tagNames); 156 | } 157 | 158 | for ($p = $this->node->parentNode; $p !== false; $p = $p->parentNode) { 159 | if (is_null($p)) { 160 | return false; 161 | } 162 | 163 | if (in_array($p->nodeName, $tagNames)) { 164 | return true; 165 | } 166 | } 167 | 168 | return false; 169 | } 170 | 171 | /** 172 | * @param string $markdown 173 | */ 174 | public function setFinalMarkdown($markdown) 175 | { 176 | $markdown_node = $this->node->ownerDocument->createTextNode($markdown); 177 | $this->node->parentNode->replaceChild($markdown_node, $this->node); 178 | } 179 | 180 | /** 181 | * @return string 182 | */ 183 | public function getChildrenAsString() 184 | { 185 | return $this->node->C14N(); 186 | } 187 | 188 | /** 189 | * @return int 190 | */ 191 | public function getSiblingPosition() 192 | { 193 | $position = 0; 194 | 195 | // Loop through all nodes and find the given $node 196 | foreach ($this->getParent()->getChildren() as $current_node) { 197 | if (!$current_node->isWhitespace()) { 198 | $position++; 199 | } 200 | 201 | // TODO: Need a less-buggy way of comparing these 202 | // Perhaps we can somehow ensure that we always have the exact same object and use === instead? 203 | if ($this->equals($current_node)) { 204 | break; 205 | } 206 | } 207 | 208 | return $position; 209 | } 210 | 211 | /** 212 | * @return int 213 | */ 214 | public function getListItemLevel() 215 | { 216 | $level = 0; 217 | $parent = $this->getParent(); 218 | 219 | while ($parent !== null && $parent->node->parentNode) { 220 | if ($parent->getTagName() === 'li') { 221 | $level++; 222 | } 223 | $parent = $parent->getParent(); 224 | } 225 | 226 | return $level; 227 | } 228 | 229 | /** 230 | * @param string $name 231 | * 232 | * @return string 233 | */ 234 | public function getAttribute($name) 235 | { 236 | if ($this->node instanceof \DOMElement) { 237 | return $this->node->getAttribute($name); 238 | } 239 | 240 | return ''; 241 | } 242 | 243 | /** 244 | * @param ElementInterface $element 245 | * 246 | * @return bool 247 | */ 248 | public function equals(ElementInterface $element) 249 | { 250 | if ($element instanceof self) { 251 | return $element->node === $this->node; 252 | } 253 | 254 | return $element === $this; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/ElementInterface.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | interface ElementInterface 6 | { 7 | /** 8 | * @return bool 9 | */ 10 | public function isBlock(); 11 | 12 | /** 13 | * @return bool 14 | */ 15 | public function isText(); 16 | 17 | /** 18 | * @return bool 19 | */ 20 | public function isWhitespace(); 21 | 22 | /** 23 | * @return string 24 | */ 25 | public function getTagName(); 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getValue(); 31 | 32 | /** 33 | * @return ElementInterface|null 34 | */ 35 | public function getParent(); 36 | 37 | /** 38 | * @param string|string[] $tagNames 39 | * 40 | * @return bool 41 | */ 42 | public function isDescendantOf($tagNames); 43 | 44 | /** 45 | * @return bool 46 | */ 47 | public function hasChildren(); 48 | 49 | /** 50 | * @return ElementInterface[] 51 | */ 52 | public function getChildren(); 53 | 54 | /** 55 | * @return ElementInterface|null 56 | */ 57 | public function getNext(); 58 | 59 | /** 60 | * @return int 61 | */ 62 | public function getSiblingPosition(); 63 | 64 | /** 65 | * @return string 66 | */ 67 | public function getChildrenAsString(); 68 | 69 | /** 70 | * @param string $markdown 71 | */ 72 | public function setFinalMarkdown($markdown); 73 | 74 | /** 75 | * @param string $name 76 | * 77 | * @return string 78 | */ 79 | public function getAttribute($name); 80 | } 81 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/Environment.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | use League\HTMLToMarkdown\Converter\BlockquoteConverter; 6 | use League\HTMLToMarkdown\Converter\CodeConverter; 7 | use League\HTMLToMarkdown\Converter\CommentConverter; 8 | use League\HTMLToMarkdown\Converter\ConverterInterface; 9 | use League\HTMLToMarkdown\Converter\DefaultConverter; 10 | use League\HTMLToMarkdown\Converter\DivConverter; 11 | use League\HTMLToMarkdown\Converter\EmphasisConverter; 12 | use League\HTMLToMarkdown\Converter\HardBreakConverter; 13 | use League\HTMLToMarkdown\Converter\HeaderConverter; 14 | use League\HTMLToMarkdown\Converter\HorizontalRuleConverter; 15 | use League\HTMLToMarkdown\Converter\ImageConverter; 16 | use League\HTMLToMarkdown\Converter\LinkConverter; 17 | use League\HTMLToMarkdown\Converter\ListBlockConverter; 18 | use League\HTMLToMarkdown\Converter\ListItemConverter; 19 | use League\HTMLToMarkdown\Converter\ParagraphConverter; 20 | use League\HTMLToMarkdown\Converter\PreformattedConverter; 21 | use League\HTMLToMarkdown\Converter\TextConverter; 22 | 23 | final class Environment 24 | { 25 | /** 26 | * @var Configuration 27 | */ 28 | protected $config; 29 | 30 | /** 31 | * @var ConverterInterface[] 32 | */ 33 | protected $converters = array(); 34 | 35 | public function __construct(array $config = array()) 36 | { 37 | $this->config = new Configuration($config); 38 | $this->addConverter(new DefaultConverter()); 39 | } 40 | 41 | /** 42 | * @return Configuration 43 | */ 44 | public function getConfig() 45 | { 46 | return $this->config; 47 | } 48 | 49 | /** 50 | * @param ConverterInterface $converter 51 | */ 52 | public function addConverter(ConverterInterface $converter) 53 | { 54 | if ($converter instanceof ConfigurationAwareInterface) { 55 | $converter->setConfig($this->config); 56 | } 57 | 58 | foreach ($converter->getSupportedTags() as $tag) { 59 | $this->converters[$tag] = $converter; 60 | } 61 | } 62 | 63 | /** 64 | * @param string $tag 65 | * 66 | * @return ConverterInterface 67 | */ 68 | public function getConverterByTag($tag) 69 | { 70 | if (isset($this->converters[$tag])) { 71 | return $this->converters[$tag]; 72 | } 73 | 74 | return $this->converters[DefaultConverter::DEFAULT_CONVERTER]; 75 | } 76 | 77 | /** 78 | * @param array $config 79 | * 80 | * @return Environment 81 | */ 82 | public static function createDefaultEnvironment(array $config = array()) 83 | { 84 | $environment = new static($config); 85 | 86 | $environment->addConverter(new BlockquoteConverter()); 87 | $environment->addConverter(new CodeConverter()); 88 | $environment->addConverter(new CommentConverter()); 89 | $environment->addConverter(new DivConverter()); 90 | $environment->addConverter(new EmphasisConverter()); 91 | $environment->addConverter(new HardBreakConverter()); 92 | $environment->addConverter(new HeaderConverter()); 93 | $environment->addConverter(new HorizontalRuleConverter()); 94 | $environment->addConverter(new ImageConverter()); 95 | $environment->addConverter(new LinkConverter()); 96 | $environment->addConverter(new ListBlockConverter()); 97 | $environment->addConverter(new ListItemConverter()); 98 | $environment->addConverter(new ParagraphConverter()); 99 | $environment->addConverter(new PreformattedConverter()); 100 | $environment->addConverter(new TextConverter()); 101 | 102 | return $environment; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/HtmlConverter.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | /** 6 | * Class HtmlConverter 7 | * 8 | * A helper class to convert HTML to Markdown. 9 | * 10 | * @author Colin O'Dell <colinodell@gmail.com> 11 | * @author Nick Cernis <nick@cern.is> 12 | * 13 | * @link https://github.com/thephpleague/html-to-markdown/ Latest version on GitHub. 14 | * 15 | * @license http://www.opensource.org/licenses/mit-license.php MIT 16 | */ 17 | class HtmlConverter implements HtmlConverterInterface 18 | { 19 | /** 20 | * @var Environment 21 | */ 22 | protected $environment; 23 | 24 | /** 25 | * Constructor 26 | * 27 | * @param Environment|array $options Environment object or configuration options 28 | */ 29 | public function __construct($options = array()) 30 | { 31 | if ($options instanceof Environment) { 32 | $this->environment = $options; 33 | } elseif (is_array($options)) { 34 | $defaults = array( 35 | 'header_style' => 'setext', // Set to 'atx' to output H1 and H2 headers as # Header1 and ## Header2 36 | 'suppress_errors' => true, // Set to false to show warnings when loading malformed HTML 37 | 'strip_tags' => false, // Set to true to strip tags that don't have markdown equivalents. N.B. Strips tags, not their content. Useful to clean MS Word HTML output. 38 | 'bold_style' => '**', // DEPRECATED: Set to '__' if you prefer the underlined style 39 | 'italic_style' => '*', // DEPRECATED: Set to '_' if you prefer the underlined style 40 | 'remove_nodes' => '', // space-separated list of dom nodes that should be removed. example: 'meta style script' 41 | 'hard_break' => false, // Set to true to turn <br> into `\n` instead of ` \n` 42 | 'list_item_style' => '-', // Set the default character for each <li> in a <ul>. Can be '-', '*', or '+' 43 | 'preserve_comments' => false, // Set to true to preserve comments, or set to an array of strings to preserve specific comments 44 | 'use_autolinks' => true, // Set to true to use simple link syntax if possible. Will always use []() if set to false 45 | ); 46 | 47 | $this->environment = Environment::createDefaultEnvironment($defaults); 48 | 49 | $this->environment->getConfig()->merge($options); 50 | } 51 | } 52 | 53 | /** 54 | * @return Environment 55 | */ 56 | public function getEnvironment() 57 | { 58 | return $this->environment; 59 | } 60 | 61 | /** 62 | * @return Configuration 63 | */ 64 | public function getConfig() 65 | { 66 | return $this->environment->getConfig(); 67 | } 68 | 69 | /** 70 | * Convert 71 | * 72 | * @see HtmlConverter::convert 73 | * 74 | * @param string $html 75 | * 76 | * @return string The Markdown version of the html 77 | */ 78 | public function __invoke($html) 79 | { 80 | return $this->convert($html); 81 | } 82 | 83 | /** 84 | * Convert 85 | * 86 | * Loads HTML and passes to getMarkdown() 87 | * 88 | * @param string $html 89 | * 90 | * @throws \InvalidArgumentException 91 | * 92 | * @return string The Markdown version of the html 93 | */ 94 | public function convert($html) 95 | { 96 | if (trim($html) === '') { 97 | return ''; 98 | } 99 | 100 | $document = $this->createDOMDocument($html); 101 | 102 | // Work on the entire DOM tree (including head and body) 103 | if (!($root = $document->getElementsByTagName('html')->item(0))) { 104 | throw new \InvalidArgumentException('Invalid HTML was provided'); 105 | } 106 | 107 | $rootElement = new Element($root); 108 | $this->convertChildren($rootElement); 109 | 110 | // Store the now-modified DOMDocument as a string 111 | $markdown = $document->saveHTML(); 112 | 113 | return $this->sanitize($markdown); 114 | } 115 | 116 | /** 117 | * @param string $html 118 | * 119 | * @return \DOMDocument 120 | */ 121 | private function createDOMDocument($html) 122 | { 123 | $document = new \DOMDocument(); 124 | 125 | if ($this->getConfig()->getOption('suppress_errors')) { 126 | // Suppress conversion errors (from http://bit.ly/pCCRSX) 127 | libxml_use_internal_errors(true); 128 | } 129 | 130 | // Hack to load utf-8 HTML (from http://bit.ly/pVDyCt) 131 | $document->loadHTML('<?xml encoding="UTF-8">' . $html); 132 | $document->encoding = 'UTF-8'; 133 | 134 | if ($this->getConfig()->getOption('suppress_errors')) { 135 | libxml_clear_errors(); 136 | } 137 | 138 | return $document; 139 | } 140 | 141 | /** 142 | * Convert Children 143 | * 144 | * Recursive function to drill into the DOM and convert each node into Markdown from the inside out. 145 | * 146 | * Finds children of each node and convert those to #text nodes containing their Markdown equivalent, 147 | * starting with the innermost element and working up to the outermost element. 148 | * 149 | * @param ElementInterface $element 150 | */ 151 | private function convertChildren(ElementInterface $element) 152 | { 153 | // Don't convert HTML code inside <code> and <pre> blocks to Markdown - that should stay as HTML 154 | // except if the current node is a code tag, which needs to be converted by the CodeConverter. 155 | if ($element->isDescendantOf(array('pre', 'code')) && $element->getTagName() !== 'code') { 156 | return; 157 | } 158 | 159 | // If the node has children, convert those to Markdown first 160 | if ($element->hasChildren()) { 161 | foreach ($element->getChildren() as $child) { 162 | $this->convertChildren($child); 163 | } 164 | } 165 | 166 | // Now that child nodes have been converted, convert the original node 167 | $markdown = $this->convertToMarkdown($element); 168 | 169 | // Create a DOM text node containing the Markdown equivalent of the original node 170 | 171 | // Replace the old $node e.g. '<h3>Title</h3>' with the new $markdown_node e.g. '### Title' 172 | $element->setFinalMarkdown($markdown); 173 | } 174 | 175 | /** 176 | * Convert to Markdown 177 | * 178 | * Converts an individual node into a #text node containing a string of its Markdown equivalent. 179 | * 180 | * Example: An <h3> node with text content of 'Title' becomes a text node with content of '### Title' 181 | * 182 | * @param ElementInterface $element 183 | * 184 | * @return string The converted HTML as Markdown 185 | */ 186 | protected function convertToMarkdown(ElementInterface $element) 187 | { 188 | $tag = $element->getTagName(); 189 | 190 | // Strip nodes named in remove_nodes 191 | $tags_to_remove = explode(' ', $this->getConfig()->getOption('remove_nodes')); 192 | if (in_array($tag, $tags_to_remove)) { 193 | return false; 194 | } 195 | 196 | $converter = $this->environment->getConverterByTag($tag); 197 | 198 | return $converter->convert($element); 199 | } 200 | 201 | /** 202 | * @param string $markdown 203 | * 204 | * @return string 205 | */ 206 | protected function sanitize($markdown) 207 | { 208 | $markdown = html_entity_decode($markdown, ENT_QUOTES, 'UTF-8'); 209 | $markdown = preg_replace('/<!DOCTYPE [^>]+>/', '', $markdown); // Strip doctype declaration 210 | $markdown = trim($markdown); // Remove blank spaces at the beggining of the html 211 | 212 | /* 213 | * Removing unwanted tags. Tags should be added to the array in the order they are expected. 214 | * XML, html and body opening tags should be in that order. Same case with closing tags 215 | */ 216 | $unwanted = array('<?xml encoding="UTF-8">', '<html>', '</html>', '<body>', '</body>', '<head>', '</head>', ' '); 217 | 218 | foreach ($unwanted as $tag) { 219 | if (strpos($tag, '/') === false) { 220 | // Opening tags 221 | if (strpos($markdown, $tag) === 0) { 222 | $markdown = substr($markdown, strlen($tag)); 223 | } 224 | } else { 225 | // Closing tags 226 | if (strpos($markdown, $tag) === strlen($markdown) - strlen($tag)) { 227 | $markdown = substr($markdown, 0, -strlen($tag)); 228 | } 229 | } 230 | } 231 | 232 | return trim($markdown, "\n\r\0\x0B"); 233 | } 234 | 235 | /** 236 | * Pass a series of key-value pairs in an array; these will be passed 237 | * through the config and set. 238 | * The advantage of this is that it can allow for static use (IE in Laravel). 239 | * An example being: 240 | * 241 | * HtmlConverter::setOptions(['strip_tags' => true])->convert('<h1>test</h1>'); 242 | */ 243 | public function setOptions(array $options) 244 | { 245 | $config = $this->getConfig(); 246 | 247 | foreach ($options as $key => $option) { 248 | $config->setOption($key, $option); 249 | } 250 | 251 | return $this; 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /vendor/league/html-to-markdown/src/HtmlConverterInterface.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | namespace League\HTMLToMarkdown; 4 | 5 | /** 6 | * Interface for an HTML-to-Markdown converter. 7 | * 8 | * @author Colin O'Dell <colinodell@gmail.com> 9 | * 10 | * @link https://github.com/thephpleague/html-to-markdown/ Latest version on GitHub. 11 | * 12 | * @license http://www.opensource.org/licenses/mit-license.php MIT 13 | */ 14 | interface HtmlConverterInterface 15 | { 16 | /** 17 | * Convert the given $html to Markdown 18 | * 19 | * @param string $html 20 | * 21 | * @throws \InvalidArgumentException 22 | * 23 | * @return string The Markdown version of the html 24 | */ 25 | public function convert($html); 26 | } 27 | --------------------------------------------------------------------------------