A simple way to export using a word processor's paragraph styles

The contents of this post will seem trivial to experienced TB users, but maybe they will be helpful to novices like me.
I recently decided that I should try using Tinderbox for writing rather than simply making notes and sorting out my ideas before writing a document, usually in Scrivener. Although the advantage of Tinderbox will come only when I have more complicated projects to organise, I decided to start with a simple one to learn how to do it. The files I was writing had the following structure.

The first level notes are chapter headings, which may or may not have any text in them. Within each chapter are sections, each of which contains text.
The problem I had was that I wanted to export all these notes to a word processor, including both headings and text, and to have everything formatted using the word processor’s paragraph styles. I could not get any of the built-in methods to export text as I wanted it. After getting into a muddle, one of Michael Becker’s videos (thank you!) led to a simple solution.
As Mark Anderson points out elsewhere, the easiest way to export a batch of notes is to put them into a container:

Then create an HTML Export Template for each level of notes as follows:

Level 0:
^children(/Templates/Level0/Level1)^

Level 1:

Level 2:

Note that nothing from Level 0 (other than its children) is output, because it is merely used as a container to group notes together.

After that, to export all the chapters, select Note 0, attach the Level 0 template and export the Selected Note. No need to attach Templates to the notes inside Note 0. Note that you need to do it by opening an HTML file in LibreOffice because otherwise the HTML code is not converted.

To export a single “chapter” (Note 1, Note 2 etc) with all its contents, click on the “Export” pane in the Note, and set the Template to Level 1. The note can then be exported to an HTML file. It can then be opened in LibreOffice, and when the text is copied and pasted into a regular document, the headings will all have corresponding styles attached.

It would be very easy to extend this to further levels of note, including or excluding Titles as desired.

Maybe there are easier ways of doing this in TB, and there are obviously other ways to convert HTML to text formatted with paragraph styles, but using LibreOffice is very easy, and from there it can go into any other word processor.

This is like the envelope-and-letter technique, but required multiple descendant template because of the need to hard-set the heading level(i.e. <h2> for level 2, etc.).

This can easily be resolved by making the heading dynamic. The envelope template “tEnvelope”:

<h^value($OutlineDepth)^>^title^</h^value($OutlineDepth)^>
^text^
^children("tLetter")^

Here, the root note has $Text but you could leave out the ^text^ call. Now, the letter (template “tLetter”:

<h^value($OutlineDepth)^>^title^</h^value($OutlineDepth)^>
^text^
^children("tLetter")^

The problem you now face is whether the root container is at $OutlineDepth of 1. If not you could add/remove an offset value in all the ^value($OutlineDepth)^ calls, e.g. `^value($OutlineDepth-2)^ in the root exporting container is at outline depth of 3.

Or you could use action code (via a rule predict) to seed a use $HeadingLevel. In the last example $OutlineDepth at root might be 3 but $HeadingDepth would be set to 1, etc. Then, the templates are, template “tEnvelope”:

<h^value($HeadingLevel)^>^title^</h^value($HeadingLevel)^>
^text^
^children("tLetter")^

Now, the template “tLetter”:

<h^value($HeadingLevel)^>^title^</h^value($HeadingLevel)^>
^text^
^children("tLetter")^

My searches did not uncover the envelope and letter technique. The problem is knowing what words to search for. I shall study this carefully with a view to improving my Templates, though for my current simple project they are working nicely.

Thank you.

1 Like

A challenge is that the ‘envelope and letter’ metaphor is a description but not necessarily canonical, I don’t believe there is a single term to search for. The technique in use is recursion but the isn’t a topic most of us non-tech lay readers would likely understand at first glance (it’s not lesson #1 in computer science).

For clarity, I didn’t mention the technique in a manner of censure. I was simply trying to help community members build out from your original article. The link was by way of reference, not a suggestion of a lack of searching. :slight_smile: