Skip to content

Commit 1602b60

Browse files
authored
Merge pull request #23 from moefront/fix-markdown-convert
2 parents feb4dab + ef696e8 commit 1602b60

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

Action.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,21 @@ private function recursion($comments, $parents, $map)
927927
return $result;
928928
}
929929

930+
/**
931+
* Safely parse markdown into HTML
932+
* @param string|null $content
933+
* @return string
934+
*/
935+
private function safelyParseMarkdown($content) {
936+
if (is_null($content) || empty($content)) {
937+
return '';
938+
}
939+
$contentWidget = $this->widget('Widget_Abstract_Contents');
940+
return method_exists($contentWidget, 'markdown')
941+
? $contentWidget->markdown($content)
942+
: MarkdownExtraExtended::defaultTransform($content);
943+
}
944+
930945
/**
931946
* 过滤和补全文章数组
932947
*
@@ -941,22 +956,14 @@ private function filter($value)
941956

942957
$value['password'] = ''; // typecho:#94ddb69 compat
943958

944-
if (method_exists($contentWidget, 'markdown')) {
945-
$value = $contentWidget->filter($value);
946-
$value['text'] = $contentWidget->markdown($value['text']);
947-
$value['digest'] = $contentWidget->markdown($value['digest']);
948-
} else {
949-
// Typecho 0.9 compatibility
950-
$value['type'] = isset($value['type']) ? $value['type'] : null;
951-
$value = $contentWidget->filter($value);
952-
$value['text'] = MarkdownExtraExtended::defaultTransform($value['text']);
953-
$value['digest'] = MarkdownExtraExtended::defaultTransform($value['digest']);
954-
955-
if ($value['type'] === null) {
956-
unset($value['type']);
957-
}
958-
}
959+
$value['type'] = isset($value['type']) ? $value['type'] : null; // Typecho 0.9 compatibility
960+
$value = $contentWidget->filter($value);
961+
$value['text'] = $this->safelyParseMarkdown($value['text']);
962+
$value['digest'] = $this->safelyParseMarkdown($value['text']);
959963

964+
if ($value['type'] === null) {
965+
unset($value['type']);
966+
}
960967
if (empty(trim($value['text']))) {
961968
unset($value['text']);
962969
}

0 commit comments

Comments
 (0)