Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2925439
D25299.1737616836.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
5 KB
Referenced Files
None
Subscribers
None
D25299.1737616836.diff
View Options
diff --git a/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php b/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
--- a/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
+++ b/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
@@ -44,11 +44,18 @@
}
public function markupText($text, $children) {
- if (preg_match('/^\s*```/', $text)) {
+ $header_line = null;
+ if (preg_match('/^\s*```(.*)/', $text, $matches)) {
// If this is a ```-style block, trim off the backticks and any leading
// blank line.
$text = preg_replace('/^\s*```(\s*\n)?/', '', $text);
$text = preg_replace('/```\s*$/', '', $text);
+
+ // Just after the opening backticks there can be something valuable.
+ // Note that the general options are not necessarily here.
+ if (isset($matches[1])) {
+ $header_line = $matches[1];
+ }
}
$lines = explode("\n", $text);
@@ -79,6 +86,21 @@
}
}
+ // Language expressed as Flavored Markdown
+ // If language was not specified using lang=something, we parse
+ // the thing after the first backticks.
+ // We skip one-line blocks, to do not eat potential one-line content.
+ // If found, we remove that line since it is not part of the content.
+ // In this early version we are somehow strict and we do not support
+ // c# or c++ or enttalk/2 etc - but you can 'csharp', 'cpp', etc.
+ // The goal is to avoid false positives taking away content.
+ if (empty($options['lang']) && $header_line && count($lines) > 1) {
+ if (preg_match('/^[a-z][a-z0-9\-]*$/', $header_line)) {
+ $options['lang'] = $header_line;
+ array_shift($lines);
+ }
+ }
+
// Normalize the text back to a 0-level indent.
$min_indent = 80;
foreach ($lines as $line) {
diff --git a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
--- a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
+++ b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
@@ -2,6 +2,8 @@
/**
* Test cases for @{class:PhutilRemarkupEngine}.
+ * @TODO: This unit is not always triggered when you need it.
+ * https://we.phorge.it/T15500
*/
final class PhutilRemarkupEngineTestCase extends PhutilTestCase {
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-flavored.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-flavored.txt
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-flavored.txt
@@ -0,0 +1,6 @@
+```cpp
+code```
+~~~~~~~~~~
+<div class="remarkup-code-block" data-code-lang="cpp" data-sigil="remarkup-code-block"><pre class="remarkup-code">code</pre></div>
+~~~~~~~~~~
+ code
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-comment.txt
copy from src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt
copy to src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-comment.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-comment.txt
@@ -1,18 +1,18 @@
-```code
-
-more code
+```#comment
+code
+#more comment
more code```
~~~~~~~~~~
-<div class="remarkup-code-block" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code">code
-
-more code
+<div class="remarkup-code-block" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code">#comment
+code
+#more comment
more code</pre></div>
~~~~~~~~~~
+ #comment
code
- more code
-
+ #more comment
more code
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-empty.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-empty.txt
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored-empty.txt
@@ -0,0 +1,9 @@
+```
+cpp
+second line```
+~~~~~~~~~~
+<div class="remarkup-code-block" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code">cpp
+second line</pre></div>
+~~~~~~~~~~
+ cpp
+ second line
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored.txt
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi-flavored.txt
@@ -0,0 +1,19 @@
+```cpp
+code
+
+more code
+
+more code```
+
+~~~~~~~~~~
+<div class="remarkup-code-block" data-code-lang="cpp" data-sigil="remarkup-code-block"><pre class="remarkup-code">code
+
+more code
+
+more code</pre></div>
+~~~~~~~~~~
+ code
+
+ more code
+
+ more code
diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt
--- a/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/tick-block-multi.txt
@@ -1,17 +1,17 @@
-```code
+```code code
more code
more code```
~~~~~~~~~~
-<div class="remarkup-code-block" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code">code
+<div class="remarkup-code-block" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code">code code
more code
more code</pre></div>
~~~~~~~~~~
- code
+ code code
more code
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 23, 07:20 (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1112724
Default Alt Text
D25299.1737616836.diff (5 KB)
Attached To
Mode
D25299: Remarkup Code-block: parse language specifier in markdown
Attached
Detach File
Event Timeline
Log In to Comment