Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13996929
D8931.id21195.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
16 KB
Referenced Files
None
Subscribers
None
D8931.id21195.diff
View Options
diff --git a/src/markup/__tests__/PhutilMarkupTestCase.php b/src/markup/__tests__/PhutilMarkupTestCase.php
--- a/src/markup/__tests__/PhutilMarkupTestCase.php
+++ b/src/markup/__tests__/PhutilMarkupTestCase.php
@@ -119,7 +119,10 @@
$hrefs = array(
'javascript:alert(1)' => true,
'JAVASCRIPT:alert(2)' => true,
- ' javascript:alert(3)' => true,
+
+ // NOTE: When interpreted as a URI, this is dropped because of leading
+ // whitespace.
+ ' javascript:alert(3)' => array(true, false),
'/' => false,
'/path/to/stuff/' => false,
'' => false,
@@ -158,6 +161,10 @@
foreach (array(true, false) as $use_uri) {
foreach ($hrefs as $href => $expect) {
+ if (is_array($expect)) {
+ $expect = ($use_uri ? $expect[1] : $expect[0]);
+ }
+
if ($use_uri) {
$href = new PhutilURI($href);
}
diff --git a/src/markup/engine/__tests__/remarkup/link-alternate.txt b/src/markup/engine/__tests__/remarkup/link-alternate.txt
--- a/src/markup/engine/__tests__/remarkup/link-alternate.txt
+++ b/src/markup/engine/__tests__/remarkup/link-alternate.txt
@@ -3,7 +3,7 @@
x[0][1](**ptr);
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">Example</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">Example</a></p>
<p>x[0][1](**ptr);</p>
~~~~~~~~~~
diff --git a/src/markup/engine/__tests__/remarkup/link-brackets.txt b/src/markup/engine/__tests__/remarkup/link-brackets.txt
--- a/src/markup/engine/__tests__/remarkup/link-brackets.txt
+++ b/src/markup/engine/__tests__/remarkup/link-brackets.txt
@@ -1,5 +1,5 @@
<http://www.zany.com/omg/weird_url,,,>
~~~~~~~~~~
-<p><a href="http://www.zany.com/omg/weird_url,,," target="_blank">http://www.zany.com/omg/weird_url,,,</a></p>
+<p><a href="http://www.zany.com/omg/weird_url,,," target="_blank" rel="noreferrer">http://www.zany.com/omg/weird_url,,,</a></p>
~~~~~~~~~~
http://www.zany.com/omg/weird_url,,,
diff --git a/src/markup/engine/__tests__/remarkup/link-edge-cases.txt b/src/markup/engine/__tests__/remarkup/link-edge-cases.txt
--- a/src/markup/engine/__tests__/remarkup/link-edge-cases.txt
+++ b/src/markup/engine/__tests__/remarkup/link-edge-cases.txt
@@ -10,17 +10,17 @@
Quick! http://www.example.com/!
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p>(<a href="http://www.example.com/" target="_blank">http://www.example.com/</a>)</p>
+<p>(<a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
-<p><a href="http://www.example.com/" target="_blank">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p><a href="http://www.example.com/wiki/example_(disambiguation)" target="_blank">http://www.example.com/wiki/example_(disambiguation)</a></p>
+<p><a href="http://www.example.com/wiki/example_(disambiguation)" target="_blank" rel="noreferrer">http://www.example.com/wiki/example_(disambiguation)</a></p>
-<p>(example <a href="http://www.example.com/" target="_blank">http://www.example.com/</a>)</p>
+<p>(example <a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>)</p>
-<p>Quick! <a href="http://www.example.com/" target="_blank">http://www.example.com/</a>!</p>
+<p>Quick! <a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>!</p>
~~~~~~~~~~
http://www.example.com/
diff --git a/src/markup/engine/__tests__/remarkup/link-mixed.txt b/src/markup/engine/__tests__/remarkup/link-mixed.txt
--- a/src/markup/engine/__tests__/remarkup/link-mixed.txt
+++ b/src/markup/engine/__tests__/remarkup/link-mixed.txt
@@ -5,11 +5,11 @@
<http://www.example.com/ [[http://www.example.net/ | Example]]>
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">Example</a>(<a href="http://www.alternate.org/" target="_blank">http://www.alternate.org/</a>)</p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">Example</a>(<a href="http://www.alternate.org/" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)</p>
-<p>(<a href="http://www.alternate.org/" target="_blank">http://www.alternate.org/</a>)<a href="http://www.example.com/" target="_blank">Example</a></p>
+<p>(<a href="http://www.alternate.org/" target="_blank" rel="noreferrer">http://www.alternate.org/</a>)<a href="http://www.example.com/" target="_blank" rel="noreferrer">Example</a></p>
-<p><<a href="http://www.example.com/" target="_blank">http://www.example.com/</a> <a href="http://www.example.net/" target="_blank">Example</a>></p>
+<p><<a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a> <a href="http://www.example.net/" target="_blank" rel="noreferrer">Example</a>></p>
~~~~~~~~~~
Example <http://www.example.com/>(http://www.alternate.org/)
diff --git a/src/markup/engine/__tests__/remarkup/link-square.txt b/src/markup/engine/__tests__/remarkup/link-square.txt
--- a/src/markup/engine/__tests__/remarkup/link-square.txt
+++ b/src/markup/engine/__tests__/remarkup/link-square.txt
@@ -8,9 +8,9 @@
[[#anchor | Anchors ]]
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
-<p><a href="http://www.example.com/" target="_blank">example.com</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">example.com</a></p>
<p><a href="/" target="_blank">/</a></p>
diff --git a/src/markup/engine/__tests__/remarkup/link-with-punctuation.txt b/src/markup/engine/__tests__/remarkup/link-with-punctuation.txt
--- a/src/markup/engine/__tests__/remarkup/link-with-punctuation.txt
+++ b/src/markup/engine/__tests__/remarkup/link-with-punctuation.txt
@@ -2,8 +2,8 @@
http://www.example.com/..
http://www.example.com/!!!
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">http://www.example.com/</a>,
-<a href="http://www.example.com/" target="_blank">http://www.example.com/</a>..
-<a href="http://www.example.com/" target="_blank">http://www.example.com/</a>!!!</p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>,
+<a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>..
+<a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a>!!!</p>
~~~~~~~~~~
http://www.example.com/, http://www.example.com/.. http://www.example.com/!!!
diff --git a/src/markup/engine/__tests__/remarkup/link-with-tilde.txt b/src/markup/engine/__tests__/remarkup/link-with-tilde.txt
--- a/src/markup/engine/__tests__/remarkup/link-with-tilde.txt
+++ b/src/markup/engine/__tests__/remarkup/link-with-tilde.txt
@@ -1,5 +1,5 @@
http://www.example.com/~
~~~~~~~~~~
-<p><a href="http://www.example.com/~" target="_blank">http://www.example.com/~</a></p>
+<p><a href="http://www.example.com/~" target="_blank" rel="noreferrer">http://www.example.com/~</a></p>
~~~~~~~~~~
http://www.example.com/~
diff --git a/src/markup/engine/__tests__/remarkup/link.txt b/src/markup/engine/__tests__/remarkup/link.txt
--- a/src/markup/engine/__tests__/remarkup/link.txt
+++ b/src/markup/engine/__tests__/remarkup/link.txt
@@ -1,5 +1,5 @@
http://www.example.com/
~~~~~~~~~~
-<p><a href="http://www.example.com/" target="_blank">http://www.example.com/</a></p>
+<p><a href="http://www.example.com/" target="_blank" rel="noreferrer">http://www.example.com/</a></p>
~~~~~~~~~~
http://www.example.com/
diff --git a/src/markup/engine/__tests__/remarkup/list-checkboxes.txt b/src/markup/engine/__tests__/remarkup/list-checkboxes.txt
new file mode 100644
--- /dev/null
+++ b/src/markup/engine/__tests__/remarkup/list-checkboxes.txt
@@ -0,0 +1,35 @@
+- [] a
+- [ ] b
+- [X] c
+- d
+
+[ ] A
+[X] B
+ [ ] C
+ [ ] D
+
+~~~~~~~~~~
+<ul class="remarkup-list-with-checkmarks">
+<li class="remarkup-unchecked-item"><input type="checkbox" disabled="disabled" /> a</li>
+<li class="remarkup-unchecked-item"><input type="checkbox" disabled="disabled" /> b</li>
+<li class="remarkup-checked-item"><input type="checkbox" checked="checked" disabled="disabled" /> c</li>
+<li>d</li>
+</ul>
+
+<ul class="remarkup-list-with-checkmarks">
+<li class="remarkup-unchecked-item"><input type="checkbox" disabled="disabled" /> A</li>
+<li class="remarkup-checked-item"><input type="checkbox" checked="checked" disabled="disabled" /> B<ul class="remarkup-list-with-checkmarks">
+<li class="remarkup-unchecked-item"><input type="checkbox" disabled="disabled" /> C</li>
+<li class="remarkup-unchecked-item"><input type="checkbox" disabled="disabled" /> D</li>
+</ul></li>
+</ul>
+~~~~~~~~~~
+[ ] a
+[ ] b
+[X] c
+- d
+
+[ ] A
+[X] B
+ [ ] C
+ [ ] D
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
@@ -10,7 +10,7 @@
<br />- second
<br />- third
-<p><a href="http://hello" target="_blank">world</a></p>
+<p><a href="http://hello" target="_blank" rel="noreferrer">world</a></p>
~~~~~~~~~~
**foo**
diff --git a/src/markup/engine/__tests__/remarkup/simple-table-with-link.txt b/src/markup/engine/__tests__/remarkup/simple-table-with-link.txt
--- a/src/markup/engine/__tests__/remarkup/simple-table-with-link.txt
+++ b/src/markup/engine/__tests__/remarkup/simple-table-with-link.txt
@@ -1,7 +1,7 @@
| [[ http://example.com | name ]] | [x] |
~~~~~~~~~~
<table class="remarkup-table">
-<tr><td><a href="http://example.com" target="_blank">name</a></td><td>[x]</td></tr>
+<tr><td><a href="http://example.com" target="_blank" rel="noreferrer">name</a></td><td>[x]</td></tr>
</table>
~~~~~~~~~~
| name <http://example.com> | [x] |
diff --git a/src/markup/engine/__tests__/remarkup/toc.txt b/src/markup/engine/__tests__/remarkup/toc.txt
--- a/src/markup/engine/__tests__/remarkup/toc.txt
+++ b/src/markup/engine/__tests__/remarkup/toc.txt
@@ -13,11 +13,11 @@
<li><a href="#http-www-example-com">http://www.example.com</a></li>
</ul>
-<h2><a name="http-www-example-com-lin"></a><a href="http://www.example.com/" target="_blank">link_name</a></h2>
+<h2><a name="http-www-example-com-lin"></a><a href="http://www.example.com/" target="_blank" rel="noreferrer">link_name</a></h2>
<h3><a name="bold"></a><strong>bold</strong></h3>
-<h2><a name="http-www-example-com"></a><a href="http://www.example.com" target="_blank">http://www.example.com</a></h2>
+<h2><a name="http-www-example-com"></a><a href="http://www.example.com" target="_blank" rel="noreferrer">http://www.example.com</a></h2>
~~~~~~~~~~
[[ http://www.example.com/ | link_name ]]
=========================================
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupListBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupListBlockRule.php
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupListBlockRule.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupEngineRemarkupListBlockRule.php
@@ -54,8 +54,9 @@
* the stack.
*/
const MAXIMUM_LIST_NESTING_DEPTH = 12;
- const START_BLOCK_PATTERN = '@^\s*(?:[-*#]+|1[.)])\s+@';
- const CONT_BLOCK_PATTERN = '@^\s*(?:[-*#]+|[0-9]+[.)])\s+@';
+ const START_BLOCK_PATTERN = '@^\s*(?:[-*#]+|1[.)]|\[.?\])\s+@';
+ const CONT_BLOCK_PATTERN = '@^\s*(?:[-*#]+|[0-9]+[.)]|\[.?\])\s+@';
+ const STRIP_BLOCK_PATTERN = '@^\s*(?:[-*#]+|[0-9]+[.)])\s*@';
public function markupText($text) {
@@ -158,6 +159,7 @@
// ),
// );
+ $has_marks = false;
foreach ($items as $key => $item) {
$item = preg_replace('/\s*\n\s*/', ' ', implode("\n", $item));
$item = rtrim($item);
@@ -184,19 +186,28 @@
$style = '-';
}
- // If we don't match the block pattern (for example, because the user
- // has typed only " " or " -"), treat the line as containing no text.
- // This prevents newly added items from rendering with a bullet and
- // the text "-", e.g.
- $text = preg_replace(self::CONT_BLOCK_PATTERN, '', $item);
- if ($text == $item) {
- $text = '';
+ // Strip leading indicators off the item.
+ $text = preg_replace(self::STRIP_BLOCK_PATTERN, '', $item);
+
+ // Look for "[]", "[ ]", "[*]", "[x]", etc., which we render as a
+ // checkbox.
+ $mark = null;
+ $matches = null;
+ if (preg_match('/^\s*\[(.?)\]\s*/', $text, $matches)) {
+ if (strlen(trim($matches[1]))) {
+ $mark = true;
+ } else {
+ $mark = false;
+ }
+ $has_marks = true;
+ $text = substr($text, strlen($matches[0]));
}
$items[$key] = array(
'text' => $text,
'depth' => $depth,
'style' => $style,
+ 'mark' => $mark,
);
}
$items = array_values($items);
@@ -267,7 +278,7 @@
// Finally, we have enough information to render the tree.
- $out = $this->renderTree($tree);
+ $out = $this->renderTree($tree, 0, $has_marks);
if ($this->getEngine()->isTextMode()) {
$out = implode('', $out);
@@ -317,6 +328,7 @@
'text' => null,
'level' => $cur_level,
'style' => null,
+ 'mark' => null,
'items' => $this->buildTree($items, $l, $min, $cur_level + 1),
);
}
@@ -369,7 +381,7 @@
/**
* See additional notes in markupText().
*/
- private function renderTree(array $tree, $level = 0) {
+ private function renderTree(array $tree, $level, $has_marks) {
$style = idx(head($tree), 'style');
$out = array();
@@ -377,36 +389,70 @@
if (!$this->getEngine()->isTextMode()) {
switch ($style) {
case '#':
- $out[] = hsprintf("<ol>\n");
+ $tag = 'ol';
break;
case '-':
- $out[] = hsprintf("<ul>\n");
+ $tag = 'ul';
break;
}
+
+ if ($has_marks) {
+ $out[] = hsprintf('<%s class="remarkup-list-with-checkmarks">', $tag);
+ } else {
+ $out[] = hsprintf('<%s>', $tag);
+ }
+
+ $out[] = "\n";
}
$number = 1;
foreach ($tree as $item) {
if ($this->getEngine()->isTextMode()) {
$out[] = str_repeat(' ', 2 * $level);
- switch ($style) {
- case '#':
- $out[] = $number.'. ';
- $number++;
- break;
- case '-':
- $out[] = '- ';
- break;
+ if ($item['mark'] !== null) {
+ if ($item['mark']) {
+ $out[] = '[X] ';
+ } else {
+ $out[] = '[ ] ';
+ }
+ } else {
+ switch ($style) {
+ case '#':
+ $out[] = $number.'. ';
+ $number++;
+ break;
+ case '-':
+ $out[] = '- ';
+ break;
+ }
}
$out[] = $this->applyRules($item['text'])."\n";
} else if ($item['text'] === null) {
$out[] = hsprintf('<li class="phantom-item">');
} else {
- $out[] = hsprintf('<li>');
+ if ($item['mark'] !== null) {
+ if ($item['mark'] == true) {
+ $out[] = hsprintf('<li class="remarkup-checked-item">');
+ } else {
+ $out[] = hsprintf('<li class="remarkup-unchecked-item">');
+ }
+ $out[] = phutil_tag(
+ 'input',
+ array(
+ 'type' => 'checkbox',
+ 'checked' => ($item['mark'] ? 'checked' : null),
+ 'disabled' => 'disabled',
+ ));
+ $out[] = ' ';
+ } else {
+ $out[] = hsprintf('<li>');
+ }
+
$out[] = $this->applyRules($item['text']);
}
if ($item['items']) {
- foreach ($this->renderTree($item['items'], $level + 1) as $i) {
+ $subitems = $this->renderTree($item['items'], $level + 1, $has_marks);
+ foreach ($subitems as $i) {
$out[] = $i;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 25, 1:06 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6713760
Default Alt Text
D8931.id21195.diff (16 KB)
Attached To
Mode
D8931: Allow Remarkup lists to have checkboxes
Attached
Detach File
Event Timeline
Log In to Comment