/** * Returns the field type html (parsed output) * * @param array $options Parsing options if any * * @return \Twig_Markup */ public function parse(array $options = array()) { if (!empty($options)) { $this->html = doxter()->parse($this->text, $options); } return $this->html; }
/** * @param mixed $value * * @return DoxterModel */ public function prepValue($value) { $model = DoxterModel::create(); if (!empty($value)) { $model->setAttribute('text', $value); $model->setAttribute('html', doxter()->parse($value)); } return $model; }
/** * Parses headers and adds anchors to them if necessary * * @param string $source HTML source to search for headers within * @param array $options Passed in parsing options * * @return string */ public function parse($source, array $options = array()) { $addHeaderAnchorsTo = array('h1', 'h2', 'h3'); $startingHeaderLevel = 1; extract($options); if (!is_array($addHeaderAnchorsTo)) { $addHeaderAnchorsTo = doxter()->getHeadersToParse($addHeaderAnchorsTo); } $this->startingHeaderLevel = $startingHeaderLevel; $headers = implode('|', array_map('trim', $addHeaderAnchorsTo)); $pattern = sprintf('/<(?<tag>%s)>(?<text>.*?)<\\/(%s)>/i', $headers, $headers); $source = preg_replace_callback($pattern, array($this, 'handleMatch'), $source); return $source; }
/** * @param array $settings * * @return array */ public function prepSettings($settings = array()) { $settings['addHeaderAnchorsTo'] = doxter()->getHeadersToParse($settings['addHeaderAnchorsTo']); return $settings; }
/** * @param DoxterShortcodeModel $code * * @return string */ public function updates(DoxterShortcodeModel $code) { $lines = array_filter(array_map('trim', explode(PHP_EOL, $code->content))); $notes = array(); if (count($lines)) { foreach ($lines as $index => $line) { $line = doxter()->parseMarkdownInline(preg_replace('/^([ \\-\\+\\*\\=]+)?/', '', $line)); $type = $this->getUpdateTypeFromLine($line); $notes[] = array('text' => $line, 'type' => $type); } } if (craft()->templates->doesTemplateExist('_doxter/shortcodes/updates')) { return craft()->templates->render('_doxter/shortcodes/updates', compact('notes')); } return doxter()->renderPluginTemplate('shortcodes/_updates', compact('notes')); }