Export children as separate file

Is there a way to export children of a single container as separate files. I know you can do this for the entire document with export HTML. What I want to do is select a single container and export its children as separate files. Is there an attribute that I can check to do this?

The simplest way to understand this is that by default, Tinderbox is set up to (HTML) export the whole document (bar a few special things like the prototypes container). In fact the latter is done using the same attribute $HTMLDontExport. If ticked, that note doesn’t export.

A separate control is $HTMLExportChildren. If un-ticked that note will not export its children, ergo its descendants. If the parent is set not to export, but allows its children to do so, the parent emits a container but no note - this is necessary given the outline based nature of the export.

Tinderbox does allow you to export the current note but for HTML export it is that or the whole file - or rather those parts you haven’t modified to not export. I think what you’re presuming, and which does not exist is a method to export the current branch: i.e. the current notes and all its (exportable) descendants. At present that would be a feature request for someone to make.

Otherwise a stamp to toggle $HTMLDontExport and $HTMLExportChildren appropriately for all the outline branches that currently export but which you want to suppress. After the export or at al later date you can reverse the toggle. This will result in a File → Export → HTML exporting just the (outline) branch desired.

For my own needs, I am using something along these lines:

var theText;

if($ChildCount >= 1){theText = $Text + "\n\n" + $Text(children).replace(";","\n\n")};

This is, of course, part of a larger script. :wink:

1 Like

If you use ^children(templateName)^ you don’t need the conditional to . Just make a new export template with two line-break and then the code ^text^ then save and use that template as the templateName argument.

You can do the same via minor modification to the default HTML template’s nested HTML-item template.

The other point is the code above is taking the plain text of the note(s) whereas for export, only ^text^ does the HTML parsing: ^value($Text)^ inserts the raw text.

If you’re going down the Markdown route then the difference is moot.

I don’t understand. How will this method save each child as an individual file?

Yep. I am deliberately avoiding the ExportedString(this, Export Template) method. This would convert the markdown text to HTML, but plain markdown is preferable for the Pandoc conversion that will follow.

BTW, @mwra, would it be possible to use a stamp to gather the text of the selected notes so that I could export all of them as a single file? I am not sure if this would be possible without triggering the export action for each of them individually.

I was responding to @Bernard-0’s last post! :slight_smile:

Yes, but you may end up with a very big note which may choke Tinderbox. FWIW, I think as an experiment I exported all of the main aTbREf TBX content as a single HTML file without problem. But note a thread just yesterday(?) - don’t use the Preview pane with such big single notes - it has a limit that will be fixed for v9 release.

As regards the stamp, yes. You’ll need to work out code that finds all necessary notes, sorted in the correct order and then you can concatenate the list and (stamp) insert the overall string as the text of your root export note or on the end of its text if it has some.

The best way to take this forward is with a smallish doc with sample notes, say 10-20, in an out/line reflecting your main doc and then experiment. Once you’re getting the desired result, move the code to your actual work doc and try (on a copy!).

1 Like

@satikusala, the template I shared with you the other day will do this. All you have to do is select the notes you want to export and apply the stamp. If you prefer to just select the parent and export each child individually I think it would be easy to adapt it to do just that.

Really? I don’t see how. When I look at the script it seems to be exporting only the consolidated parent/child file.

Maybe you can show me later. I think I’m missing something.

I’ve had good luck using AppleScript to export selected notes rather than the whole document.

See this for Markdown export (where you’re writing in the usual rich text but want to export to Markdown).

Export of selected notes to individual .html files can be as simple as this:

See short script here
-- Have an export folder ready. Select Tinderbox notes and run. 
-- NB: overwrites any like-named files in that folder

set theFolder to (choose folder with prompt "Choose a folder to receive the exported files")

tell front document of application "Tinderbox 8"
	repeat with aNote in selections
		tell aNote
			set theFilePath to theFolder & (value of attribute "Name") & ".html"
			set theExportedString to evaluate with "exportedString(this,$HTMLExportTemplate)"
			my writeTextToFile(theExportedString, theFilePath)
		end tell
	end repeat
end tell

on writeTextToFile(theText, theFilePath)
	set theFilePath to theFilePath as string -- file path must be string
	set theOpenedFile to open for access file theFilePath with write permission
	set eof of theOpenedFile to 0 -- will overwrite like named existing file
	write theText to theOpenedFile starting at eof as «class utf8»
	close access theOpenedFile
end writeTextToFile

If instead of selecting the notes within the container you select the container itself and run the script, then (assuming your templates are set up) you should get one “consolidated” file.

So you can easily have it both ways, without having to toggle and so forth.

2 Likes

Wow, this works great. I still think it would be nice to have a menu item in the app (will ask the developer in the backend for a feature request), but this works. :slight_smile: Thanks.

@TomD, this should do the trick for you.