# HG changeset patch # User SvartalF # Date 1272465077 -32400 # Node ID d5c9ac8bfb1c30c9e40f896b6150111cb194129a # Parent ea28ed44af93abd67777ae326aa3c364bac69ac4 Тесты для подсветки URI и E-mail в классе HTML diff -r ea28ed44af93abd67777ae326aa3c364bac69ac4 -r d5c9ac8bfb1c30c9e40f896b6150111cb194129a pytyph/constants.py --- a/pytyph/constants.py Wed Apr 28 15:58:15 2010 +0900 +++ b/pytyph/constants.py Wed Apr 28 23:31:17 2010 +0900 @@ -9,6 +9,6 @@ ОГУП|АО|ТОО|МУЗМПТПНОО|ГУП|АНО|ОГУК|ОГУЗ|НУЗ|МУ|ФГП|ФГУЗ|НКОУ|ГОУ НПО|МДОУ| НДОУ|ГДОУ|ГК|НИИ'''.replace('\n', '') -url = ur'https?://(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::\d+)?(?:/?|[/?]\S+)' +url = u'[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}' -email = ur"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*|^\"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*\")@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?" +email = ur'[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}' diff -r ea28ed44af93abd67777ae326aa3c364bac69ac4 -r d5c9ac8bfb1c30c9e40f896b6150111cb194129a pytyph/rules/html.py --- a/pytyph/rules/html.py Wed Apr 28 15:58:15 2010 +0900 +++ b/pytyph/rules/html.py Wed Apr 28 23:31:17 2010 +0900 @@ -14,9 +14,16 @@ import string from pytyph.typograph import Rule +from pytyph.constants import url, email rules = ( # Замена символа переноса строки на
Rule(ur'\b\s*\n\s*', u'
\n', classes=('html',)), + + # Подсветка URL + Rule(ur'[^"](%s)' % url, u'\g<1>', classes=('html',)), + + # Подсветка E-mail + Rule(u'\b(%s)\b' % email, u'\g<1>', classes=('html',)), ) diff -r ea28ed44af93abd67777ae326aa3c364bac69ac4 -r d5c9ac8bfb1c30c9e40f896b6150111cb194129a pytyph/tests/html.py --- a/pytyph/tests/html.py Wed Apr 28 15:58:15 2010 +0900 +++ b/pytyph/tests/html.py Wed Apr 28 23:31:17 2010 +0900 @@ -15,5 +15,23 @@ self.assertEqual(self.typograph.process(test), right) + def testUrl(self): + test = u'Hello http://www.example.org world' + right = u'Hello http://www.example.org world' + self.assertEqual(self.typograph.process(test), right) + + test = u'Hello world!' + right = u'Hello world!' + self.assertEqual(self.typograph.process(test), right) + + def testEmail(self): + test = u'example@example.com' + right = u'example@example.com' + self.assertEqual(self.typograph.process(test), right) + + test = u'example@example.com' + right = u'example@example.com' + self.assertEqual(self.typograph.process(test), right) + if __name__ == '__main__': unittest.main()