summaryrefslogtreecommitdiff
path: root/sandbox/py-rest-doc/sphinx/util.py
diff options
context:
space:
mode:
authorblackbird <blackbird@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-05-22 21:11:58 +0000
committerblackbird <blackbird@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-05-22 21:11:58 +0000
commit57b6a2e9aaf13a745407bcf77ec182ec16b58e20 (patch)
treecb7263f3015af199e5048513f99a843958ccaa4f /sandbox/py-rest-doc/sphinx/util.py
parent6c34caabbe1eb96f3ddcf6900d63526b639df924 (diff)
downloaddocutils-57b6a2e9aaf13a745407bcf77ec182ec16b58e20.tar.gz
implemented online search
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5094 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/py-rest-doc/sphinx/util.py')
-rw-r--r--sandbox/py-rest-doc/sphinx/util.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/sandbox/py-rest-doc/sphinx/util.py b/sandbox/py-rest-doc/sphinx/util.py
index 53fc6644c..65047fe3a 100644
--- a/sandbox/py-rest-doc/sphinx/util.py
+++ b/sandbox/py-rest-doc/sphinx/util.py
@@ -76,6 +76,35 @@ def get_category(filename):
return parts[0]
+def shorten_result(text='', keywords=[], maxlen=240, fuzz=60):
+ if not text:
+ text = ''
+ text_low = text.lower()
+ beg = -1
+ for k in keywords:
+ i = text_low.find(k.lower())
+ if (i > -1 and i < beg) or beg == -1:
+ beg = i
+ excerpt_beg = 0
+ if beg > fuzz:
+ for sep in ('.', ':', ';', '='):
+ eb = text.find(sep, beg - fuzz, beg - 1)
+ if eb > -1:
+ eb += 1
+ break
+ else:
+ eb = beg - fuzz
+ excerpt_beg = eb
+ if excerpt_beg < 0:
+ excerpt_beg = 0
+ msg = text[excerpt_beg:beg+maxlen]
+ if beg > fuzz:
+ msg = '... ' + msg
+ if beg < len(text)-maxlen:
+ msg = msg + ' ...'
+ return msg
+
+
class attrdict(dict):
def __getattr__(self, key):
return self[key]