diff --git a/admin/js/hyperdown.js b/admin/js/hyperdown.js
index 436fc4a9..0ab078aa 100644
--- a/admin/js/hyperdown.js
+++ b/admin/js/hyperdown.js
@@ -156,8 +156,11 @@
return html;
};
- Parser.prototype.parse = function(text) {
+ Parser.prototype.parse = function(text, inline) {
var block, blocks, end, extract, html, j, len, lines, method, result, start, type, value;
+ if (inline == null) {
+ inline = false;
+ }
lines = [];
blocks = this.parseBlock(text, lines);
html = '';
@@ -171,6 +174,9 @@
result = this.call('after' + ucfirst(method), result, value);
html += result;
}
+ if (inline && blocks.length === 1 && blocks[0][0] === 'normal') {
+ html = html.replace(/^\s*
(.*)<\/p>\s*$/m, '$1');
+ }
return html;
};
@@ -735,7 +741,7 @@
leftLines.push(line.replace(new RegExp("^\\s{" + secondMinSpace + "}"), ''));
} else {
if (leftLines.length > 0) {
- html += '
' + (this.parse(leftLines.join("\n"))) + '';
+ html += '' + (this.parse(leftLines.join("\n"), true)) + '';
}
if (lastType !== type) {
if (!!lastType) {
@@ -751,7 +757,7 @@
}
}
if (leftLines.length > 0) {
- html += '' + (this.parse(leftLines.join("\n"))) + ("" + lastType + ">");
+ html += '' + (this.parse(leftLines.join("\n"), true)) + ("" + lastType + ">");
}
return html;
};
diff --git a/var/HyperDown.php b/var/HyperDown.php
index a8c549cb..a3af0321 100644
--- a/var/HyperDown.php
+++ b/var/HyperDown.php
@@ -179,9 +179,10 @@ class HyperDown
* parse
*
* @param string $text
+ * @param bool $inline
* @return string
*/
- private function parse($text)
+ private function parse($text, $inline = false)
{
$blocks = $this->parseBlock($text, $lines);
$html = '';
@@ -198,6 +199,12 @@ class HyperDown
$html .= $result;
}
+ // inline mode for single normal block
+ if ($inline && count($blocks) == 1 && $blocks[0][0] == 'normal') {
+ // remove p tag
+ $html = preg_replace("/^\s*(.*)<\/p>\s*$/", "\\1", $html);
+ }
+
return $html;
}
@@ -982,7 +989,7 @@ class HyperDown
$leftLines[] = preg_replace("/^\s{" . $secondMinSpace . "}/", '', $line);
} else {
if (!empty($leftLines)) {
- $html .= "
" . $this->parse(implode("\n", $leftLines)) . "";
+ $html .= "" . $this->parse(implode("\n", $leftLines), true) . "";
}
if ($lastType != $type) {
@@ -1002,7 +1009,7 @@ class HyperDown
}
if (!empty($leftLines)) {
- $html .= "" . $this->parse(implode("\n", $leftLines)) . "{$lastType}>";
+ $html .= "" . $this->parse(implode("\n", $leftLines), true) . "{$lastType}>";
}
return $html;