From f3bf3c76995e3ec050433d30fca1bf1155c0ba82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferry=20J=C3=A9r=C3=A9mie?= Date: Sun, 18 Jan 2015 14:10:54 +0100 Subject: [PATCH 1/2] make html's IDs unique on using multiple code-blocks with 'linespans' option activate --- pelican/rstdirectives.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py index 1c25cc42..f485c3fe 100644 --- a/pelican/rstdirectives.py +++ b/pelican/rstdirectives.py @@ -11,6 +11,16 @@ import six import pelican.settings as pys +def integers(): + """Infinite sequence of integers.""" + i = 1 + while True: + yield str(i) + i = i + 1 + +code_block_id = integers() + + class Pygments(Directive): """ Source code syntax highlighting. """ @@ -61,6 +71,8 @@ class Pygments(Directive): if flag in self.options: self.options[flag] = True + self.options['linespans'] += next(code_block_id) + # noclasses should already default to False, but just in case... formatter = HtmlFormatter(noclasses=False, **self.options) parsed = highlight('\n'.join(self.content), lexer, formatter) From 951b1840170aba00919f45e3bbbf5bef554055d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferry=20J=C3=A9r=C3=A9mie?= Date: Sun, 18 Jan 2015 21:15:44 +0100 Subject: [PATCH 2/2] pass travis test with an option --- pelican/rstdirectives.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py index f485c3fe..3182a544 100644 --- a/pelican/rstdirectives.py +++ b/pelican/rstdirectives.py @@ -71,7 +71,10 @@ class Pygments(Directive): if flag in self.options: self.options[flag] = True - self.options['linespans'] += next(code_block_id) + if '' in self.options['linespans']: + self.options['linespans'] = str(self.options['linespans']).replace( + '', next(code_block_id) + ) # noclasses should already default to False, but just in case... formatter = HtmlFormatter(noclasses=False, **self.options)