Last active
August 22, 2017 20:02
-
-
Save scrubmx/f93eee9da29effe7d8f1f140183f207e to your computer and use it in GitHub Desktop.
Convert html string to markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class MarkdownConverter | |
| { | |
| protected = $original; | |
| protected = $formatted; | |
| public function convert(string $html) | |
| { | |
| $this->original = $html; | |
| $this->convertParagraphs(); | |
| /* | |
| Asi quedaria al final: | |
| $this->convertParagraphs() | |
| ->convertImages() | |
| ->convertWhatever() | |
| */ | |
| return $this->formatted; | |
| } | |
| public function convertParagraphs() | |
| { | |
| $pattern = '/<p\s?.*?>(.*?)<\/p>/i'; | |
| $replacement = '<parrafo>${1}</parrafo>'; | |
| $this->formatted = preg_replace($pattern, $replacement, $this->original); | |
| return $this; | |
| } | |
| public function convertImages() | |
| { | |
| // TODO: implementar esta funcionalidad | |
| return $this; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment