Scrivener → Squarto

SQUARTO DEVELOPMENT LOG | 2025-01-20:

Things are going pretty well with Squarto development. It works seamlessly from the command line. And it works as a post-processor for Scrivener’s Compile step (although reliant on a Keyboard Maestro macro since Scrivener lacks a way to pass the path for the source .scriv project file in the Compiler). I continue with refactoring to make it better!

Binder functionality:
- Use the Binder as the visual control for parts/chapters/appendices
- Parse the .scrivx file to capture the Binder structure in code
- Create Quarto folder/file hierarchy based on Binder structure
- Use slugified version of Binder title to create filename.qmd.
- Dynamically populate _quarto.yml with the folder/file pathnames for a Book
- Bugfix for squarto.processing.binder.generate_yaml_for_chapters_parts_appendices
- Fix binder.print_tree to accommodate various Scrivener Binder structures
- Add binder.print_table
- Add binder.print_raw

Extracting content (the original DIY way):
(Tested, but abandoned in favor of parsing the Scrivener-compiled .md file)
- Navigate the /Files/Data directory to find content.rtf, content.styles, etc.
- Convert .rtf > plaintext (for .qmd) using Pandoc (doesn’t handle unicode/Emoji)
- Convert .rtf > plaintext (for .qmd) using my own converter (doesn’t handle unicode well)
- Convert .rtf > plaintext (for .qmd) using TextUtil (handles unicode/Emoji well)
- Postprocess the plaintext to convert Scrivener styles to Markdown

Extracting content (using the Scrivener-Compiled .md):
- Have Scrivener compile a single, aggregated .md file with all Style substitutions
- Use Section Type and Section Layout (with Title Prefix) to add a delimiter before each chapter
- Fix the auto-assignment bug in Compiler: For some reason, Structure-Based auto-assigns nested text documents as “Chapter” instead of “Sub-section”, even though correctly defined in Project Settings.
- Collate nested text documents into a single chapter (using Section Type and Section Layout).
- Parse the compiled .md file into separate snippets for each chapter.
- Save snippet (content) into the corresponding file.
- Add proof-check for compiled_md_file that if no content is found for an empty document (when it is present in the Binder but is empty), then a file will be created containing the Title as the header and maybe a line that says “This document was empty”. Catch this in the step where the compiled_md_file is being processed.
- Refactor content_files code to use binder.items object

Images, tables, links, etc.:
- Process figures/images that are stored in the Binder
- Process figures/images that are embedded (cut-n-pasted) into one of the text documents
- Work on using internal links within the Scrivener file (for example, to an image) becoming a valid Markdown link to the file in /figures.

Quarto:
- Confirmed that quarto preview and quarto render generate .html web site
- Confirmed that quarto render generates a good .pdf file
- Store the _extensions, _fonts, references.bib, etc., in the Binder and export that to the Quarto directory alongside the other files.

CLI/TUI:
- Refactor Squarto as an installable package that can be imported into other programs
- Refactor Squarto into a CLI program
- Set up Squarto TUI

Scrivener:
- Set up the Scrivener format settings so that File > Compile runs Squarto as a post-processing script (cf. this thread)
- Create Keyboard Maestro (KM) macro to facilitate obtaining .scriv project file path for the processing script.

2 Likes