diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 88303bd1..b0542552 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,153 +1,155 @@ array( 'CommandException' => 'future/exec', 'ConduitClient' => 'conduit/client', 'ConduitClientException' => 'conduit/client', 'ConduitFuture' => 'conduit/client', 'ExecFuture' => 'future/exec', 'FileFinder' => 'filesystem/filefinder', 'FileList' => 'filesystem/filelist', 'Filesystem' => 'filesystem', 'FilesystemException' => 'filesystem', 'Future' => 'future', 'FutureIterator' => 'future', 'FutureProxy' => 'future/proxy', 'HTTPFuture' => 'future/http', 'HTTPSFuture' => 'future/https', 'LinesOfALargeFile' => 'filesystem/linesofalargefile', 'MFilterTestHelper' => 'utils/__tests__', 'PhutilConsoleFormatter' => 'console', 'PhutilDaemon' => 'daemon/base', 'PhutilDaemonOverseer' => 'daemon/overseer', 'PhutilDefaultSyntaxHighlighterEngine' => 'markup/syntax/engine/default', 'PhutilDocblockParser' => 'parser/docblock', 'PhutilDocblockParserTestCase' => 'parser/docblock/__tests__', 'PhutilFatalDaemon' => 'daemon/torture/fatal', 'PhutilHangForeverDaemon' => 'daemon/torture/hangforever', 'PhutilInteractiveEditor' => 'console/editor', 'PhutilMarkupEngine' => 'markup/engine', 'PhutilMissingSymbolException' => 'symbols/exception/missing', 'PhutilNiceDaemon' => 'daemon/torture/nice', 'PhutilProcessGroupDaemon' => 'daemon/torture/processgroup', 'PhutilRemarkupBlockStorage' => 'markup/engine/remarkup/blockstorage', 'PhutilRemarkupEngine' => 'markup/engine/remarkup', 'PhutilRemarkupEngineBlockRule' => 'markup/engine/remarkup/blockrule/base', 'PhutilRemarkupEngineRemarkupCodeBlockRule' => 'markup/engine/remarkup/blockrule/remarkupcode', 'PhutilRemarkupEngineRemarkupDefaultBlockRule' => 'markup/engine/remarkup/blockrule/remarkupdefault', 'PhutilRemarkupEngineRemarkupHeaderBlockRule' => 'markup/engine/remarkup/blockrule/remarkupheader', 'PhutilRemarkupEngineRemarkupInlineBlockRule' => 'markup/engine/remarkup/blockrule/remarkupinline', 'PhutilRemarkupEngineRemarkupListBlockRule' => 'markup/engine/remarkup/blockrule/remarkuplist', + 'PhutilRemarkupEngineTestCase' => 'markup/engine/remarkup/__tests__', 'PhutilRemarkupRule' => 'markup/engine/remarkup/markuprule/base', 'PhutilRemarkupRuleBold' => 'markup/engine/remarkup/markuprule/bold', 'PhutilRemarkupRuleEscapeHTML' => 'markup/engine/remarkup/markuprule/escapehtml', 'PhutilRemarkupRuleEscapeRemarkup' => 'markup/engine/remarkup/markuprule/escaperemarkup', 'PhutilRemarkupRuleHyperlink' => 'markup/engine/remarkup/markuprule/hyperlink', 'PhutilRemarkupRuleItalic' => 'markup/engine/remarkup/markuprule/italics', 'PhutilRemarkupRuleLinebreaks' => 'markup/engine/remarkup/markuprule/linebreaks', 'PhutilRemarkupRuleMonospace' => 'markup/engine/remarkup/markuprule/monospace', 'PhutilSaturateStdoutDaemon' => 'daemon/torture/saturatestdout', 'PhutilSymbolLoader' => 'symbols', 'PhutilSyntaxHighlighter' => 'markup/syntax/highlighter/base', 'PhutilSyntaxHighlighterEngine' => 'markup/syntax/engine/base', 'PhutilTortureTestDaemon' => 'daemon/torture/base', 'PhutilURI' => 'parser/uri', 'PhutilUtilsTestCase' => 'utils/__tests__', 'PhutilXHPASTSyntaxHighlighter' => 'markup/syntax/highlighter/xhpast', 'TempFile' => 'filesystem/tempfile', 'XHPASTNode' => 'parser/xhpast/api/node', 'XHPASTNodeList' => 'parser/xhpast/api/list', 'XHPASTSyntaxErrorException' => 'parser/xhpast/api/exception', 'XHPASTToken' => 'parser/xhpast/api/token', 'XHPASTTree' => 'parser/xhpast/api/tree', 'XHPASTTreeTestCase' => 'parser/xhpast/api/tree/__tests__', ), 'function' => array( 'Futures' => 'future', 'array_select_keys' => 'utils', 'coalesce' => 'utils', 'csprintf' => 'xsprintf/csprintf', 'exec_manual' => 'future/exec', 'execx' => 'future/exec', 'id' => 'utils', 'idx' => 'utils', 'ifilter' => 'utils', 'igroup' => 'utils', 'ipull' => 'utils', 'isort' => 'utils', 'jsprintf' => 'xsprintf/jsprintf', 'mfilter' => 'utils', 'mgroup' => 'utils', 'mpull' => 'utils', 'msort' => 'utils', 'newv' => 'utils', 'nonempty' => 'utils', 'phutil_autoload_class' => 'autoload', 'phutil_console_confirm' => 'console', 'phutil_console_format' => 'console', 'phutil_console_prompt' => 'console', 'phutil_console_wrap' => 'console', 'phutil_escape_html' => 'markup', 'phutil_escape_uri' => 'markup', 'phutil_get_library_name_for_root' => 'moduleutils', 'phutil_get_library_root' => 'moduleutils', 'phutil_get_library_root_for_path' => 'moduleutils', 'phutil_is_utf8' => 'utils', 'phutil_render_tag' => 'markup', 'phutil_utf8ize' => 'utils', 'vcsprintf' => 'xsprintf/csprintf', 'vjsprintf' => 'xsprintf/jsprintf', 'xhp_parser_node_constants' => 'parser/xhpast/constants', 'xhpast_get_binary_path' => 'parser/xhpast/bin', 'xhpast_get_build_instructions' => 'parser/xhpast/bin', 'xhpast_get_parser_future' => 'parser/xhpast/bin', 'xhpast_is_available' => 'parser/xhpast/bin', 'xhpast_parser_token_constants' => 'parser/xhpast/constants', 'xsprintf' => 'xsprintf', 'xsprintf_callback_example' => 'xsprintf', 'xsprintf_command' => 'xsprintf/csprintf', 'xsprintf_javascript' => 'xsprintf/jsprintf', ), 'requires_class' => array( 'ConduitFuture' => 'FutureProxy', 'ExecFuture' => 'Future', 'FutureProxy' => 'Future', 'HTTPFuture' => 'Future', 'HTTPSFuture' => 'Future', 'PhutilDefaultSyntaxHighlighterEngine' => 'PhutilSyntaxHighlighterEngine', 'PhutilDocblockParserTestCase' => 'ArcanistPhutilTestCase', 'PhutilFatalDaemon' => 'PhutilTortureTestDaemon', 'PhutilHangForeverDaemon' => 'PhutilTortureTestDaemon', 'PhutilNiceDaemon' => 'PhutilTortureTestDaemon', 'PhutilProcessGroupDaemon' => 'PhutilTortureTestDaemon', 'PhutilRemarkupEngine' => 'PhutilMarkupEngine', 'PhutilRemarkupEngineRemarkupCodeBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupDefaultBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupHeaderBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupInlineBlockRule' => 'PhutilRemarkupEngineBlockRule', 'PhutilRemarkupEngineRemarkupListBlockRule' => 'PhutilRemarkupEngineBlockRule', + 'PhutilRemarkupEngineTestCase' => 'ArcanistPhutilTestCase', 'PhutilRemarkupRuleBold' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleEscapeHTML' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleEscapeRemarkup' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleHyperlink' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleItalic' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleLinebreaks' => 'PhutilRemarkupRule', 'PhutilRemarkupRuleMonospace' => 'PhutilRemarkupRule', 'PhutilSaturateStdoutDaemon' => 'PhutilTortureTestDaemon', 'PhutilTortureTestDaemon' => 'PhutilDaemon', 'PhutilUtilsTestCase' => 'ArcanistPhutilTestCase', 'XHPASTTreeTestCase' => 'ArcanistPhutilTestCase', ), 'requires_interface' => array( ), )); diff --git a/src/markup/engine/remarkup/__tests__/PhutilRemarkupEngineTestCase.php b/src/markup/engine/remarkup/__tests__/PhutilRemarkupEngineTestCase.php new file mode 100644 index 00000000..a039da78 --- /dev/null +++ b/src/markup/engine/remarkup/__tests__/PhutilRemarkupEngineTestCase.php @@ -0,0 +1,80 @@ +markupText($root.$file); + } + } + + private function markupText($markup_file) { + $contents = Filesystem::readFile($markup_file); + $file = basename($markup_file); + + $parts = explode("\n~~~~~~~~~~\n", $contents); + $this->assertEqual(2, count($parts)); + + list($input_remarkup, $expected_output) = $parts; + + $engine = $this->buildNewTestEngine(); + + $actual_output = $engine->markupText($input_remarkup); + + $this->assertEqual( + $expected_output, + $actual_output, + "Failed to markup file '{$file}'."); + } + + private function buildNewTestEngine() { + $engine = new PhutilRemarkupEngine(); + + $rules = array(); + $rules[] = new PhutilRemarkupRuleEscapeRemarkup(); + $rules[] = new PhutilRemarkupRuleHyperlink(); + $rules[] = new PhutilRemarkupRuleEscapeHTML(); + $rules[] = new PhutilRemarkupRuleMonospace(); + $rules[] = new PhutilRemarkupRuleBold(); + $rules[] = new PhutilRemarkupRuleItalic(); + + $blocks = array(); + $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule(); + $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule(); + $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule(); + $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule(); + + foreach ($blocks as $block) { + if (!($block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule)) { + $block->setMarkupRules($rules); + } + } + + $engine->setBlockRules($blocks); + + return $engine; + } + +} diff --git a/src/markup/engine/remarkup/__tests__/__init__.php b/src/markup/engine/remarkup/__tests__/__init__.php new file mode 100644 index 00000000..89b05a5b --- /dev/null +++ b/src/markup/engine/remarkup/__tests__/__init__.php @@ -0,0 +1,25 @@ +a + +

blah blah blah

+ +

b

\ No newline at end of file diff --git a/src/markup/engine/remarkup/__tests__/data/link-with-punctuation.txt b/src/markup/engine/remarkup/__tests__/data/link-with-punctuation.txt index 6d6f612b..4f643d58 100644 --- a/src/markup/engine/remarkup/__tests__/data/link-with-punctuation.txt +++ b/src/markup/engine/remarkup/__tests__/data/link-with-punctuation.txt @@ -1,5 +1,7 @@ http://www.example.com/, http://www.example.com/.. http://www.example.com/!!! ~~~~~~~~~~ -

http://www.example.com/,
http://www.example.com/..
http://www.example.com/!!!

\ No newline at end of file +

http://www.example.com/, +
http://www.example.com/.. +
http://www.example.com/!!!

\ No newline at end of file diff --git a/src/markup/engine/remarkup/__tests__/data/list.txt b/src/markup/engine/remarkup/__tests__/data/list.txt index c1c2ff74..5df22a30 100755 --- a/src/markup/engine/remarkup/__tests__/data/list.txt +++ b/src/markup/engine/remarkup/__tests__/data/list.txt @@ -1,8 +1,9 @@ - < > & " text block ~~~~~~~~~~ +

text block

\ No newline at end of file diff --git a/src/markup/engine/remarkup/blockrule/remarkupdefault/PhutilRemarkupEngineRemarkupDefaultBlockRule.php b/src/markup/engine/remarkup/blockrule/remarkupdefault/PhutilRemarkupEngineRemarkupDefaultBlockRule.php index 95ac7d13..fa054e62 100644 --- a/src/markup/engine/remarkup/blockrule/remarkupdefault/PhutilRemarkupEngineRemarkupDefaultBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/remarkupdefault/PhutilRemarkupEngineRemarkupDefaultBlockRule.php @@ -1,41 +1,41 @@ $line) { $lines[$key] = $this->applyRules($line."\n"); } - return '

'.implode('', $lines).'

'; + return '

'.trim(implode('
', $lines)).'

'; } } diff --git a/src/markup/engine/remarkup/blockrule/remarkupheader/PhutilRemarkupEngineRemarkupHeaderBlockRule.php b/src/markup/engine/remarkup/blockrule/remarkupheader/PhutilRemarkupEngineRemarkupHeaderBlockRule.php index b88ea240..cbad44d1 100644 --- a/src/markup/engine/remarkup/blockrule/remarkupheader/PhutilRemarkupEngineRemarkupHeaderBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/remarkupheader/PhutilRemarkupEngineRemarkupHeaderBlockRule.php @@ -1,45 +1,49 @@ '.$this->applyRules($text).''; } } diff --git a/src/markup/engine/remarkup/blockrule/remarkuplist/PhutilRemarkupEngineRemarkupListBlockRule.php b/src/markup/engine/remarkup/blockrule/remarkuplist/PhutilRemarkupEngineRemarkupListBlockRule.php index 3a19c9cf..c67f52be 100644 --- a/src/markup/engine/remarkup/blockrule/remarkuplist/PhutilRemarkupEngineRemarkupListBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/remarkuplist/PhutilRemarkupEngineRemarkupListBlockRule.php @@ -1,44 +1,44 @@ $item) { if (!strlen($item)) { unset($items[$key]); } else { $items[$key] = '
  • '.$this->applyRules($item).'
  • '; } } - return ''; + return ""; } }