From 2355f5f1384ca0446b50be5260eb3188fef0c192 Mon Sep 17 00:00:00 2001 From: Nada Date: Mon, 3 Aug 2015 16:50:21 +0200 Subject: [PATCH] Ignoring titles and tags in the snippet option It better to have the preview of a page without the titles and tags such as , etc ... --- inc/pagequery.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inc/pagequery.php b/inc/pagequery.php index 8b25b55..741b7d1 100644 --- a/inc/pagequery.php +++ b/inc/pagequery.php @@ -377,8 +377,18 @@ private function _add_tooltip($link, $tooltip) { * @return string */ private function _shorten($text, $extent, $more = '... ') { + $match = array(); $elem = $extent[0]; $cnt = (int) substr($extent, 1); + $pattern = '/={2,}\n+((?!(={2,})).+)/'; + // first, we ignore the titles + if (!preg_match($pattern, rawWiki($id), $match)){ + $text = rawWiki($id); + } else { + $text = $match[1]; + } + // then we ignore all the tags such as + $text = preg_replace('/(<[^>]+>.*<\/[^>]+>)/', '', $text); switch ($elem) { case 'c': $result = substr($text, 0, $cnt);