| @@ 9-50 (lines=42) @@ | ||
| 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 | return html_entity_decode($element->getChildrenAsString()); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @return string[] |
|
| 45 | */ |
|
| 46 | public function getSupportedTags() |
|
| 47 | { |
|
| 48 | return array(self::DEFAULT_CONVERTER); |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 9-45 (lines=37) @@ | ||
| 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 | ||