コード例 #1
0
 /**
  * @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());
     }
 }
コード例 #2
0
 /**
  * @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());
 }
コード例 #3
0
 /**
  * @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());
 }
コード例 #4
0
 /**
  * @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;
 }
コード例 #5
0
 /**
  * @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;
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
ファイル: EmphasisConverter.php プロジェクト: rhymix/rhymix
 /**
  * @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;
 }
コード例 #8
0
ファイル: TextConverter.php プロジェクト: NanFeng009/kanboard
 /**
  * @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;
 }
コード例 #9
0
 /**
  * @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" : '';
 }
コード例 #10
0
 /**
  * @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;
 }
コード例 #11
0
 /**
  * @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;
 }
コード例 #12
0
ファイル: ListItemConverter.php プロジェクト: rhymix/rhymix
 /**
  * @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;
 }
コード例 #13
0
 /**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function convert(ElementInterface $element)
 {
     return $element->getValue() . "\n";
 }
コード例 #14
0
 /**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function convert(ElementInterface $element)
 {
     $value = $element->getValue();
     return trim($value) !== '' ? rtrim($value) . "\n\n" : '';
 }
コード例 #15
0
 /**
  * @param ElementInterface $element
  *
  * @return string
  */
 public function convert(ElementInterface $element)
 {
     $value = $element->getValue();
     return trim($value) ? rtrim($value) . PHP_EOL . PHP_EOL : '';
 }