|
From: <mi...@us...> - 2023-11-19 09:44:30
|
Revision: 9480
http://sourceforge.net/p/docutils/code/9480
Author: milde
Date: 2023-11-19 09:44:17 +0000 (Sun, 19 Nov 2023)
Log Message:
-----------
More smartquotes optimizations.
Simplify regexps (we don't need to consider HTML character entities
when transforming a Docutils document tree).
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/utils/smartquotes.py
trunk/docutils/test/test_transforms/test_smartquotes.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2023-11-19 09:44:04 UTC (rev 9479)
+++ trunk/docutils/HISTORY.txt 2023-11-19 09:44:17 UTC (rev 9480)
@@ -71,6 +71,11 @@
- Update to version `1.4 <https://pypi.org/project/roman/4.1/>`__.
Fixes feature-requests:#95 (license is now ZPL 2.1).
+* docutils/utils/smartquotes.py
+
+ - Pre-compile regexps once, not with every call of `educateQuotes()`
+ (patch #206 by Chris Sewell). Simplify regexps.
+
* docutils/writers/latex2e/__init__.py
- Fix placement of hyperlink target (label) for tables (bug #440).
Modified: trunk/docutils/docutils/utils/smartquotes.py
===================================================================
--- trunk/docutils/docutils/utils/smartquotes.py 2023-11-19 09:44:04 UTC (rev 9479)
+++ trunk/docutils/docutils/utils/smartquotes.py 2023-11-19 09:44:17 UTC (rev 9480)
@@ -1,6 +1,6 @@
#!/usr/bin/python3
# :Id: $Id$
-# :Copyright: © 2010 Günter Milde,
+# :Copyright: © 2010-2023 Günter Milde,
# original `SmartyPants`_: © 2003 John Gruber
# smartypants.py: © 2004, 2007 Chad Miller
# :Maintainer: doc...@li...
@@ -149,19 +149,13 @@
posts (and final HTML output) will appear with smart quotes, em-dashes,
and proper ellipses.
-SmartyPants does not modify characters within ``<pre>``, ``<code>``, ``<kbd>``,
-``<math>`` or ``<script>`` tag blocks. Typically, these tags are used to
-display text where smart quotes and other "smart punctuation" would not be
-appropriate, such as source code or example markup.
-
-
Backslash Escapes
=================
If you need to use literal straight quotes (or plain hyphens and periods),
`smartquotes` accepts the following backslash escape sequences to force
-ASCII-punctuation. Mind, that you need two backslashes as Docutils expands it,
-too.
+ASCII-punctuation. Mind, that you need two backslashes in "docstrings", as
+Python expands them, too.
======== =========
Escape Character
@@ -259,6 +253,10 @@
Version History
===============
+1.10 2023-11-18
+ - Pre-compile regexps once, not with every call of `educateQuotes()`
+ (patch #206 by Chris Sewell). Simplify regexps.
+
1.9 2022-03-04
- Code cleanup. Require Python 3.
@@ -387,10 +385,10 @@
class smartchars:
"""Smart quotes and dashes"""
- endash = '–' # "–" EN DASH
- emdash = '—' # "—" EM DASH
- ellipsis = '…' # "…" HORIZONTAL ELLIPSIS
- apostrophe = '’' # "’" RIGHT SINGLE QUOTATION MARK
+ endash = '–' # EN DASH
+ emdash = '—' # EM DASH
+ ellipsis = '…' # HORIZONTAL ELLIPSIS
+ apostrophe = '’' # RIGHT SINGLE QUOTATION MARK
# quote characters (language-specific, set in __init__())
# https://en.wikipedia.org/wiki/Non-English_usage_of_quotation_marks
@@ -509,9 +507,9 @@
# character classes:
_CH_CLASSES = {'open': '[([{]', # opening braces
'close': r'[^\s]', # everything except whitespace
- 'punct': r"""[-!" #\$\%'()*+,.\/:;<=>?\@\[\\\]\^_`{|}~]""",
- 'dash': r'[-–—]|&[mn]dash;|&\#8211;|&\#8212;|&\#x201[34];',
- 'sep': '[\\s\u200B\u200C]| ', # Whitespace, ZWSP, ZWNJ
+ 'punct': r"""[-!" #\$\%'()*+,.\/:;<=>?\@\[\\\]\^_`{|}~]""",
+ 'dash': r'[-–—]',
+ 'sep': '[\\s\u200B\u200C]', # Whitespace, ZWSP, ZWNJ
}
START_SINGLE = re.compile(r"^'(?=%s\\B)" % _CH_CLASSES['punct'])
START_DOUBLE = re.compile(r'^"(?=%s\\B)' % _CH_CLASSES['punct'])
@@ -679,7 +677,7 @@
Returns: The `text`, with "educated" curly quote characters.
Example input: "Isn't this fun?"
- Example output: “Isn’t this fun?“;
+ Example output: “Isn’t this fun?“
"""
smart = smartchars(language)
@@ -737,7 +735,7 @@
Returns: The `text`, with ``backticks'' -style double quotes
translated into HTML curly quote entities.
Example input: ``Isn't this fun?''
- Example output: “Isn't this fun?“;
+ Example output: “Isn't this fun?“
"""
smart = smartchars(language)
@@ -813,7 +811,7 @@
an ellipsis character.
Example input: Huh...?
- Example output: Huh…?
+ Example output: Huh…?
"""
text = text.replace(r'...', smartchars.ellipsis)
Modified: trunk/docutils/test/test_transforms/test_smartquotes.py
===================================================================
--- trunk/docutils/test/test_transforms/test_smartquotes.py 2023-11-19 09:44:04 UTC (rev 9479)
+++ trunk/docutils/test/test_transforms/test_smartquotes.py 2023-11-19 09:44:17 UTC (rev 9480)
@@ -32,6 +32,8 @@
class TransformTestCase(unittest.TestCase):
+ maxDiff = None
+
def test_transforms(self):
parser = Parser()
settings = get_default_settings(Parser)
@@ -183,7 +185,6 @@
escaped space\\ "a" and\\ 'a',
hyphen -"a", -'a'
-—"a",—'a'
en dash –"a"–'a',
em dash —"a"—'a'.
@@ -210,7 +211,6 @@
escaped space“a” and‘a’,
<paragraph>
hyphen -“a”, -‘a’
- —“a”,—‘a’
en dash –“a”–‘a’,
em dash —“a”—‘a’.
<paragraph>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|