SEP: Store quoted content within the source table
Currently, when I quote a piece of text, it lives fully contained in it’s own document. If I want to write some commentary about it or note down some related references, I create a second note which transcludes the quote and write in that. This works, and the separation of concerns appeals to me, but it creates just enough friction that I’m much less likely to write any commentary for most things I quote.
I’m proposing that rather than occupying the content["plain"]
of a document, a quote reference should instead live in the source
table, perhaps as source["text"]
?
source["content"]["plain"]
would be the most appropriate, but nested tables in TOML are frustratingly verbose so I’m not sure (maybe I need YAML after all?).
Example TOML for that:
...
[source]
title = "The Ten Commandments"
character = "Sephora (Anne Baxter)"
year = 1956
timestamp = "02:02:07"
[source.content]
plain = """
Nothing from some, is more than gold from others.
"""
...
The current special case handling of multi-line and literal multi-line strings won’t scale to having many per document, so now would be a good time to solve for that.
It looks like the tomlkit library preserved multi-line strings by default, which would obviate the need for any special handling.
Discovered by outsourcing the hunt to Perplexity, which returned the following when asked Is there a python TOML library that can read and write TOML multiline strings without converting them to normal strings? followed by Show me an example output of tomlkit if printing a multiline string to a file:
Using the tomlkit library, you can easily write a multiline string to a TOML file while preserving its formatting. Below is an example demonstrating how to create a TOML document with a multiline string and then write it to a file.
#python
from pathlib import Path
import tomlkit
# Create a new TOML document
doc = tomlkit.document()
# Add a comment and a title
doc.add(tomlkit.comment("This is a TOML document."))
doc.add(tomlkit.nl()) # Adds a newline for better formatting
doc.add("title", "TOML Example")
# Add a multiline string
multiline_string = tomlkit.multi_line_string("""
Hello,
World!
This is a multiline string.
""")
doc.add("greeting", multiline_string)
# Specify the path to the output file
output_file_path = Path("output.toml")
# Write the TOML document to a file
with output_file_path.open("w") as fout:
fout.write(tomlkit.dumps(doc))
print(f"TOML document written to {output_file_path}")
If adopted, this would allow for more streamlined ‘quote blogging’, similar to Simon Willison (see example). I will have to give some thought to how I want to present the quotes page though, now that there is more than just quotes involved.