Print HTML in Tinderbox $Text

I don’t want this to be a functioning link. I want it to simply show the text "Name ". How do I comment the <…> so that prevview shows this as text and does not read it as HTML.

Here is another example.

In the image below, I have a bunch of code that I want to display as text.

Preview renders it and does not display it as text:

How can I bloke out the code so it renders as text?

put <code></code> tags in the $Text around the code samples, ^text^ export will retain these and cause the (preview) browser to render that text in monospace font. If you have discrete lines of code (i.e. with line breaks between lines) use <pre>/</pre> instead. See more on exporting code samples.

OK, sadly we don’t have a definite example string, so I’ll assume you have an $EmailAddress value with a string like "<j.doe@example.com>". We want it to export as "&lt;j.doe@example.com&gt;" to the angle brackets show as literal characters on screen. Here is our $Text:

On the shores of Gitche Gumee,
Of the shining Big-Sea-Water,
Name: ^value(escapeHTML($EmailAddress))^

which exports as:

<p>On the shores of Gitche Gumee,</p>
<p>Of the shining Big-Sea-Water,</p>
<p>Name: &lt;j.doe@example.com&gt;</p>

which renders as :

On the shores of Gitche Gumee,

Of the shining Big-Sea-Water,

Name: <j.doe@example.com>

See more on escapeHTML(). Remember, inside ^value()^, it is literal text, values from attributes or action code. So, we need to add HTML encoding of HTML mark-up-like characters—e.g. angle brackets—in the $EmailAddress whilst still in action code context before exporting the result to the HTML output (now in HTML-safe form) via the ^value()^ call.

Sorry, I don’t mean to be difficult. This is just not working for me. To be clear, I’m not trying to do this in an export template, I’m trying to do this in $Text. I want the code to be displayed as text.

I tried this, no joy.

^value(escapeHTML($AttendedNames=runCommand((“awk -F ’ <’ ‘/</ {print $1}’|awk 'FNR==1 " + “{printf(” + '”%s",’ + “$0);next}” + “{printf(” + ‘";%s",’ + “$0)}’”),$Text);))^

The argument to escapeHTML must be a string. But you can’t put this particular string into either single or double quotes, because it contains both single and double quotes.

Instead, put it in a string attribute, and use ^value(escapeHTML($ThatAttribute))

Is there no easier way? I really don’t want this to be an attribute, I simply want it to be inline text.

This does seem to work, which is good.

However, if I have numerous examples of code in one not the I need to create a bunch of code attributes. This does not feel efficient. Totally admit I may be missing some big aha insight.

Think about it from the point of view of the program.

You: “Say cheese!”
Tinderbox: cheese!
You: Say “Mary read ‘War and Peace’ yesterday.”
Tinderbox: Mary read ‘War and Peace’ yesterday.
You: Say “Another good book is ‘“Hello”, He Lied’ by Lynda Obst.”
Tinderbox: “Another good book is '”
You: What gives?
Tinderbox: I said what you told me.
You: That’s not what I meant.
Tinderbox: I started at the quotation mark, and continued to the matching quotation mark.

As illustrated above, however many escape mechanisms you have, examples will still need to escape the escapes. And here, we’re talking about special parsing by Tinderbox and also by HTML.

3 Likes

Ya, that makes sense. I appreciate your taking the time to help me see the world through the eyes of the program.

Did you try <code> and or <pre>, as in:

<code>^value($Code)^</code>

or

<pre>^value($Code)^</pre>

?

Ya, both.

Odd - do you have a demo file. It defies logic those shouldn’t work, but without seeing real code it’s hard to tell.

Try using the entity codes. &lt; and &gt; – it works for me.

Your longer awk example can be handled the same way – use TextSoap or an online tool that will entity-encode text for you. Search for “HTML entity encode online” and several options will pop up.

Funny you ask, yes I do, please see attached TBXUC - ParseTextToSemiColonList.tbx (652.1 KB) .

I’m working on creating a format for memorializing my Tinderbox use cases and solutions. In addition to helping me with the code insertion (see Parse Names, Parse Emails, Considerations) issue, can you also take a look at three others?

First, I did try the suggestion in the Parse Names note, but it ends up turning all my preview formatting through the document to code format. It does not work at all for the Stamp examples; the only thing that works for this is the attribute insertion idea Mark provided.

Secondly, any idea on the best way to handle embedded images in a demo file like this? I’d love to have the images exportable, but I can’t do this if the file is shared with others as the images will be on my hard drive.

Thirdly, any ideas on how to improve this use case explanation format? I’d like to create more of these. I think they’ll be useful for others, they give attribution to those that help, and I learn a lot!

1 Like

Try the entity encoding I pointed out to you. It’s a standard way of handling HTML code within HTML.

1 Like

Yup, just tried TextSoap, per your recommendation. I works great. Thanks.

Rather like working with XML, a small number of characters will need handling with care. the left angle bracket < is one such. Markdown—used to write this post has a similar limitation.

This < displays because it is placed between back-ticks with causes the markdown parser to place the characters in <code></code> tags. The preceding tags only rendered as the opening < of each tags was preceded by a backslash.

It some point, the sort of documentation you’re trying to do will involved some extra gymnastics most users don’t need - so bear that in mind in your tutorials lest learners are spooked by the possibility of problems they may not meet. An example of such extra work is seen in the aTbRef TBX notes relating to export texts to make the text ‘^value()^’ render as such on export as opposed to as evaluated export code I have to write it with double carets as ‘^^value()^^’, this being the method of escaping a caret in $Text exported via the ^text^ code.

Ya, thanks for that. This exercise has been enlightening and fun. Learned a lot about Tinderbox. @PaulWalters’s Text Soap suggestion I think is an awesome solution for the code work.

2 Likes

On the question of embedded images in Preview:

It’s tricky, but I figured out how to do it last night. Actual implementation might take a while, but I think it can be done.

3 Likes

Sweet!!! :slight_smile: