Modified Export Code in HTML item from October 2 Meetup

I’ve watched what @satikusala demonstrated last Saturday on the video, and I’ve tried to replicate it in a small test file. I’m ignoring the CSS piece to make things as simple as possible, and I have just changed the code in HTML item

When I view the Preview/Export panes, the export seems to default to H3 for all notes of $OutlineDepth 2 or greater, when $Outline depth 2 should be H2.

The relevant portion of the recorded video begins at 1hr. 20min.

I believe I entered the export code correctly:

^if ($0utlineDepth="2")^
<h2>^title^</h2>
^text
^children (/Templates/HTML page/HTML item)^
^else^
<h3>^title^</h3>
^text
^children(/Templates/HTML page/HTML item)^
^endif^

(angle brackets omitted for clarity on this page)

The attached file should exhibit the issue.

What am I doing wrong.tbx (103.1 KB)

Not necessarily the cause of the main problem, but one obvious error is using ‘=’ (assign a value) in a query when trying to set equality of two terms, i.e. ‘==’. IOW, that line should be:

^if ($0utlineDepth=="2")^

Using the correct syntax is a query matters. It might be hard to remember first time but as the usage is documented (links above) check the documentation each time until you are confident you’ve learned the syntax.

also, in an ^if^ code there this no space between the command name and the opening parentheses. WRONG:

^if ($0utlineDepth=="2")^

CORRECT:

^if($0utlineDepth=="2")^

The layout matters. Again, as a first check, look at available docs and fix syntax errors before looking for other issues.

Further error, again do proof read for syntax, in your “HTML item” template, WRONG:

^children (/Templates/HTML page/HTML item)^

Not the stray space after ‘children’. RIGHT:

^children(/Templates/HTML page/HTML item)^

After cleaning the cause becomes clear. OutlineDepth is spelt with a capital ‘o’ and not a zero. Wrong:

^if($0utlineDepth=="2")^

Right:

^if($OutlineDepth=="2")^

As 0utlineDepth is, I believe a valid attribute name, Tinderbox can’t tell that the reference is a typo for OutlineDepth as opposed to referring to a not-yet-defined user attribute called 0utlineDepth.

1 Like

I picked up on 0utlineDepth beginning with a zero right away, thanks to my ancient FORTRAN reflexes. This is the sort of error that’s truly hard to catch!

2 Likes

Well, it appears that I have outsmarted myself once again. Rather than try and type the code in from the video frame, and make a typographical error, I used TextSniper and converted the screencap into text.

I thought I did look at it closely, but I missed the zero entirely, I’ll need to pick a font that uses a slashed zero. I don’t know if Textsniper inserted the extra space after ^children, that may have been me as I fumbled around trying various configurations, adding and subtracting spaces between various elements.

I did try the “==” in the obviously defective code, so naturally that didn’t seem to make a difference. I also recalled the “=” for assignment “==” for comparison discussion I heard someplace; but I think if you look at the video at 1:22:27, there’s just single “=” and it seemed to work fine. So either I need a new prescription or that “==” isn’t essential in export code. But I’ll stick with it in comparisons, just to be consistent between export code and action code.

The zero is what got me. Probably would have worked right the first time. I think the extra space is something I did.

Thanks for the help.

Yes, that’s due to legacy support for very old code where = was allowed in a query, and thus my note that it likely wasn’t the cause. :slight_smile:


Given all your attention to detail it seems TextSniper may well have been the innocent cause of the stray extra spaces inserted in commands. there, it will be trying to make readable sense of the scanned text. In that context, script/code is very typical writing. Tinderbox may have coped with extra space—but it’s best not to rely on that.

The mis-named attribute seems the root cause here, but it’s useful to see how innocently some of the errors crept in, e.g. OCR-type software misunderstanding code as parsing with normal written English conventions.

Amen. As pre-digital Navy signals guy I still find myself reflexively using a crossing bar on zero (0 vs O), 7 (7 vs. 1) and Z (vertical bar for Z vs 2); working at speed under minimal red lighting clarity trumps aesthetics (this may ring a bell for some readers :wink:). So, oddly, I didn’t gat quite the same prompt, even on opening the template. Why? Aesthetics. The font designer of the font (here Andale Mono) chose to reassert aesthetics and replace the zero-with-diagonal-bar (a normal zero with cross-strike) with a dot on the middle of the character.

No foul there though, as IIRC Andale Mono was designed for aiding machine OCR rather than human character recognition. But it does explain why just changing the ‘normal’ style of cross-strike zero failed to register as quickly as it did for Mark.

If anyone is still reading, one more tip, from experience. If the code isn’t working, but you’ve confidence it should (e.g. you’ve used the same commands elsewhere) and it is still failing, try re-typing the code from scratch. Ideally don’t touch-type whilst reading from the existing code. The trick works because, for instance, whereas the eye might read if (… and see no issue when typing an if() from memory you are unlike to insert an unwanted space. Old-style human hack that’s got me out of the pickle in the past. Odd how our (proof)reading skills are nerfed when screen reading. I mis miss errors on screen that I never do if reading the same text printed on paper.

[Edit: necessary post-edit correction in last line above proves my point. Only spotted that re-reading the article later on].

1 Like

typo can be very nasty while debugging code…

Just another solution for the headline structure in the html child export code:

<h^value($OutlineDepth)^>^title^</h^value($OutlineDepth)^>

No need for nested if constructs.

1 Like

True, this is useful technique but actually solves a different issue.

However, the intent here isthat everything 2 levels down or more from the top exported note will use an <h3> for its heading. Therefore ^value($OutlineDepth)^ would be wrong for outline levels 4+.

†. IIRC, I think I first posted that approach back in Tinderbox v5 days, for exporting outlines. Seems like yesterday, though actually not. :open_mouth:

1 Like

I tried to use a dictionary where I can apply a specific value for each level - for example $HeadingLevel=“1:1;2:2;3:3;4:3;5:3;6:3” and then use

<h^value($HeadingLevel[$OutlineDepth])^>^title^</h^value($HeadingLevel[$OutlineDepth])^>

But this will not work - I have to figure out why :wink:

When trying to figure out a tricky template, it’s useful to compare the HTML that’s being exported (see the HTML pane) with what you wanted to export. That way, we know what didn’t work, and can figure out how to fix it.

I can’t test (no test document offered) but I’d wager you’ve set the dictionary in a single note and then assuming the template knows where to find it.

I’d guess you meant to do something like:

<h^value($HeadingLevel[$OutlineDepth])^>^title^</h^value($HeadingLevel[$OutlineDepth("config_note")])^>

where the $HeadingLevel[ for note “config_note” holds the value dictionary you are assuming.

You could set the doc level HeadingLevel value to "1:1;2:2;3:3;4:3;5:3;6:3" but I’m guessing that isn’t what you want.

Hi Mark,

thanks for your help - I added the attribute to the HTML item template itself.
Tried with a config note too - same result: no value parsed into the final html

p.s: ^value($HeadingLevel(“config_note”)[$OutlineDepth])^ will do it :wink:

The working sample:
test_heading.tbx (108.9 KB)

1 Like