Re: [Docutils-users] header directive in rst2html and rst2pdf

On Tue, 29 Jan 2013 19:43:20 -0300
Roberto Alsina <ralsina@...> wrote:
> Probably not what you want, but you could set the header in rst2pdf
> from the stylesheet or the command line (--header option) instead of
> the document.
Good call! I hadn't realised that the --header existed as my local man
page doesn't mention it. I should have checked rst2pdf -h which does
describe it. So, I used:
--header="###Title### - Page ###Page### of ###Total###"
which worked.
However, it is a little cumbersome typing this on the commandline.
Would a directive which allows one to direct parts of a document to
only specified converters be feasible?
Regards,
Iain.

Thread view

Hello,
Docutils newbie here.
I created a single reStructuredText document which I want to convert to
PDF and HTML using rst2pdf and rst2html respectively. For the PDF
version I have used:
.. header:: ###Title### - Page ###Page### of ###Total###
which produces exactly the desired results. However, when using
rst2html it prints the literal text.
So, I used:
--strip-elements-with-class=header
However, this does not change the output (header created after the
strip perhaps).
Any suggestions how to handle this with a single source file?
Regards,
Iain.
rst2html (Docutils 0.8.1 [release], Python 2.7.3rc2, on linux2)

On 29/01/13 19:14, Iain Mac Donald wrote:
> Hello,
>
> Docutils newbie here.
>
> I created a single reStructuredText document which I want to convert to
> PDF and HTML using rst2pdf and rst2html respectively. For the PDF
> version I have used:
> .. header:: ###Title### - Page ###Page### of ###Total###
>
> which produces exactly the desired results. However, when using
> rst2html it prints the literal text.
>
> So, I used:
> --strip-elements-with-class=header
>
> However, this does not change the output (header created after the
> strip perhaps).
>
> Any suggestions how to handle this with a single source file?
Probably not what you want, but you could set the header in rst2pdf from
the stylesheet or the command line (--header option) instead of the
document.

On Tue, 29 Jan 2013 19:43:20 -0300
Roberto Alsina <ralsina@...> wrote:
> Probably not what you want, but you could set the header in rst2pdf
> from the stylesheet or the command line (--header option) instead of
> the document.
Good call! I hadn't realised that the --header existed as my local man
page doesn't mention it. I should have checked rst2pdf -h which does
describe it. So, I used:
--header="###Title### - Page ###Page### of ###Total###"
which worked.
However, it is a little cumbersome typing this on the commandline.
Would a directive which allows one to direct parts of a document to
only specified converters be feasible?
Regards,
Iain.

On 30/01/13 09:12, Iain Mac Donald wrote:
> On Tue, 29 Jan 2013 19:43:20 -0300
> Roberto Alsina <ralsina@...> wrote:
>
>> Probably not what you want, but you could set the header in rst2pdf
>> from the stylesheet or the command line (--header option) instead of
>> the document.
> Good call! I hadn't realised that the --header existed as my local man
> page doesn't mention it. I should have checked rst2pdf -h which does
> describe it. So, I used:
> --header="###Title### - Page ###Page### of ###Total###"
>
> which worked.
Looks like I need to update the man page :-)
> However, it is a little cumbersome typing this on the commandline.
> Would a directive which allows one to direct parts of a document to
> only specified converters be feasible?
>
No idea, sorry.

On Wed, 30 Jan 2013 09:27:23 -0300
Roberto Alsina <ralsina@...> wrote:
> Looks like I need to update the man page :-)
I was referring to the man page provided by Debian (I am using
Wheezy) written by Chris Lamb. This man page is dated 2008 which might
mean it is a bit out of date.
Thanks for providing rst2pdf it is a great package.
Regards,
Iain.

On Wednesday 30 January 2013 13:12:19 Iain Mac Donald wrote:
> […] So, I used:
> --header="###Title### - Page ###Page### of ###Total###"
>
> which worked.
>
> However, it is a little cumbersome typing this on the commandline.
Then type it once into a script or makefile or something similar.
Ciao,
Marc 'BlackJack' Rintsch

On Wed, 30 Jan 2013 14:08:17 +0100
"Marc 'BlackJack' Rintsch" <marc@...> wrote:
> On Wednesday 30 January 2013 13:12:19 Iain Mac Donald wrote:
> > […] So, I used:
> > --header="###Title### - Page ###Page### of ###Total###"
> >
> > which worked.
> >
> > However, it is a little cumbersome typing this on the commandline.
>
> Then type it once into a script or makefile or something similar.
Thanks for the suggestion. I had thought about having a wrapper script
that sets my own options depending on the desired output. However, I
thought it worthwhile to ask if there was a "proper" way of doing it.
An advantage of a wrapper script would be to integrate my choice of
page template and style file at the same time.
Regards,
Iain.

On Wed, 30 Jan 2013 13:54:39 +0100
Guenter Milde <milde@...> wrote:
>> So, I used:
>> --strip-elements-with-class=header
>> However, this does not change the output (header created after the
>> strip perhaps).
> The element "header" does not have *class* "header", so this is
> expected.
That is not how I read the man page nor rst2html -h output. When I use
the ::header directive and then convert using rst2html I get output
like this:
<div class="header">
###Title###
<hr class="header"/>
</div>
rst2html -h for --strip-elements-with-class=<class> states:
Remove all elements with classes="<class>" from the document tree.
The <div> element has the class "header" so, the whole <div> should be
removed. It isn't removed.
> I did some experimentation, but also with the example::
>
> Was ist das?
>
> .. class:: no-html
>
> .. header:: ###Title### - Page ###Page### of ###Total###
>
> Wau.
>
> Actually the class is applied to the paragraph following the header
> directive, it seems that the header element is handled/moved before
> the application of the class directive.
>
> The documentation
> http://docutils.sourceforge.net/docs/ref/rst/directives.html#document-header-footer
> reveals that the header directive does not take options, so that ::
>
>
> .. header:: ###Title### - Page ###Page### of ###Total###
> :class: no-html
>
> does not work either.
I had tried both those approaches too, but, thanks for the suggestion.
>
> Maybe the "header" directive should get a "class" option.
I am not sure that would work either for the reasons described above.
For my particular document the page title would be useful for the
HTML output but not the page n of n. That is why I was thinking a way
of restricting directives to particular output destinations would be
useful.
Regards,
Iain.

On 30/01/13 12:20, Iain Mac Donald wrote:
> That is not how I read the man page nor rst2html -h output. When I use
> the ::header directive and then convert using rst2html I get output
> like this:
> <div class="header">
> ###Title###
> <hr class="header"/>
> </div>
In which case you can just hide it via CSS...

On 2013-01-30, Iain Mac Donald wrote:
> On Wed, 30 Jan 2013 13:54:39 +0100
> Guenter Milde <milde@...> wrote:
>>> So, I used:
>>> --strip-elements-with-class=header
>>> However, this does not change the output (header created after the
>>> strip perhaps).
>> The element "header" does not have *class* "header", so this is
>> expected.
> That is not how I read the man page nor rst2html -h output. When I use
> the ::header directive and then convert using rst2html I get output
> like this:
><div class="header">
> ###Title###
><hr class="header"/>
></div>
> rst2html -h for --strip-elements-with-class=<class> states:
> Remove all elements with classes="<class>" from the document tree.
If you compile the example with rst2xml or rst2pseudoxml, you will get a
representation of the document tree.
<document source="/tmp/foo.rst">
<decoration>
<header>
<paragraph>
###Title### - Page ###Page### of ###Total###
<paragraph>
Was ist das?
<paragraph classes="no-html">
Wau.
> The <div> element has the class "header" so, the whole <div> should be
> removed. It isn't removed.
The conversion <header> -> <div class="header"> is only done in the HTML
writer, after the application of the strip-elements-with-class transform
(this is a good thing, because this way it is possible to remove elements
that would fail otherwise).
>> I did some experimentation, but also with the example::
>> Was ist das?
>> .. class:: no-html
>> .. header:: ###Title### - Page ###Page### of ###Total###
>> Wau.
>> Actually the class is applied to the paragraph following the header
>> directive, it seems that the header element is handled/moved before
>> the application of the class directive.
>> The documentation
>> http://docutils.sourceforge.net/docs/ref/rst/directives.html#document-header-footer
>> reveals that the header directive does not take options, so that ::
>> .. header:: ###Title### - Page ###Page### of ###Total###
>> :class: no-html
>> does not work either.
> I had tried both those approaches too, but, thanks for the suggestion.
>> Maybe the "header" directive should get a "class" option.
> I am not sure that would work either for the reasons described above.
> For my particular document the page title would be useful for the
> HTML output but not the page n of n. That is why I was thinking a way
> of restricting directives to particular output destinations would be
> useful.
Exactly this should be possible with a class argument assigned to the
directive in the document and e.g.
[html4css1 writer]
strip-elements-with-classes: no-html
in the configuration file.
Günter