Re: Custom style on title/heading element?

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Solved-Custom-style-on-title-heading-element-tp4543p4551.html

Erik,

We like follow-ups. It helps others who are facing the same challenge.

after digging a little deeper I'm pretty confident I'm going to need to use a template.

Correct. Templates are the simplest way to customize the HTML that Asciidoctor generates by default (and keep in mind, it's just a default). In fact, you can use templates to change every bit of HTML that is generated.

Before I continue, I want to acknowledge that we're still missing a tutorial for how to use custom templates. I welcome assistance from anyone who wants to help make it happen. See https://github.com/asciidoctor/asciidoctor.org/issues/80

I'm working on incorporating the following theme with Middleman/Asciidoc so that contributors don't have to write ERB: 

👍

 the slim you referenced ... I assume is the "out of the box" template: 

For the most part, yes. It requires the helpers.rb file that is found in the same directory (in other words, you need to pull out both files).

There's also a HAML version.

https://github.com/asciidoctor/asciidoctor-backends/blob/master/haml/html5/section.html.haml 

I'm guessing I'll need to engineer a template that somehow gets passed an attribute "anchored" which inserts the fragment identifier bit... which is where I'm a little lost. 

When making a custom template, I always recommend starting simple and adding things back in as you go. That's how I start. Therefore, you might start with:

*{tag: %(h#{level + 1}), id: id, class: role}
  =captioned_title
=content

For your example, that will give you:

<h3 id="_this_title_is_styled" class="category-title">This Title Is Styled</h3>
section content here

In order to load the templates when using Middleman, you need to set the following option in your config.rb file:

set :asciidoc, {
  safe: :safe,
  template_dir: 'path/to/templates',
  attributes: %W(showtitle env=middleman env-middleman middleman-version=#{Middleman::VERSION})
}

NOTE: The value of the asciidoc_attributes option is appended to the attribute list in the value of the asciidoc option.

You may want to set other options or attributes.

I hope that helps!

Cheers,

-Dan 

--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen