Ref T5560, Adds a basic highlight rule.
Details
- Reviewers
epriestley - Maniphest Tasks
- T5560: Add some sort of highlighting syntax to Remarkup
- Commits
- rPHUceca9d1122ea: Add Highlight Remarkup Rule
Edit a Document and add a highlighted word.
Diff Detail
- Repository
- rPHU libphutil
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Something is wrong with the unit test, but I can't figure out what. Here's the failure:
Assertion failed, expected values to be equal (at PhutilRemarkupEngineTestCase.php:56): Failed to markup HTML in file 'highlight.txt'. Expected vs Actual Output Diff --- Old Value +++ New Value @@ -1,4 +1 @@ -'<p>how about we -<span class="remarkup-highlight">highlight</span> -some -<span class="remarkup-highlight">text</span>!</p>' +'<p>how about we !!highlight!! some !!text!!!</p>'
Oh, I think you need to add the rule to PhutilRemarkupEngineTestCase.
For this input:
!!xxx!!!
...it seems like the "!" at the end should be highlighted? I think you could do that with a regular expression like this:
'@!!(.+?)(!{2,})@'
...which says "match two or more exclamation points at the end".
Then, in applyCallback(), you'll get $matches[2] with all the exclamation points at the end. Then do:
// Remove the two exclamation points that represent syntax. $excitement = substr($matches[2], 2); // $excitement now has two fewer !'s than we started with. return hsprintf('<blah ...>%s%s<... blah>', $matches[1], $excitement);
src/markup/engine/remarkup/markuprule/PhutilRemarkupHighlightRule.php | ||
---|---|---|
16 | You should be able to get away without escaping the ! characters, since they don't have special meanings in regular expressions. I think this slightly simpler thing will work: '@!!(.+?)!!@s' |
oh, I presumed it should not highlight the ! in the second example. Maybe we should use \\this to highlight\\ instead?
My thinking is that if I type this:
IF YOU DO THIS, IT WILL DESTROY ALL YOUR DATA!
...I probably mean the extra "!" as punctuation for the highlighted part. Are you imagining a different sort of use case?
I think we currently could use \\ but I'm hesitant to use it for things that aren't related to escaping because it's so consistently an escaping character across many programming languages. For example, there's no way to write two bold asterisks right now. Possibly this sequence should eventually produce that:
**\*\***
That is: begin bold text, two literal escaped asterisks, end bold text.
We should also maybe use a regex like this:
'@!!(?!\s)...
That is, "two exclamation points, not followed by a whitespace character". Then this wouldn't highlight:
No Do not do this It is bad!!
...because all of the "!!" are followed by spaces (or no text, in the last case).
That lint stuff will clear itself up if we move the stuff to a __tests__/data/ directory, I just haven't gotten around to doing that.