Skip to main content

Python-Markdown extension for parsing Iron Vault journals

Project description

ironvaultmd - Iron Vault Markdown Parser

Quality Gate Status Coverage Security Hotspots Reliability Issues Maintainability Issues Security Issues

A Python-Markdown (GitHub) extension to parse Markdown files from the Iron Vault (GitHub) Obsidian plugin.

The main idea for this extension is to convert Iron Vault Markdown journals into HTML sites for publishing.

Features

Supports at this point

  • parsing ```iron-vault-mechanics ``` blocks
  • collecting frontmatter YAML information into a dictionary
  • regular and labeled wiki-style links, i.e. [[link]] and [[link|label]] (see also below for details)
  • user-definable templates for parsing the supported nodes

Supported mechanics block content

Disclaimer: This extension came into existence for my own purposes, to eventually publish my campaigns.

After old-school pen and paper, and a bunch of other experiments, I eventually gave Iron Vault a try for my Starforged campaign at that time. This was in December 2024, around Iron Vault version 1.88.1.

I have used it for other campaigns and Ironsworn rulesets since, but chances are I'm still missing some parts here or there, and full support for everything cannot be claimed yet. Nor any support for older Iron Vault versions.

Mechanics blocks and nodes

All nodes and blocks within a iron-vault-mechanics block should be supported.

Some have a strict regular expression to match, others support a generic key=value parameter matching, with the latter hopefully covering some more variety in rulesets and Iron Vault versions.

Links

Links are detected and optionally collected into a list with their reference, anchor, and label, see the Collecting Links section below.

Note that no actual linking is performed by default, and links are packed in a <span class="ivm-link"> element insted. This behavior can be changed by providing template files or template overrides for the link element.

Roll results

Roll results of a move are collected, including dice rerolls and burning momentum, and the outcome is added as CSS classes to the enclosing move block.

User-defined templates

Nodes are parsed using the Jinja templating engine. Every supported node has a default template and gets automatically passed all available data to it.

The default templates for each node (and some extra elements) along with a description of the available variables can be found from the templates/ directory .

Each node template can be overridden when initiating the IronVaultExtension. See below for some examples. Setting a template to an empty string ('') will prevent the node from being parsed to HTML altogether.

Installation

pip install ironvaultmd

This will install the required dependencies (markdown, pyyaml, and Jinja2) as well.

Usage within Python code

Quick usage to convert an Iron Vault journal Markdown file to HTML and print it to the terminal:

import markdown
from ironvaultmd import IronVaultExtension

md = markdown.Markdown(extensions=[IronVaultExtension()])

with open("/path/to/ironvault/Journals/JournalEntry.md", "r", encoding="utf-8") as file:
    print(md.convert(file.read()))

Check also the ironparser.py example file for a more complete example to write a given journal Markdown file as HTML file.

Collecting Links

import markdown
from ironvaultmd import IronVaultExtension, Link

my_links: list[Link] = []
md = markdown.Markdown(extensions=[IronVaultExtension(links=my_links)])

with open("/path/to/ironvault/Journals/JournalEntry.md", "r", encoding="utf-8") as file:
    print(md.convert(file.read()))

print(my_links)

Frontmatter

import markdown
from ironvaultmd import IronVaultExtension

my_frontmatter = {}
md = markdown.Markdown(extensions=[IronVaultExtension(frontmatter=my_frontmatter)])

with open("/path/to/ironvault/Journals/JournalEntry.md", "r", encoding="utf-8") as file:
    print(md.convert(file.read()))

print(my_frontmatter)

User Templates

Template Files

If you don't like the package-provided default templates, you can pass your own set of templates to the extension.

To make this work, you'll need a dedicated directory that resembles the default template directory layout:

my-own-templates/
├── blocks
│   ├── actor.html
│   ├── block.html
│   ├── ...
├── link.html
└── nodes
    ├── add.html
    ├── burn.html
    ├── ...

Setting your own template directory:

import markdown
from ironvaultmd import IronVaultExtension

md = markdown.Markdown(extensions=[IronVaultExtension(template_path="my-own-templates/")])

Template Overrides

Template files, both passed as a theme and default package-provided ones, can be overridden for additional flexibility.

This allows to either change the rendered text, by providing an alternative template string that Jinja understands, or completely disable the specific template by setting it to an empty string "".

This is ideal if you're mostly happy with the default templates but want to tweak a thing or two.

import markdown
from ironvaultmd import IronVaultExtension, IronVaultTemplateOverrides

my_overrides = IronVaultTemplateOverrides()
my_overrides.add  = '<div class="my-own-class">Adding {{ add }}</div>'
my_overrides.roll = '<div class="ivm-roll">{{ total }} vs {{ vs1 }} and {{ vs2 }}</div>'
my_overrides.link = '<i>{{ label }}</i>'
my_overrides.xp = '' # don't add xp nodes to HTML output

md = markdown.Markdown(extensions=[IronVaultExtension(template_overrides=my_overrides)])

Note that you can provide both template_path and template_overrides values, and the overrides always take precedence over file-based templates.

Usage with MkDocs

MkDocs is a static site generator that creates HTML pages from Markdown files, using Python-Markdown in the background. Since ironvaultmd is an extension to just that, MkDocs can be used to create HTML pages from Iron Vault Markdown files.

See the MkDocs getting started section about setting it all up.

Adding ironvaultmd support

Add ironvaultmd to your MkDocs project's mkdocs.yml:

markdown_extensions:
  - ironvaultmd:IronVaultExtension

See https://www.mkdocs.org/user-guide/configuration/#markdown_extensions for more information.

Templates

To set a template files directory, modify the mkdocs.yml accordingly:

markdown_extensions:
  - ironvaultmd:IronVaultExtension:
      template_path: "docs/themes/minimal/templates/"

NOTE:

  1. Make sure you have the colon (:) added after ironvaultmd:IronVaultExtension if you add a template_path
  2. The template_path directory must either be relative to the MkDocs project's root directory or an absolute path.
  3. Template overrides are unfortunately not supported

Styles

extra_css:
  - /themes/minimal/styles/layout/minimal.css
  - themes/minimal/styles/colors/muted.css

NOTE:

  1. Unlike the templates directory, the extra_css directory is relative to the MkDocs project's docs/ directory
  2. Because of 1., paths can be with or without leading / as shown above.

See https://www.mkdocs.org/user-guide/configuration/#extra_css for more information.

Developing

See DEVELOPING.md for details on how to set up development environments etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ironvaultmd-0.5.2.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ironvaultmd-0.5.2-py3-none-any.whl (50.2 kB view details)

Uploaded Python 3

File details

Details for the file ironvaultmd-0.5.2.tar.gz.

File metadata

  • Download URL: ironvaultmd-0.5.2.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ironvaultmd-0.5.2.tar.gz
Algorithm Hash digest
SHA256 4fa1ce5d7ca4e665721c62fe6337e6cca4bd4b75090dbeb433d431dd2918fc52
MD5 d4f0d41220886b5d26c076d61561cac1
BLAKE2b-256 95f3a97ed987120d64cecb1ed09eab88f956c3b0fc1f2cf58f6f994a35e3861f

See more details on using hashes here.

File details

Details for the file ironvaultmd-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: ironvaultmd-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 50.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for ironvaultmd-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 301b7e2f439ffdc579acaee545cc83580e3e6a5a0d4500271329288be4ec8852
MD5 e75f2adcaaeebf02675efb3c6a6a1fd5
BLAKE2b-256 6942381e545611ec931ce11d4fa38d97733421428d800a8dcaec7349819ace2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page