Custom Placeholders and Metadata (for a fictional magazine)

Hello everyone!

Inspired by an answer from @nontroppo in a previous thread of mine, I’m trying out something new, but I don’t know if it’d work. I’ll go more in-depth below.

What I’m Planning to Do

Just for fun, I’m using a Python script pipeline (that I’ve vibecoded myself) to create a fictional magazine (Rutan = Swedish for telly or screen) inspired by Radio Times. [1] The issue creator script is interactive, but I’ve thought about using Scrivener to create the issues (which would double my work speed) and then compile them into a .txt file so that the script can import it.

I’m using PrinceXML and CSS for styling too.

Ideas I’ve had to make this work

So yesterday I googled some stuff and arrived at this possible section layout:

Title: <$title>
Duration: <$custom:ProgramDuration>
Genre: <$custom:ProgramGenre>
Description: <$synopsis>

Is the layout above doable in Compile? If not, could someone point me towards some way of making this work?


  1. Basically, if SVT had gone even further with its “let’s model the BBC, guys.” idea and created their own listings magazine. ↩︎

In general, markdown metadata is specified per-project (one metadata block at the top of a single document[1]), not per section. Scrivener compiles to a single document, so if you want section-specific metadata this must be transformed into some intermediate markup and a custom filter could then use this when converting to HTML.

A simple solution is that section titles can contain attributes, and these attributes should make it to HTML and thus can be used. Scrivener would generate something like:

# Title {#id .class foo='bar'}

Text.

making:

<h1 class="class" data-foo="bar" id="id">Title</h1>
<p>Text</p>

The attributes can then be used by JS and CSS: Use data attributes - HTML | MDN

In this case the compiler section format can inject section metadata into the title attributes for that section.

Or you can use the compile format to inject custom “final” html elements with the section-metadata at the top of that section (after the title). There are many ways to cut this cake, as is usually the case for Scrivener / Markdown workflows.


  1. if there is more than one metadata block in a document, they are combined together ↩︎

2 Likes

So, how would I go about doing this? Compiling to HTML?

One thing to watch out for, with custom metadata in the Section Layout, is this open bug in the Windows version. Looking at my notes on the matter, it looks like if you use the Prefix tab instead of the title fields, you should be fine, and as I note in the thread, that’s a more natural place to put this kind of stuff anyway.

Just do make sure to clear out the Metadata fields from the main compile overview tab, otherwise you’ll get doubled up metadata blocks, as it isn’t programmed to detect anything from the section layouts.

2 Likes

I found a way to do this using custom metadata and document templates and avoiding the Metadata checkbox. I compiled a test into.txt format, and it works fine, as demonstrated below:

Title: Rapport

Duration: 10

Description: Swedish news delivered in a quick and concise report. Presented by Linnea Bergman.

@AmberV Is my poking around above correct?

Here is a thread on this matter in particular, which may help. As you say, the Metadata checkbox itself is not terribly useful for this.

Speaking strictly of formatting, you do need the three dashes on a line above and below, like Scrivener would normally put into the .md file. I think empty lines within this block are okay, but I’d keep each row adjacent to be safe, like so:

---
Title: value
Duration: value
Description: value
---

MMD + post-processing in Pandoc, you can go to HTML or PDF via PrinceXML directly. I can make s simple project for you, but the principle is the same as my Quarto sample workflow:

This example shows a section with custom metadata in the Inspector: ID, Class, Attributes etc. and in the compile format prefix there is Scrivener placeholders to generate markdown :::{ attributes } – a pandoc custom div. In your case you could make a custom div or use prefix (as @AmberV mentions for the windows bug) to make a title + attributes.

2 Likes

I have a Python script that creates an HTML file and a CSS file based on a JSON file. I’m automating the creation of the actual issue using Scrivener. The idea is to import TXT files, get a JSON and then turn that into a PDF using Prince.

I do plan to move towards Typst in the near future (either when I have a new Mac/mine is fixed, or when Scrivener for Windows gains a scripting window in its Post-Processing).

Ah okay, I thought you were aiming for a Pandoc YAML metadata block. If not, disregard the above notes on formatting.

As an aside, I made a compile Format for producing JSON straight out of the compiler, that might be helpful, or more straight-forward than creating an intermediary .txt and then making a script to process that into JSON.

2 Likes

I made the script before I tried to automate it using Scrivener.

If you’d like, Amber/Ioa, I can send over the vibecoded scripts, and we can try to figure something out.

Oh I knew some Python many (many) years ago, but probably don’t know enough about it, that isn’t obsolete, to offer any useful advice. :slight_smile:

1 Like

I can send the JSON then.