Simple Pandoc Template

@satikusala, thank you very much for bringing up all these important details that I left out. It also reminded me that I left out a crucial step: for the export stamp to work, one has to download the applescript and point the correct location at the TbxConfig note.

Thanks. Download from where? I don’t see it on your github? What does the script do?

I added it to the first post :wink:

Oh, I see, it is the script to export children individually. It is in your TBX. Missed that. Thanks.

1 Like

Hi! Thanks @Bernard-0 , the template you provided seems to be exactly what I was looking for, the easy way to export my notes to markdown files whenever I want. BUT as I am not a programmer and my skills in computer science field are very limited, I don’t really know how to make your template work :confused: . Thanks to @satikusala guide (BTW, I love your TBX tutorials!) I managed to install home-brew and Pandoc but I’ve got lost after copying stamp to my tinderbox project… Would anyone be so kind to explain in plain English what next steps I should take to make it work? What exactly I should do with provided template to export my individual notes into markdown files?
I’m new to Tinderbox (using it merely for about 2-3 months) and still struggling with its more complex functions, but seeing its potential keeps me motivated to learn more about it :slight_smile:
Thanks! :blush:

2 Likes

These are great! Thanks for the great explanations!

@ShiJianhui if you’re writing in “rich text” in Tinderbox and just looking for an easy way to export to Markdown files (and don’t currently need the other Pandoc options nicely demonstrated in this thread) then you may find it convenient to use the short AppleScript posted and explained here .

Script repeated here (improved by ideas from this thread, e.g. "borrowed" idea to use `touch`)
-- Have an export folder ready. Select Tinderbox notes and run. 
-- Assumes Pandoc is installed at /usr/local/bin/. See https://pandoc.org/installing.html
-- NB: overwrites any like-named .md files in that folder

set prefix to "@" -- character(s) used to distinguish internal links from external ones

set pandocCmd to "/usr/local/bin/pandoc -f html -t markdown_mmd" -- html to MultiMarkdown
set sedCmd to "sed -E 's/" & prefix & "(\\[.+\\]).+\\)/[\\1]/g;t'" -- grab anchor, surround by [[ ]]
set cmdStr to pandocCmd & " | " & sedCmd -- assemble the "pipe"

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

tell front document of application "Tinderbox 8"
	repeat with aNote in selections
		tell aNote
			set theFilePath to POSIX path of theFolder & (value of attribute "Name") & ".md" -- name file after note
			set theHTML to evaluate with "exportedString(this,$HTMLExportTemplate)"
			set theMMD to do shell script "echo " & quoted form of theHTML & " | " & cmdStr
			do shell script "touch " & quoted form of theFilePath -- create file if doesn't exist
			do shell script "echo " & quoted form of theMMD & "> " & quoted form of theFilePath -- write to file
		end tell
	end repeat
end tell

Virtually no assembly is required within Tinderbox. Add the default export template at File > Built-in Templates > HTML, then select Tinderbox notes you want, and click run.

3 Likes

@sumnerg Thanks a lot, the solution you provided is perfect for my needs! :relaxed:

1 Like

There is a key insight in this thread: there are many ways to export (i.e. publish) your data out of Tinderbox.

As with anything your output is dependent on your input, and both have a relationship with your short-term along-term intentions and goals. Are you simply taking notes? Are you writing short-form content? Writing long-form content? Do you need stylized content? In preview or just for ouput? Outlines? Is your work academic in nature, and need footnotes and references? Do you need map visuals, or will the outline suffice? Are you developing a solution of interrelated notes, like an industry map, where links and associations are important, as well as attributes to help manage the relationship between notes. All the choices you make in to address these work efforts will influence how you use Tinderbox. The beauty of Tinderbox, however, is in its flexibility. You can go down one path and simply pivot to another with relative ease.

You can use basic export templates to publish your work

If you’re looking to get markdown out, you don’t need an AppleScript. If you want MD to HTML then apply the HTML template to your MD note and Tinderbox will conver it. If you want MD to MD then apply a text template for your export*.

You can mix templates.

You can enhance templates with action code to transform your content on the fly.

You can work with utilities like Pandoc and Applescript to auotmagically transform your data.

Again, what you do depends on your immediate and long-term needs and your general skill level with Tinderbox and other utilities, like Applescript.

*##Example of exporting markdown out of tinderbox
See the attached example.

  1. Witere you note in Markdown
  2. Apply the markdown prototype
  3. Apply a template that only has # ^value($Name)^ and ^value($Text)^ in it (see tMarkdown in the attahced).

TBX L - Working with Markdown in Tinderbox.tbx (96.5 KB)

If you want to export your markdown out as HTML, then apply the HTML template to your note.

3 Likes

Basic export templates easily handle Markdown → HTML, and Markdown → Markdown. Thanks for the clarifying examples.

But I’ve found RTF → Markdown (writing “normally” in Tinderbox then exporting to Markdown files) more complicated. You can get easily from RTF → HTML (a traditional strength of Tinderbox). But then you have to go through Pandoc to get to Markdown, and use regex to “fix” note-to-note text links that are rendered with an .html extension even if you specify .md.

A short AppleScript currently seems to be the most efficient way to get from RTF to multiple individual Markdown files, especially if you don’t want to export the entire Tinderbox document. A bonus is that this will work with other Tinderbox documents too. You don’t have to configure each new document.

I looking forward to working through and trying to absorb all the great material upthread. Thanks!

3 Likes

This can be done, but nice built-in support is coming.

7 Likes

Thanks @satikusala for this explanation! It let me have a better understanding of how Tinderbox works! The solution @sumnerg provided is the best for my needs i.e. “writing “normally” in Tinderbox then exporting to Markdown files”. I like to have notes written in RTF, but sometimes when I’m not on my desktop, I want to be able to access and edit my notes with an iPad.

You bet! You can do RTF to Markdown too, but it is a bit more tedious. As noted above, it looks like @eastgate will be a better solution for us in TBX 9.

2 Likes

Just updated the template. Now there is practically no setup to do. Just download and enjoy.

1 Like

Thank you Bernard-o. Is the Github version also updated?

Tom

Not yet! I will update it shortly. :wink:

EDIT: done.

1 Like

Very cool…you’ve got a lot of cool stuff going on here wit RegEx. :slight_smile:
BTW, question for you, do you have any idea on how to set the PDF export in pandoc to create a one-page PDF, like DevonThink can do? I want to be able to create a PDF of exported TBX files without there being a page break in the middle of the PDF file.

Hey Michel, the conversion to PDF in Pandoc can happen by two different mechanisms: HTML and LaTeX. So it all depends on what you are trying to accomplish and by what means. If you are trying with LaTeX, perhaps you could try changing the document class:

-V documentclass:report

or

-V documentclass:article

For more info, see this and this.

And you could remove headers and footers:

-V pagestyle:empty

Latex can be a pain if you still don’t know your way around it, but this could get you started. HTML could be easier, of course, since you know your way around it. Just check Pandoc’s documentation for more info on this method (I never use it).

Hi Bernardo
Pandoc NEWbie
Downloaded your Simple Pandoc Template…works great (.md->.docx) for new files created within the document. 2 questions

  1. How do I create a pdf (my preference would be a one-pager as Michael has described.
  2. When I drag my files into the app, I do not get the conversion, only .md. (NB: I changed the Template to PandocPreview but that does not seem to fix it.

Thoughts and many thanks for your Pandoc work!
Tom

Tom, I don’t understand this. Which app are you talking about?

The simple Pandoc Template v 0.2.tbx Simple Pandoc Template 02.tbx (488.2 KB)

Creating new files work perfectly. If I drag a note from another Tbx document into the file, it creates the .md file but not the .docx

I am certain I probably am doing something wrong. I am using the PandocPreview as my HTMLExportTemplate

Hope that helps
Tom