@@ 7-28 (lines=22) @@ | ||
4 | ||
5 | use Sioen\SirTrevorBlock; |
|
6 | ||
7 | final class HeadingConverter implements Converter |
|
8 | { |
|
9 | use HtmlToMarkdown; |
|
10 | ||
11 | public function toJson(\DOMElement $node) |
|
12 | { |
|
13 | $html = $node->ownerDocument->saveXML($node); |
|
14 | ||
15 | // remove the h2 tags from the text. We just need the inner text. |
|
16 | $html = preg_replace('/<(\/|)h2>/i', '', $html); |
|
17 | ||
18 | return new SirTrevorBlock( |
|
19 | 'heading', |
|
20 | array('text' => ' ' . $this->htmlToMarkdown($html)) |
|
21 | ); |
|
22 | } |
|
23 | ||
24 | public function matches(\DomElement $node) |
|
25 | { |
|
26 | return $node->nodeName === 'h2'; |
|
27 | } |
|
28 | } |
|
29 |
@@ 7-28 (lines=22) @@ | ||
4 | ||
5 | use Sioen\SirTrevorBlock; |
|
6 | ||
7 | final class ListConverter implements Converter |
|
8 | { |
|
9 | use HtmlToMarkdown; |
|
10 | ||
11 | public function toJson(\DOMElement $node) |
|
12 | { |
|
13 | $markdown = $this->htmlToMarkdown($node->ownerDocument->saveXML($node)); |
|
14 | ||
15 | // we need a space in the beginning of each line |
|
16 | $markdown = ' ' . str_replace("\n", "\n ", $markdown); |
|
17 | ||
18 | return new SirTrevorBlock( |
|
19 | 'list', |
|
20 | array('text' => $markdown) |
|
21 | ); |
|
22 | } |
|
23 | ||
24 | public function matches(\DomElement $node) |
|
25 | { |
|
26 | return $node->nodeName === 'ul'; |
|
27 | } |
|
28 | } |
|
29 |