Paragraph designation when exporting to HTML

When exporting to HTML, is there a way to change when a line is designated as a new paragraph and given the paragraph tags?

For example, if I have a note with the following text:

First paragraph line 1
First paragraph line 2
First paragraph line 3

Next paragraph line 1
Next paragraph line 2
Next paragraph line 3

It will export in HTML as:

<p>First paragraph line 1</p>
<p>First paragraph line 2</p>
<p>First paragraph line 3</p>

<p>Next paragraph line 1</p>
<p>Next paragraph line 2</p>
<p>Next paragraph line 3</p>

What I would like is:

<p>First paragraph line 1
First paragraph line 2
First paragraph line 3</p>

<p>Next paragraph line 1
Next paragraph line 2
Next paragraph line 3</p>

Thanks!

Each note has its own markup attributes. So, you could explode each line into its own note, and modify the markup for each note.

Note that there are separate attributes for $HTMLParagraphStart/End and for $HTMLFirstParagraphStart/End.

Thanks for your quick response!

I did take a look at the documentation and I saw the $HTMLParagraphStart/End attributes that you mentioned. However, I don’t think that’s what needs to be modified, but I could be wrong since I’m new to TBX.

I think what needs to be modified is where TBX designates a new paragraph. It looks like it designates a new paragraph at a single newline, but I would like to change it so it designates it at two newlines.

Thanks for your help!

That was going to be my new question: how do we recognize where the paragraph starts?

Short answer: you can’t change this.

Clever answer: you can, if you want! Three ways:

  1. Quick and dirty: Search and replace double newlines with a place marker string — perhaps “•”. Now, replace all remaining newlines with the empty string. Finally, replace your place marker string with a single newline \n.

  2. Less quick, less dirty: Explode your text at double newlines. For the exploded notes, omit paragraph markup entirely, and insert <p> and </p> before and after the text in the template.

  3. Less dirty, arguably: use ctrl-Return to obtain a line break in Tinderbox that is not treated as a paragraph ending for export.

Thanks, the ctrl-Enter did the trick!

The alternative approach is to use
tags in HTML or Markdown. Using <br> over ctrl-return could give you more control down the road as you can use action code to easily remove them later

Figure: Text

Figure: Preview

Figure: HTML

1 Like

Exporting to HTML can be a bit finicky with how it handles paragraph breaks, especially if you’re trying to keep the code clean. If you’re seeing weird spacing or unwanted line breaks in the output, it’s often due to how the source text is structured before the export filters even touch it.

One thing that helps me is ‘flattening’ the text first to make sure there aren’t any hidden breaks causing issues. I usually just run it through Paragraph to Single Line Converter Online to get a clean block of text before I apply the HTML tags. It’s much easier than hunting through the source code to find where a stray or tag is coming from!

Empty paragraphs are not exported to HTML, if using the likes of $Text. So a run of, for instance 3 line breaks (\n\n\n) is treated as if one (\n).

If the eye is offended by ‘messy’ HTML output, time getting to know export code is recommended. In a template all line breaks are literal. A common misunderstanding re output is to put a line break after an^endIf^ rather than before it. This does mean the template looks a bit odd as the ^endIf^ now sit—in the template—at the beginning of the next paragraph. It is certainly hard to get ‘pretty’ layout in all three of $Text, template and output HTML. For my 2¢, I put up with a messy looking template layout in order that the HTML layout is cleaner. Only I look at the template: others might need to look at (understand) the output code.