mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7325 from xini/patch-3
use html5 mark tag to highlight search parameter
This commit is contained in:
commit
4c84f22b2e
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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 & HTML included',
|
||||
20,
|
||||
'html',
|
||||
'... text & <span class="highlight">HTML</span> inc...'
|
||||
'... text & <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')
|
||||
);
|
||||
|
||||
|
@ -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 & <span class="highlight">HTML</span> inc...'
|
||||
'... text & <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',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user