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