/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $level = (int) substr($element->getTagName(), 1, 1); $style = $this->config->getOption('header_style', self::STYLE_SETEXT); if (($level === 1 || $level === 2) && !$element->isDescendantOf('blockquote') && $style === self::STYLE_SETEXT) { return $this->createSetextHeader($level, $element->getValue()); } else { return $this->createAtxHeader($level, $element->getValue()); } }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { if ($this->config->getOption('strip_tags', false)) { return $element->getValue() . PHP_EOL . PHP_EOL; } return html_entity_decode($element->getChildrenAsString()); }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { // If strip_tags is false (the default), preserve tags that don't have Markdown equivalents, // such as <span> nodes on their own. C14N() canonicalizes the node to a string. // See: http://www.php.net/manual/en/domnode.c14n.php if ($this->config->getOption('strip_tags', false)) { return $element->getValue(); } return html_entity_decode($element->getChildrenAsString()); }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $tag = $element->getTagName(); $value = $element->getValue(); if ($tag === 'i' || $tag === 'em') { $style = $this->config->getOption('italic_style'); } else { $style = $this->config->getOption('bold_style'); } return $style . $value . $style; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { // If parent is an ol, use numbers, otherwise, use dashes $list_type = $element->getParent()->getTagName(); $value = $element->getValue(); if ($list_type === 'ul') { $markdown = '- ' . trim($value) . "\n"; } else { $number = $element->getSiblingPosition(); $markdown = $number . '. ' . trim($value) . "\n"; } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $value = $element->getValue(); $markdown = preg_replace('~\\s+~', ' ', $value); $markdown = preg_replace('~^#~', '\\\\#', $markdown); if ($markdown === ' ') { $next = $element->getNext(); if (!$next || $next->isBlock()) { $markdown = ''; } } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $tag = $element->getTagName(); $value = $element->getValue(); if ($tag === 'i' || $tag === 'em') { $style = $this->config->getOption('italic_style'); } else { $style = $this->config->getOption('bold_style'); } $prefix = ltrim($value) !== $value ? ' ' : ''; $suffix = rtrim($value) !== $value ? ' ' : ''; return $prefix . $style . trim($value) . $style . $suffix; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $value = $element->getValue(); $markdown = preg_replace('~\\s+~', ' ', $value); //escape the following characters: '*', '_' and '\' $markdown = preg_replace('~([*_\\\\])~', '\\\\$1', $markdown); $markdown = preg_replace('~^#~', '\\\\#', $markdown); if ($markdown === ' ') { $next = $element->getNext(); if (!$next || $next->isBlock()) { $markdown = ''; } } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $value = $element->getValue(); $markdown = ''; $lines = preg_split('/\\r\\n|\\r|\\n/', $value); foreach ($lines as $line) { /* * Some special characters need to be escaped based on the position that they appear * The following function will deal with those special cases. */ $markdown .= $this->escapeSpecialCharacters($line); $markdown .= "\n"; } return trim($markdown) !== '' ? rtrim($markdown) . "\n\n" : ''; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { // Contents should have already been converted to Markdown by this point, // so we just need to add '>' symbols to each line. $markdown = ''; $quote_content = trim($element->getValue()); $lines = preg_split('/\\r\\n|\\r|\\n/', $quote_content); $total_lines = count($lines); foreach ($lines as $i => $line) { $markdown .= '> ' . $line . "\n"; if ($i + 1 === $total_lines) { $markdown .= "\n"; } } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $href = $element->getAttribute('href'); $title = $element->getAttribute('title'); $text = $element->getValue(); if ($title != '') { $markdown = '[' . $text . '](' . $href . ' "' . $title . '")'; } elseif ($href === $text) { $markdown = '<' . $href . '>'; } else { $markdown = '[' . $text . '](' . $href . ')'; } if (!$href) { $markdown = html_entity_decode($element->getChildrenAsString()); } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { // If parent is an ol, use numbers, otherwise, use dashes $list_type = $element->getParent()->getTagName(); $value = $element->getValue(); // Add spaces to start for nested list items $level = $element->getListItemLevel($element); $prefix = str_repeat(' ', $level); // If list item is the first in a nested list, add a newline before it if ($level > 0 && $element->getSiblingPosition() === 1) { $prefix = "\n" . $prefix; } if ($list_type === 'ul') { $markdown = $prefix . '- ' . trim($value) . "\n"; } else { $number = $element->getSiblingPosition(); $markdown = $prefix . $number . '. ' . trim($value) . "\n"; } return $markdown; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { return $element->getValue() . "\n"; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $value = $element->getValue(); return trim($value) !== '' ? rtrim($value) . "\n\n" : ''; }
/** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { $value = $element->getValue(); return trim($value) ? rtrim($value) . PHP_EOL . PHP_EOL : ''; }