Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Last active August 22, 2017 20:02
Show Gist options
  • Select an option

  • Save scrubmx/f93eee9da29effe7d8f1f140183f207e to your computer and use it in GitHub Desktop.

Select an option

Save scrubmx/f93eee9da29effe7d8f1f140183f207e to your computer and use it in GitHub Desktop.
Convert html string to markdown
<?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