Tinderbox Forum

How to transclude child notes with the Markdown Preview Template

Hello,
I’m very much enjoying the new “preview” functionality in 9, and especially happy to see how easy it is to drop in some css and a pandoc command and get my Markdown writing in a very near final format with footnotes and bibliography displaying quite well. Amazing.

One thing that I’m struggling with however is “transcluding” child notes in the Markdown preview so as to achieve a view of a whole document in the Preview pane. It helps me to see how the document is shaping up.

For instance, imagine I have a document entitled “Paper”, with 3 sections, Sec. 1, Sec. 2, and Sec. 3.
I’d like to be able to see a complete version of Paper with all 3 sections and a final bibliography rendered in the preview. I’m able right now to see each of the Sections this way, each with their own bibliographies rendered in pandoc (which isn’t bad by any stretch of the imagination!)

I see that the export template found in “Hints\Preview\template” seems as if it should be easy to manipulate, but I’m not having much success at achieving what I’m after which should be to gather the text of the children of “Paper” (i.e. the three sections) and then have them stand in the place of the

<body> ^text^ </body> in this “Hints\Preview\template”. I feel as if I’m very close, but for some reason, close isn’t good enough this time. :slight_smile:

Thanks very much.

Yours,
Maurice

Hello Again,
I decided to place export code in the body of the parent note, and concatenate the strings of text from the sections (child notes) by grabbing their text.

^action($MyString= $Text(child[0]));^value($MyString.format)^;

This almost works.

The flies in the ointment are the two semicolons leading and trailing which make it impossible for the item to render properly in markdown:

;## Title 

  As the progenitor of this form, the tales feature the fictional exploits of x, a notorious rogue who travels across the cities of the ME. Many of these tales turn upon a moment of recognition/anagnoresis in which the narrator of the tales.;

(The trailing semicolon comes at the end of a paragraph in Markdown).

How do I go about deleting these unwanted semicolons? They inhibit the pandoc markdown from registering the level 2 header. Incidentally, why are they appearing?

Thanks very much if anyone can explain to me what to do now.

Thanks very much,
Maurice

Bear in mind that the built-in Markdown template is a generic template for preview use by every note in a document, unless the document has one or more existing (HTML) templates. In the latter case documents default to using the first added template. The internal template cannot be manually applied. so, if you emend your internal template specifically for one note, all other notes will preview using the exactly the same code.

Testing, I don’t think the built-in preview template (a special case, as described above) allows normal inclusion codes like ^include()^ or ^children()^.

That doesn’t make sense. I think you may mean:

^action($MyString = $Text(child[0]))^^value($MyString.format)^

That likely explains the semicolon issue. ^action()^ _contains_ action code, so semicolons are used between expressions inside ^action()^ but not outside it, where they are treated as literal characters in the template and thus the semicolons you see on screen.

Note that $MyString.format does nothing and us the same as $MyString. the .format() command is not used with String-type data. Also, the designator child[0] is he same as child i.e. the first child note.

So, closer to your solution, I think, is this:

^action($MyString = "<p>" + (collect(children,$Text).format("</p><p>")) + "</p>")^
<html>
<head>
    <style> ^value($Text(/Hints/Preview/style))^ </style>
</head>
<body> ^text^ 
^value($MyString)^
</body>
</html>

Which gives me a result like this for a container with 3 children:

Here’s my test file used for my answer above: Internal-template.tbx (93.4 KB)

Dear Mark,
Thanks so much for the prompt and informative reply. This almost works! While the example you give certainly does the trick with short uncomplicated bits of plain text/markdown, longer strings like the sections of papers that I’m transcluding, end up being wrapped in quotation marks, like so:

“## Section 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Egestas egestas fringilla phasellus faucibus scelerisque eleifend donec. Turpis tincidunt id aliquet risus feugiat in ante. Pharetra diam sit amet nisl suscipit adipiscing bibendum est. Natoque penatibus et magnis dis parturient montes nascetur ridiculus. Et malesuada fames ac turpis egestas sed tempus urna. Cursus euismod quis viverra nibh cras pulvinar. Arcu risus quis varius quam quisque id diam vel quam. Gravida arcu ac tortor dignissim convallis aenean et tortor. Eros in cursus turpis massa tincidunt dui ut ornare lectus.”

I’m guessing that this may well be the pandoc interpreter, but I’m not sure. It could also be something about the way I’ve formatted my markdown. Any thoughts on how to iron this last bit out?

Yours,
Maurice

No such problem here. Please post a document showing the problem otherwise we all spand ages typing essays back and forwards. much easier is to see a document showing the problem being reported. :slight_smile:

Hi,
I think I’ve discovered where the problem lies. It’s having parentheses (like this ) in the markdown text.
The subsequent text is then wrapped in quotation marks. See the attached file. Not sure what I should do about this. Already tried backslash escapes, but that didn’t work.

Yours,
Maurice
Internal-template Parentheses Problem.tbx (95.3 KB)