diff options
author | zotlabs <mike@macgirvin.com> | 2017-05-23 16:14:41 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-05-23 16:14:41 -0700 |
commit | bf580fcc0651663031d74072ee17a8f6becb49fc (patch) | |
tree | aaf0ac6129053c728f29559381f521395494f0b8 /vendor/league/html-to-markdown/src/Environment.php | |
parent | 357e7af6adb303aa12f6506585e7d59a1250da99 (diff) | |
parent | 31d920817264552cece5a57c2390411af4d7a3a1 (diff) | |
download | volse-hubzilla-bf580fcc0651663031d74072ee17a8f6becb49fc.tar.gz volse-hubzilla-bf580fcc0651663031d74072ee17a8f6becb49fc.tar.bz2 volse-hubzilla-bf580fcc0651663031d74072ee17a8f6becb49fc.zip |
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into xdev_merge
Diffstat (limited to 'vendor/league/html-to-markdown/src/Environment.php')
-rw-r--r-- | vendor/league/html-to-markdown/src/Environment.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/vendor/league/html-to-markdown/src/Environment.php b/vendor/league/html-to-markdown/src/Environment.php new file mode 100644 index 000000000..560cfe613 --- /dev/null +++ b/vendor/league/html-to-markdown/src/Environment.php @@ -0,0 +1,104 @@ +<?php + +namespace League\HTMLToMarkdown; + +use League\HTMLToMarkdown\Converter\BlockquoteConverter; +use League\HTMLToMarkdown\Converter\CodeConverter; +use League\HTMLToMarkdown\Converter\CommentConverter; +use League\HTMLToMarkdown\Converter\ConverterInterface; +use League\HTMLToMarkdown\Converter\DefaultConverter; +use League\HTMLToMarkdown\Converter\DivConverter; +use League\HTMLToMarkdown\Converter\EmphasisConverter; +use League\HTMLToMarkdown\Converter\HardBreakConverter; +use League\HTMLToMarkdown\Converter\HeaderConverter; +use League\HTMLToMarkdown\Converter\HorizontalRuleConverter; +use League\HTMLToMarkdown\Converter\ImageConverter; +use League\HTMLToMarkdown\Converter\LinkConverter; +use League\HTMLToMarkdown\Converter\ListBlockConverter; +use League\HTMLToMarkdown\Converter\ListItemConverter; +use League\HTMLToMarkdown\Converter\ParagraphConverter; +use League\HTMLToMarkdown\Converter\PreformattedConverter; +use League\HTMLToMarkdown\Converter\TextConverter; + +final class Environment +{ + /** + * @var Configuration + */ + protected $config; + + /** + * @var ConverterInterface[] + */ + protected $converters = array(); + + public function __construct(array $config = array()) + { + $this->config = new Configuration($config); + $this->addConverter(new DefaultConverter()); + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * @param ConverterInterface $converter + */ + public function addConverter(ConverterInterface $converter) + { + if ($converter instanceof ConfigurationAwareInterface) { + $converter->setConfig($this->config); + } + + foreach ($converter->getSupportedTags() as $tag) { + $this->converters[$tag] = $converter; + } + } + + /** + * @param string $tag + * + * @return ConverterInterface + */ + public function getConverterByTag($tag) + { + if (isset($this->converters[$tag])) { + return $this->converters[$tag]; + } + + return $this->converters[DefaultConverter::DEFAULT_CONVERTER]; + } + + /** + * @param array $config + * + * @return Environment + */ + public static function createDefaultEnvironment(array $config = array()) + { + $environment = new static($config); + + $environment->addConverter(new BlockquoteConverter()); + $environment->addConverter(new CodeConverter()); + $environment->addConverter(new CommentConverter()); + $environment->addConverter(new DivConverter()); + $environment->addConverter(new EmphasisConverter()); + $environment->addConverter(new HardBreakConverter()); + $environment->addConverter(new HeaderConverter()); + $environment->addConverter(new HorizontalRuleConverter()); + $environment->addConverter(new ImageConverter()); + $environment->addConverter(new LinkConverter()); + $environment->addConverter(new ListBlockConverter()); + $environment->addConverter(new ListItemConverter()); + $environment->addConverter(new ParagraphConverter()); + $environment->addConverter(new PreformattedConverter()); + $environment->addConverter(new TextConverter()); + + return $environment; + } +} |