Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97388
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'feature.': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'index': 0.13; 'syntax': 0.13; 'def': 0.13; 'do,': 0.15; '(but': 0.15; 'skip:p 40': 0.15; '"""\\': 0.16; '[3],': 0.16; 'footnote': 0.16; 'footnotes': 0.16; 'help?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'am,': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'rest': 0.26; 'skip:" 20': 0.26; 'room': 0.27; '[2]': 0.27; 'regular': 0.29; 'itself,': 0.29; '[1]': 0.32; 'changing': 0.34; 'add': 0.34; 'text': 0.35; 'replace': 0.35; 'replaced': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'within': 0.64; 'between': 0.65; 'repeat': 0.67; 'hand.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Footnotes in ReST |
| Date | Sun, 04 Oct 2015 11:50:24 +0200 |
| Organization | None |
| References | <560fbe70$0$1586$c3e8da3$5496439d@news.astraweb.com> <CA+wXuVnA4aPsDzaWNQWtP53Z3Dt-3w9k40uJ-BYx9kBwKi7J6g@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd82a1.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.375.1443952246.28679.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1443952247 news.xs4all.nl 23791 [2001:888:2000:d::a6]:35871 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:97388 |
Show key headers only | View raw
Blake Garretson wrote:
> On Oct 3, 2015 7:40 AM, "Steven D'Aprano" <steve@pearwood.info> wrote:
>> I need to add a footnote between [2] and [3], but I don't want to have to
>> renumber the following 997 footnotes by hand. Is there something I can
>> do, within the syntax of ReST itself, to help?
>
> I would use a regular expression to find and replace all the numbers with
> the auto-numbering feature. So something like "\[\d+\]_" should be
> replaced with "\[#\]_".
With labeled autonumbers:
>>> text = """\
... blah blah blah [1]_ and blah blah blah [2]_.
... blah blah [3]_ blah ... blah blah
... blah blah [999]_.
...
... .. [1] fe
... .. [2] fi
... .. [3] fo
... ...
... .. [999] fum
... """
>>> print(re.compile(r"\[(\d+)\]").sub(r"[#n\1]", text))
blah blah blah [#n1]_ and blah blah blah [#n2]_.
blah blah [#n3]_ blah ... blah blah
blah blah [#n999]_.
.. [#n1] fe
.. [#n2] fi
.. [#n3] fo
...
.. [#n999] fum
Changing numbers to make room for a new footnote is not much harder (but
less convenient as you have to repeat it for every new footnote):
>>> def replace(match, n=2):
... index = int(match.group(1))
... if index >= n:
... index += 1
... return "[{}]".format(index)
...
>>> print(re.compile(r"\[(\d+)\]").sub(replace, text))
blah blah blah [1]_ and blah blah blah [3]_.
blah blah [4]_ blah ... blah blah
blah blah [1000]_.
.. [1] fe
.. [3] fi
.. [4] fo
...
.. [1000] fum
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Footnotes in ReST Steven D'Aprano <steve@pearwood.info> - 2015-10-03 21:39 +1000
Re: Footnotes in ReST Chris Angelico <rosuav@gmail.com> - 2015-10-03 21:57 +1000
Re: Footnotes in ReST Laura Creighton <lac@openend.se> - 2015-10-03 14:21 +0200
Re: Footnotes in ReST Steven D'Aprano <steve@pearwood.info> - 2015-10-04 00:22 +1000
Re: Footnotes in ReST Peter Otten <__peter__@web.de> - 2015-10-04 11:50 +0200
Re: Footnotes in ReST Peter Otten <__peter__@web.de> - 2015-10-04 12:14 +0200
csiph-web