Page MenuHomePhabricator

D16892.id40663.diff
No OneTemporary

D16892.id40663.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2896,6 +2896,7 @@
'PhabricatorManiphestTaskTestDataGenerator' => 'applications/maniphest/lipsum/PhabricatorManiphestTaskTestDataGenerator.php',
'PhabricatorMarkupCache' => 'applications/cache/storage/PhabricatorMarkupCache.php',
'PhabricatorMarkupEngine' => 'infrastructure/markup/PhabricatorMarkupEngine.php',
+ 'PhabricatorMarkupEngineTestCase' => 'infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php',
'PhabricatorMarkupInterface' => 'infrastructure/markup/PhabricatorMarkupInterface.php',
'PhabricatorMarkupOneOff' => 'infrastructure/markup/PhabricatorMarkupOneOff.php',
'PhabricatorMarkupPreviewController' => 'infrastructure/markup/PhabricatorMarkupPreviewController.php',
@@ -7871,6 +7872,7 @@
'PhabricatorManiphestTaskTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorMarkupCache' => 'PhabricatorCacheDAO',
'PhabricatorMarkupEngine' => 'Phobject',
+ 'PhabricatorMarkupEngineTestCase' => 'PhabricatorTestCase',
'PhabricatorMarkupOneOff' => array(
'Phobject',
'PhabricatorMarkupInterface',
diff --git a/src/applications/project/typeahead/PhabricatorProjectDatasource.php b/src/applications/project/typeahead/PhabricatorProjectDatasource.php
--- a/src/applications/project/typeahead/PhabricatorProjectDatasource.php
+++ b/src/applications/project/typeahead/PhabricatorProjectDatasource.php
@@ -130,7 +130,7 @@
$description = idx($descriptions, $phid);
if (strlen($description)) {
- $summary = PhabricatorMarkupEngine::summarize($description);
+ $summary = PhabricatorMarkupEngine::summarizeSentence($description);
$proj_result->addAttribute($summary);
}
}
diff --git a/src/infrastructure/markup/PhabricatorMarkupEngine.php b/src/infrastructure/markup/PhabricatorMarkupEngine.php
--- a/src/infrastructure/markup/PhabricatorMarkupEngine.php
+++ b/src/infrastructure/markup/PhabricatorMarkupEngine.php
@@ -607,6 +607,28 @@
return array_values($files);
}
+ public static function summarizeSentence($corpus) {
+ $corpus = trim($corpus);
+ $blocks = preg_split('/\n+/', $corpus, 2);
+ $block = head($blocks);
+
+ $sentences = preg_split(
+ '/\b([.?!]+)\B/u',
+ $block,
+ 2,
+ PREG_SPLIT_DELIM_CAPTURE);
+
+ if (count($sentences) > 1) {
+ $result = $sentences[0].$sentences[1];
+ } else {
+ $result = head($sentences);
+ }
+
+ return id(new PhutilUTF8StringTruncator())
+ ->setMaximumGlyphs(128)
+ ->truncateString($result);
+ }
+
/**
* Produce a corpus summary, in a way that shortens the underlying text
* without truncating it somewhere awkward.
diff --git a/src/infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php b/src/infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/markup/__tests__/PhabricatorMarkupEngineTestCase.php
@@ -0,0 +1,43 @@
+<?php
+
+final class PhabricatorMarkupEngineTestCase
+ extends PhabricatorTestCase {
+
+ public function testRemarkupSentenceSummmaries() {
+ $this->assertSentenceSummary(
+ 'The quick brown fox. Jumped over the lazy dog.',
+ 'The quick brown fox.');
+
+ $this->assertSentenceSummary(
+ 'Go to www.help.com for details. Good day.',
+ 'Go to www.help.com for details.');
+
+ $this->assertSentenceSummary(
+ 'Coxy lummox gives squid who asks for job pen.',
+ 'Coxy lummox gives squid who asks for job pen.');
+
+ $this->assertSentenceSummary(
+ 'DEPRECATED',
+ 'DEPRECATED');
+
+ $this->assertSentenceSummary(
+ 'Never use this! It is deadly poison.',
+ 'Never use this!');
+
+ $this->assertSentenceSummary(
+ "a short poem\nmeow meow meow\nmeow meow meow\n\n- cat",
+ 'a short poem');
+
+ $this->assertSentenceSummary(
+ 'WOW!! GREAT PROJECT!',
+ 'WOW!!');
+ }
+
+ private function assertSentenceSummary($corpus, $summary) {
+ $this->assertEqual(
+ $summary,
+ PhabricatorMarkupEngine::summarizeSentence($corpus),
+ pht('Summary of: %s', $corpus));
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 3:03 AM (18 h, 50 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6909309
Default Alt Text
D16892.id40663.diff (4 KB)

Event Timeline