Merge pull request #7325 from xini/patch-3

use html5 mark tag to highlight search parameter
This commit is contained in:
Damian Mooyman 2017-09-05 13:38:42 +12:00 committed by GitHub
commit 4c84f22b2e
3 changed files with 15 additions and 15 deletions

View File

@ -175,7 +175,7 @@ class DBText extends DBString
*
* @param int $characters Number of characters in the summary
* @param string $keywords Supplied string ("keywords"). Will fall back to 'Search' querystring arg.
* @param bool $highlight Add a highlight <span> element around search query?
* @param bool $highlight Add a highlight <mark> element around search query?
* @param string $prefix Prefix text
* @param string $suffix Suffix text
* @return string HTML string with context
@ -222,7 +222,7 @@ class DBText extends DBString
// Maintain case of original string
$summary = preg_replace(
'/' . preg_quote($stringPiece, '/') . '/i',
'<span class="highlight">$0</span>',
'<mark>$0</mark>',
$summary
);
}

View File

@ -295,21 +295,21 @@ class DBHTMLTextTest extends SapphireTest
'This is some text. It is a test',
20,
'test',
'... text. It is a <span class="highlight">test</span>'
'... text. It is a <mark>test</mark>'
],
[
// Retains case of original string
'This is some test text. Test test what if you have multiple keywords.',
50,
'some test',
'This is <span class="highlight">some</span> <span class="highlight">test</span> text.'
. ' <span class="highlight">Test</span> <span class="highlight">test</span> what if you have...'
'This is <mark>some</mark> <mark>test</mark> text.'
. ' <mark>Test</mark> <mark>test</mark> what if you have...'
],
[
'Here is some text &amp; HTML included',
20,
'html',
'... text &amp; <span class="highlight">HTML</span> inc...'
'... text &amp; <mark>HTML</mark> inc...'
],
[
'A dog ate a cat while looking at a Foobar',
@ -323,16 +323,16 @@ class DBHTMLTextTest extends SapphireTest
100,
'ate',
// it should highlight 3 letters or more.
'A dog <span class="highlight">ate</span> a cat while looking at a Foobar',
'A dog <mark>ate</mark> a cat while looking at a Foobar',
],
// HTML Content is plain-textified, and incorrect tags removed
[
'<p>A dog ate a cat while <span class="highlight">looking</span> at a Foobar</p>',
'<p>A dog ate a cat while <mark>looking</mark> at a Foobar</p>',
100,
'ate',
// it should highlight 3 letters or more.
'A dog <span class="highlight">ate</span> a cat while looking at a Foobar',
'A dog <mark>ate</mark> a cat while looking at a Foobar',
]
];
}
@ -586,7 +586,7 @@ class DBHTMLTextTest extends SapphireTest
$field->FirstParagraph()
);
$this->assertEquals(
'Replaced <span class="highlight">short</span> <span class="highlight">code</span> with this. home',
'Replaced <mark>short</mark> <mark>code</mark> with this. home',
$field->ContextSummary(500, 'short code')
);

View File

@ -214,21 +214,21 @@ class DBTextTest extends SapphireTest
'This is some text. It is a test',
20,
'test',
'... text. It is a <span class="highlight">test</span>'
'... text. It is a <mark>test</mark>'
],
[
// Retains case of original string
'This is some test text. Test test what if you have multiple keywords.',
50,
'some test',
'This is <span class="highlight">some</span> <span class="highlight">test</span> text.'
. ' <span class="highlight">Test</span> <span class="highlight">test</span> what if you have...'
'This is <mark>some</mark> <mark>test</mark> text.'
. ' <mark>Test</mark> <mark>test</mark> what if you have...'
],
[
'Here is some text & HTML included',
20,
'html',
'... text &amp; <span class="highlight">HTML</span> inc...'
'... text &amp; <mark>HTML</mark> inc...'
],
[
'A dog ate a cat while looking at a Foobar',
@ -242,7 +242,7 @@ class DBTextTest extends SapphireTest
100,
'ate',
// it should highlight 3 letters or more.
'A dog <span class="highlight">ate</span> a cat while looking at a Foobar',
'A dog <mark>ate</mark> a cat while looking at a Foobar',
]
];
}