fletcher / MultiMarkdown-5

Reference implementation of MultiMarkdown; replaces MultiMarkdown v4 (deprecated -- see MMD-6 instead)
https://github.com/fletcher/MultiMarkdown-6
Other
294 stars 46 forks source link

{{TOC}} in individual file and File transclusion will render all of them #23

Closed ickc closed 8 years ago

ickc commented 8 years ago

Because of how {{TOC}} is treated, putting it in each individual files will result in multiple TOC in the master file. I'm not sure if there's any workaround by pure MultiMarkdown, if a TOC is required for each files---individual or the master that includes them.

A suggestion is to add an alternative way to add a TOC: by metadata front matter. Put there, file transclusion will exclude it. This loses the flexibility to the location and the title of TOC. For the location, the old syntax can be used if file transclusion is not needed. For the title, a syntax like this in the metadata front matter block:

toc: true
toc-title: Fancy TOC Title

could work.

The 2 names are directly borrowed from Pandoc - Pandoc User’s Guide.

fletcher commented 8 years ago

The problem is that it's not clear where the TOC should be placed. That's why I use the {{TOC}} approach instead of metadata.

You could have the TOC command itself in a transcluded file, and then use different transclude base folders for the master vs child files. This isn't a great workaround, but it should work if done properly.

I'll think about other approaches for the future as well.

ickc commented 8 years ago

I see.

I am just brainstorming on possible ways it can be done in the future:

Solution 1: Only first {{TOC}} is rendered

This solved the file transclusion problem (assuming the {{TOC}} in the master file appears first), and also shouldn't break backward compatibility much (most probably people aren't putting 2 TOCs at 2 locations...?).

Solution 2: Added a TOC metadata field while the current {{TOC}} syntax persists

So TOC metadata and {{TOC}} are both optional, that means 4 combinations (or 3 if nothing doesn't count).

  1. If only {{TOC}} is used, the current behavior is assumed. i.e. only a bare TOC is rendered at that location.
  2. If both are used, then the {{TOC}} only represents the location (e.g. after Title and abstracts) and the metadata controls the "sensible defaults".
  3. If only the metadata is used, then sensible defaults is used (I personally added a **Contents** before the {{TOC}}) and the TOC is put at the beginning.

Optionally, the TOC metadata can be accompanied with other metadata fields (e.g. toc_title) to control the "sensible defaults".