Small changes to default HTML5 templates

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Small changes to default HTML5 templates

MattBlissett
Hi,

I'm using Asciidoctor (and po4a) to build a multilingual document system.

The default styling looks great, but I'd like to make some small changes, and I'm not sure of the best approach.

The templates in the asciidoctor-backends repository aren't maintained – the slim/html5 template throws an error on "image::name.jpg[]", so that's probably not what I should use. (I also wasn't sure which of eml, haml or slim to choose.)

What's the recommended way to make minor changes to the existing html5 template?

Before I realized the problem with the images, I edited the slim templates to generate this with a logo and placeholder for some links above the table of contents.  The "This document is also available in PDF ... español, français" part is generated with a custom extension that looks at what else is in the repository, ideally I'd also like that to be outside the document (above the TOC) as well.  Can a template call an extension for this?

Thanks :)
msc
Reply | Threaded
Open this post in threaded view
|

Re: Small changes to default HTML5 templates

msc


On Apr 16, 2019, at 11:22, MattBlissett [via Asciidoctor :: Discussion] <[hidden email]> wrote:

What's the recommended way to make minor changes to the existing html5 template? 

I don’t know that it is recommended but my way is to put the modified styles in the docinfo.html file.

Regards

    -Mark

Reply | Threaded
Open this post in threaded view
|

Re: Small changes to default HTML5 templates

mojavelinux
Administrator
Asciidoctor gives you lots of options for modifying the generated HTML (and supplementing it with additional CSS). One way is to use templates. As Mark points out, docinfo is another option.

The templates in https://github.com/asciidoctor/asciidoctor-backends are just meant to be a reference to get you started. You only need to use the templates for the nodes you want to change. If a template is missing, Asciidoctor falls back to the built-in HTML converter.

Another solution, new in Asciidoctor 2, is to override the converter directly. This is the same as using templates, but done in Ruby. For example, if you want to override the HTML for a paragraph, you can use:

class MyHtmlConverter < (Asciidoctor::Converter.for 'html5')
  register_for 'html5'
  def convert_paragraph node
    %(<p>#{node.content}</p>)
  end
end

Then just pass that script to the asciidoctor command using the -r option.

Best,

-Dan

On Tue, Apr 16, 2019 at 2:12 PM msc [via Asciidoctor :: Discussion] <[hidden email]> wrote:


On Apr 16, 2019, at 11:22, MattBlissett [via Asciidoctor :: Discussion] <[hidden email]> wrote:

What's the recommended way to make minor changes to the existing html5 template? 

I don’t know that it is recommended but my way is to put the modified styles in the docinfo.html file.

Regards

    -Mark




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Small-changes-to-default-HTML5-templates-tp6851p6854.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Small changes to default HTML5 templates

MattBlissett
Thanks Dan (and Mark), that's exactly what I needed.

> You only need to use the templates for the nodes you want to change.

I had been trying only to use _toc.html.slim, but now I see why that wouldn't work.

I've used a bit of both methods and am very pleased with the result.  Anyone finding this question can see the source.
Reply | Threaded
Open this post in threaded view
|

Re: Small changes to default HTML5 templates

mojavelinux
Administrator
Matt,

In regards to your question:

> I had been trying only to use _toc.html.slim, but now I see why that wouldn't work.

That seems to be a residual file. The template you'd need to override is outline.html.slim (which can also be named block_outline.html.slim as the block_ prefix is optional).

The files that are prefixed with underscore are specific to how the slim templates were implemented in the backends repository. If you're starting from scratch, you don't have to make use of these partials...and frankly you would be better off because then you aren't coupled to how it was done there.

Cheers,

-Dan

On Wed, Apr 17, 2019 at 7:20 AM MattBlissett [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Thanks Dan (and Mark), that's exactly what I needed.

> You only need to use the templates for the nodes you want to change.

I had been trying only to use _toc.html.slim, but now I see why that wouldn't work.

I've used a bit of both methods and am very pleased with the result.  Anyone finding this question can see the source.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Small-changes-to-default-HTML5-templates-tp6851p6856.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux