parsedown\Parsedown::parse PHP Method

parse() public method

#
public parse ( $text )
    function parse($text)
    {
        # standardize line breaks
        $text = str_replace("\r\n", "\n", $text);
        $text = str_replace("\r", "\n", $text);
        # replace tabs with spaces
        $text = str_replace("\t", '    ', $text);
        # remove surrounding line breaks
        $text = trim($text, "\n");
        # split text into lines
        $lines = explode("\n", $text);
        # iterate through lines to identify blocks
        $blocks = $this->findBlocks($lines);
        # iterate through blocks to build markup
        $markup = $this->compile($blocks);
        # trim line breaks
        $markup = trim($markup, "\n");
        return $markup;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Save upload editor
  *
  * @return void
  */
 public function save()
 {
     $value = $this->getRequest()->getPost()->get($this->getName());
     $data = array();
     if (!empty($value)) {
         $parsedown = new Parsedown();
         $data['markdown'] = $parsedown->parse($value);
         $data['source'] = $value;
     }
     $this->setValue(serialize($data));
 }