HTMLPreviewCommand and templates - can I get HTML preview, and markdown source?

I am trying to create a document that will let me:

  1. Write in rich text
  2. Construct markdown pages
  3. Preview the rendered HTML
  4. Copy / export the markdown source

I can’t seem to figure out the right combination of HTML* attributes. Basically I can have either 3 or 4, but not both.

So given this note:

image

and this template:

image

I hope to produce this preview:

image

and this HTML:

image

The problem

The problem seems to be that when HTMLExportCommand is enabled, Tinderbox processes ^text^ through the preview command before passing the text off to the template. So my preview is a mixture of unprocessed template code, and the processed note:

image

the HTML shows the same mixture:

image

Disabling HTMLPreviewCommand correctly constructs the HTML that I want, but of course it doesn’t run it through a processor for the preview pane.

What I want

I want the HTML pane to show the result of the note run through the template - not processed by the HTMLPreviewCommand.

I want the Preview pane to show the above text, but piped through the HTMLPreviewCommand.

Is that possible? I’ve attached a demo file if that’s helpful.

rich mark.tbx (89.3 KB)

1 Like

I haven’t quite cracked it (and I don’t even know if it’s possible), but I have come up with something workable for the time being. I would love it if anyone could share a way to have the preview and HTML work the way I want. But here’s my current solution that’s a few more steps.

Basically it involves creating a separate template, which renders the note using the Markdown page template, and passes the result through to the Markdown prototype’s HTMLPreviewCommand. Then I have stamps to switch between Preview and Export modes - Preview mode sets the HTMLExportTemplate to Processed markdown, and Export mode sets it to Markdown page. I have a third stamp that copies the markdown source to the clipboard, regardless of the mode.

Processed markdown template

^value(runCommand($HTMLPreviewCommand("/System/Prototypes/Markdown"), exportedString(current, "/System/Templates/Markdown page")))^

Preview mode

$HTMLExportTemplate("/System/Prototypes/Note") = "/System/Templates/Processed markdown";

Export mode

$HTMLExportTemplate("/System/Prototypes/Note") = "/System/Templates/Markdown page";

Copy markdown

runCommand("pbcopy", exportedString(current, "/System/Templates/Markdown page"))

rich mark.tbx (120.0 KB)

This seems very complicated.

Are you just trying to write in Rich Text and export as Markdown? I’m not sure what benefit the Preview step has to that process.

Why not write in Markdown?

Anyway, you might try this as the $HTMLExportCommand instead of fiddling with templates:

textutil -stdin -convert html  -stdout | pandoc --from=html --to=markdown

Converts the RTF to HTML then the HTML to markdown using Pandoc.

Yes. With the added twist that I’m using templates to construct Markdown pages from one or more notes.

It lets me see what the resulting page will look like in a browser.

In Tinderbox, I prefer to write using rich text. It’s visual, and the links are clickable.

Interesting. Does this produce an HTML-formatted preview in the Preview pane, and Markdown in the HTML pane?

Instead of ^text^ try ^value($Text)^.

In your prototype (not in the template) try setups such as:

If you have links in your rich text there is no built in command to format the tags in the output as markdown links ([...](...)).

If the ultimate goal is to produce a web page, what’s the advantage of going via Markdown rather than just generating HTML directly from Tinderbox?

If your plan is to feed the Markdown output to another tool to generate the HTML, maybe a better solution is to use that tool for the preview?

(Removed to better thread my reply)

Noting Tinderbox’s text area is an RTF writing space, Markdown is a form of plain-text mark-up basically helps those who like to write in plain text to generate HTML (sung a Markdown . In terms of your questions here and in other current threads, I’d suggest that Markdown is a distraction to your goal.

People’s tastes vary. If you don’t know what Markdown is, I’d genuinely suggest ignoring it for now as it won’t help you at this point. Markdown is generally more use for generating HTML from plain text using inline mark-up. If unclear on HTML, Markdown is likely not a way into understanding it. I’d focus on getting a good working grasp of basic HTML export before worrying about niche HTML generation techniques.

. Markdown users please don’t be enraged. If you like and know it, use it, but for those still getting to grips with HTML it is an extra layer of confusion (as Tinderbox is not a Markdown-centric editor—plenty of which exist). The above comment is not a judgment upon Markdown as a concept, but the complexity it adds for someone still understanding HTML basics), and how they relate to Tinderbox HTML export.

1 Like

Just to be precise, it’s not actually an RTF writing space. But the internal format happens to be stored as RTFD.

1 Like

Sure. But from a user’s perspective, especially one without a code/tech background, it is ‘rich text’ or ‘styled text’ if one prefers. In the context of my post the RTF vs. RTFD is moot.

Markdown is described as " a lightweight markup language for creating formatted text using a plain-text editor" (as per Wikipedia). My point is that Markdown (by intent) turns Tinderbox’s default behaviour on its head, allowing creation of styled HTML text (as if) from a plain text setting. For a user just trying to grok the basics of Tinderbox’s build-in method of HTML export, Markdown is thus a distraction to the task at hand.

. Which is fine if that is what the user wants, as some do. However, I’d not suggest someone new to HTML and HTML export to start with Markdown as it is a further layer of encoding about which to become confused. Not all users need to use all features. Not using a feature does not mean it is any less useful for those who do use it (before someone rushes in to say how much they use Markdown).

tl;dr - I want the HTML pane to show me the markdown output produced by my template, and I want the Preview pane to show me the rendered result after it passes through a markdown-to-html processor. If anybody knows how to do that without switching back and forth between export templates, I would love to hear how :slight_smile:

The main reason to generate Markdown is because it is a lightweight, portable format for representing information online. Most of the online tools I use work with markdown: my email client (MailMate), blog engine (Jekyll), GitHub, Pivotal Tracker, even certain forum software :wink: Additionally, when committing to version control, markdown makes for much leaner, readable commit diffs.

Sure, and that’s what I’ve been doing. I don’t know if it’s easier, particularly when I don’t know exactly which tool is going to be the final destination. What I do know is that markdown is the destination format. I have three ways of working with this right now: 1) my preview / export switch 2) export to the tool and preview there 3) copy the markdown and preview anywhere I want.

I would like to use Tinderbox as a spot check without using another tool, which is why I developed method 1 above. If I could achieve that same result without running stamps to switch between the modes, that would be great - and that’s honestly the only thing I’m asking about with this thread, I believe I have the rest figured out.

I suspect this is an attempt to keep @kderbyshire on the path she’s on as expressed in other threads, and not get distracted with what I’m up to here.

To be clear about my situation: I am very comfortable with markdown, HTML, and HTML export from Tinderbox - and generating Markdown is one of the key objectives here. Essentially I’ve built a dashboard for producing Markdown that I can feed into any of the several tools I use that support it.

For the last ~15 years, I have done almost all of my writing in Textile / Markdown using plain-text editors. When trying off-the-shelf writing tools, I’ve leaned toward Ulysses over Scrivener because it supports Markdown (PLEASE don’t provide Markdown-with-Scrivener links, I’ve read them all and it’s brutal :slight_smile: ). I enjoy using Markdown in Markdown-aware editors, which Tinderbox is not (nor does it need to be). Plus I’ve surprised myself by how much I enjoy writing in rich text, comfortable knowing that the content will be exported to Markdown. It’s similar to using Ulysses or Agenda or any other editor that visually displays as rich text, but encodes as Markdown under the hood.

Tinderbox is unbeatable as a writing environment for my purposes. I’ve spent plenty of time with Ulysses, Scrivener, and pretty much any other writing environment that I’ve heard come up over the years. In the end, I always prefer markdown files in a text editor. But Tinderbox has some killer features that you just can’t get anywhere else, and would be prohibitively costly for me to build myself (believe me, I’ve started down that path multiple times). Metadata, agents, visualization… and LINKS. For a community built around a hypertext tool, I’m surprised at how many of the suggestions implicitly include abandoning Tinderbox’s link mechanism - which is what happens when you just write in Markdown.

Anyway, I think that’s enough procrastination / self-justification for one day. At least I’ve added another data point to @mwra’s understanding that no two Tinderbox users are quite alike :slight_smile:

1 Like

If so, no need. I was asking out of general interest, not because of applicability to my own projects.

I am also using export templates to generate markdown which I would like to see in the preview pane. Just was searching the forum for the same problem, but couldn’t find an answer. @pat Did you found a solution for this?

I don’t think you need to switch between templates, but turn off the Markdown post-processing script.

Then again, you won’t get the web preview as you won’t yet have HTML for the preview to render.

Even if one is only using Markdown, it is important to remember that despite the ‘HTML Export’ origins, users use the export method to generate all sorts of formats.

The preview started about a a means to check the output form complex templates (i.e. lots of includes, etc.) without having to export and test in a web browser. The fact that the preview can show Markdown pages is not because it is using MD code but because it uses an internal (or user-set external) Markdown-to-HTML script and it is the output of the latter that is shown.

So without re-architecting everything just for Markdown use, it seems a (the?) solution might be tick-box control (on the Export Inspector perhaps) to suppress the running of the final script. With that off the ‘HTML’ pane would show MD (though obviously no preview) and with it on the pane would show the HTML and thus enable a prevew in the preview pane.

I realise one could just delete/reset the value $HTMLPreviewCommand but that is a string liable to re-keying error is (re-setting) manually. Plus, mark-up methods come an go. Markdown is popular now, but like as not there will be something newer/better/cooler come along to replace it. So a method that supports differing types of HTML-generator mark-ups makes more sense than engineering specifically for one mark-up system which is not universally used. It may be heavily used by those who do, but plenty more Tinderbox users will never have heard of it.

1 Like

This is my solution: HTMLPreviewCommand and templates - can I get HTML preview, and markdown source? - #2 by pat

1 Like