Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15415585
D10984.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D10984.diff
View Options
diff --git a/src/markup/engine/__tests__/remarkup/percent-block-adjacent.txt b/src/markup/engine/__tests__/remarkup/percent-block-adjacent.txt
new file mode 100644
--- /dev/null
+++ b/src/markup/engine/__tests__/remarkup/percent-block-adjacent.txt
@@ -0,0 +1,29 @@
+%%%a%%%
+%%%b%%%
+
+%%%a
+b%%%
+
+%%%a%%%
+
+%%%b%%%
+~~~~~~~~~~
+<p class="remarkup-literal">a
+<br />b</p>
+
+<p class="remarkup-literal">a
+<br />b</p>
+
+<p class="remarkup-literal">a</p>
+
+<p class="remarkup-literal">b</p>
+~~~~~~~~~~
+a
+b
+
+a
+b
+
+a
+
+b
diff --git a/src/markup/engine/__tests__/remarkup/percent-block-multiline.txt b/src/markup/engine/__tests__/remarkup/percent-block-multiline.txt
--- a/src/markup/engine/__tests__/remarkup/percent-block-multiline.txt
+++ b/src/markup/engine/__tests__/remarkup/percent-block-multiline.txt
@@ -6,9 +6,9 @@
~~~~~~~~~~
<p><strong>foo</strong></p>
-- first
+<p class="remarkup-literal">- first
<br />- second
-<br />- third
+<br />- third</p>
<p><a href="http://hello" class="remarkup-link" target="_blank" rel="noreferrer">world</a></p>
~~~~~~~~~~
diff --git a/src/markup/engine/__tests__/remarkup/percent-block-oneline.txt b/src/markup/engine/__tests__/remarkup/percent-block-oneline.txt
--- a/src/markup/engine/__tests__/remarkup/percent-block-oneline.txt
+++ b/src/markup/engine/__tests__/remarkup/percent-block-oneline.txt
@@ -2,9 +2,9 @@
%%%[[http://hello | world]] **bold**%%%
~~~~~~~~~~
-[[http://hello | world]] **bold**
+<p class="remarkup-literal">[[http://hello | world]] **bold**</p>
-[[http://hello | world]] **bold**
+<p class="remarkup-literal">[[http://hello | world]] **bold**</p>
~~~~~~~~~~
[[http://hello | world]] **bold**
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupLiteralBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupLiteralBlockRule.php
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupLiteralBlockRule.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupLiteralBlockRule.php
@@ -3,8 +3,23 @@
final class PhutilRemarkupLiteralBlockRule extends PhutilRemarkupBlockRule {
public function getMatchingLineCount(array $lines, $cursor) {
+ // NOTE: We're consuming all continguous blocks of %%% literals, so this:
+ //
+ // %%%a%%%
+ // %%%b%%%
+ //
+ // ...is equivalent to:
+ //
+ // %%%a
+ // b%%%
+ //
+ // If they are separated by a blank newline, they are parsed as two
+ // different blocks. This more clearly represents the original text in the
+ // output text and assists automated escaping of blocks coming into the
+ // system.
+
$num_lines = 0;
- if (preg_match('/^\s*%%%/', $lines[$cursor])) {
+ while (preg_match('/^\s*%%%/', $lines[$cursor])) {
$num_lines++;
while (isset($lines[$cursor])) {
@@ -18,28 +33,50 @@
$cursor++;
+ $found_empty = false;
while (isset($lines[$cursor])) {
if (!strlen(trim($lines[$cursor]))) {
$num_lines++;
$cursor++;
+ $found_empty = true;
continue;
}
break;
}
+ if ($found_empty) {
+ // If there's an empty line after the block, stop merging blocks.
+ break;
+ }
+
+ if (!isset($lines[$cursor])) {
+ // If we're at the end of the input, stop looking for more lines.
+ break;
+ }
}
return $num_lines;
}
public function markupText($text, $children) {
- $text = preg_replace('/^\s*%%%(.*)%%%\s*\z/s', '\1', $text);
+ $text = rtrim($text);
+ $text = phutil_split_lines($text, $retain_endings = true);
+ foreach ($text as $key => $line) {
+ $line = preg_replace('/^\s*%%%/', '', $line);
+ $line = preg_replace('/%%%(\s*)\z/', '\1', $line);
+ $text[$key] = $line;
+ }
+
if ($this->getEngine()->isTextMode()) {
- return $text;
+ return implode('', $text);
}
- $text = phutil_split_lines($text, $retain_endings = true);
- return phutil_implode_html(phutil_tag('br', array()), $text);
+ return phutil_tag(
+ 'p',
+ array(
+ 'class' => 'remarkup-literal',
+ ),
+ phutil_implode_html(phutil_tag('br', array()), $text));
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 21, 6:46 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7599445
Default Alt Text
D10984.diff (4 KB)
Attached To
Mode
D10984: Preserve whitespace more faithfully when processing %%% remarkup blocks
Attached
Detach File
Event Timeline
Log In to Comment