Re: [Docutils-users] Class parameter is not effective in code directive (rst2latex)
Sébastien Dailly <[email protected]>
| Newsgroups | gmane.text.docutils.devel,gmane.text.docutils.user |
|---|---|
| Message-ID | <[email protected]> |
Le 2017-04-19 09:36, Sébastien Dailly a écrit :
> Hello,
>
> I'm stuck with rst2latex : I want to customize the code-block rendering
> with a dark background. rst2latex translate this directive to a quote
> environnment which I can't override because it is already used
> elsewhere
> in the document.
>
> I've tried to add a class parameter to the directive
>
>>
>> .. code-block:: C
>> :class: darkBackground
>>
>> // Comment
>>
>
> But this does not seems to work (the class parameter is discarded)
>
>> \begin{quote}
>> {\ttfamily \raggedright \noindent
>> \DUrole{comment}{\DUrole{single}{//~Comment\\
>> }}~\\
>
> I've also tried to wrap the code directive inside a class one :
>
>> .. class:: darkBackground
>>
>> .. code-block:: C
>>
>> // Comment
>
> But this does not give the expected result.
>
> This seems to be a problem with the writer, because rst2html gives the
> class in the output :
>
>> <pre class="code C darkBackground literal-block">
>> <span class="comment single">// Comment
>
> Is this a known bug ? Is there a workaround for this ?
>
> Thanks a lot !
I've found a solution by editing the writer :
> $ diff -c5 __init__.py /cygdrive/t/__init__.py
> *** __init__.py 2017-04-19 10:33:56.977196800 +0200
> --- /cygdrive/t/__init__.py 2017-04-19 10:33:51.485961600 +0200
> ***************
> *** 2450,2459 ****
> --- 2450,2461 ----
> 'lstlisting': r'\usepackage{listings}',
> 'Verbatim': r'\usepackage{fancyvrb}',
> # 'verbatim': '',
> 'verbatimtab': r'\usepackage{moreverb}'}
>
> + if node['classes']:
> + self.visit_inline(node)
> if node.get('ids'):
> self.out += ['\n'] + self.ids_to_labels(node)
>
> if not self.active_table.is_open():
> # no quote inside tables, to avoid vertical space between
> ***************
> *** 2493,2502 ****
> --- 2495,2506 ----
> self.literal = False
> self.verbatim = False
> self.alltt = False
> self.out.append(self.context.pop())
> self.out.append(self.context.pop())
> + if node['classes']:
> + self.depart_inline(node)
>
> ## def visit_meta(self, node):
> ## self.out.append('[visit_meta]\n')
> # TODO: set keywords for pdf?
> # But:
It seems to be a bug in the writer (I'm ccing docutils-develop). I have
no idea if this change can break other construction… Can you check if
this change can be integrated in the project ?
Thanks !
--
Sébastien
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-develop
Please use "Reply All" to reply to the list.