Meta-data to control output

This commit is contained in:
Pelle Nilsson 2022-03-24 23:01:47 +01:00
parent 43e094011b
commit f98f3362af
4 changed files with 70 additions and 13 deletions

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 Pelle Nilsson
Copyright (c) 2021-2022 Pelle Nilsson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -86,6 +86,21 @@ documents as part of converting them, but see [Pandoc's User
Guide](https://pandoc.org/MANUAL.html) for information on all the ways you can
add style to the output document.
# Configuration
Pandoc Metadata can be used to configure the output of pangamebook. The
*-M* (or *--metadata*) flag is used for pandoc to add metadata variables.
The following variables are supported. Values can also be set in the
input document for file formats that support metadata blocks (e.g. Pandoc's
Markdown).
Name Type Default Description
---------------------- ------- ------- ---------------------------------
gamebook-post-link string '' Text to add after every link
gamebook-pre-link string '' Text to add before every link
gamebook-shuffle boolean true Shuffle sections
gamebook-strong-links boolean true Use strong text style for links
# Gamebook Graph (Graphviz DOT)
The Pandoc filter *pangamebookdot.lua* is included to create a plain-text
DOT file from a generated gamebook, that can then be used with the *dot*
@ -123,6 +138,11 @@ edits will have to be done again if the document is ever recreated. It is better
to read up on how to apply styles to the generated file, for instance by using a
template style Word document.
This is how to set some metadata variables, in this case to put double square brackets
around links and disable shuffling:
pandoc -Mgamebook-shuffle=false -Mgamebook-pre-link="[[" -Mgamebook-post-link="]]" --lua-filter=pangamebook.lua -o example.html example.md
To generate a graph from the book first create a new Markdown document
using the pangamebook filter and then use the pangamebookdot filter
on the resulting document, before running the Graphviz dot command.
@ -165,7 +185,7 @@ mirror that is updated with new releases.
# LICENSE
MIT License
Copyright (c) 2021 Pelle Nilsson
Copyright (c) 2021-2022 Pelle Nilsson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -1,14 +1,18 @@
-- pandoc filter to turn headers and links into numbers
-- Copyright 2021 Pelle Nilsson
-- Copyright 2021-2022 Pelle Nilsson
-- MIT License
-- source: https://github.com/lifelike/pangamebook
-- version: 1.1 (2021-10-05)
-- fossil hash: db17fe61a7e3c56b7afe1132bdbe4c0ea6ec82102fb22b5207d2475eaace35a7
-- version: 1.2 (2022-03-24)
-- fossil hash: 5f58b0d1e74619524ff8f64c17488a0df5e4a4d24ef9a2ceb312311db4be2c33
local nr = 1
local mapped = {}
local strong_links = false
local link_pre = ''
local link_post = ''
function get_nr_for_header(text, identifier)
local key = "#" .. identifier
local name_nr = tonumber(text)
@ -76,11 +80,28 @@ function insert_sections(sections,
table.insert(sections, section)
end
function Pandoc(doc)
function from_meta_bool(meta, name, default)
value = meta[name]
if value ~= nil then
return value
end
return default
end
function from_meta_string(meta, name, default)
value = meta[name]
if value ~= nil then
return value
end
return default
end
function shuffle_blocks(doc)
local sections = {}
local first_section_i = 0
local current_section_start = -1
local blocks = {}
for i,el in pairs(doc.blocks) do
if (el.t == "Header"
and el.level == 1) then
@ -114,7 +135,19 @@ function Pandoc(doc)
if #sections > 0 then
shuffle_insert(blocks, sections)
end
return pandoc.Pandoc(blocks, doc.meta)
return blocks
end
function Pandoc(doc)
strong_links = from_meta_bool(doc.meta, "gamebook-strong-links", true)
link_pre = from_meta_string(doc.meta, "gamebook-pre-link", "")
link_post = from_meta_string(doc.meta, "gamebook-post-link", "")
if from_meta_bool(doc.meta, "gamebook-shuffle", true) then
return pandoc.Pandoc(shuffle_blocks(doc), doc.meta)
else
return doc
end
end
function Header(el)
@ -146,12 +179,16 @@ function Link(el)
return
end
local nr = mapped[el.target]
local content
if nr == nil then
return pandoc.Link(pandoc.Strong(pandoc.Str(el.target)), el.target)
content = pandoc.Str(link_pre .. el.target .. link_post)
else
local content = pandoc.Strong(pandoc.Str(nr))
return pandoc.Link(content, el.target)
content = pandoc.Str(link_pre .. nr .. link_post)
end
if strong_links then
content = pandoc.Strong(content)
end
return pandoc.Link(content, el.target)
end
function Blocks(blocks)

View file

@ -1,10 +1,10 @@
-- pandoc filter to output Graphviz DOT graph from gamebook
-- Copyright 2021 Pelle Nilsson
-- Copyright 2021-2022 Pelle Nilsson
-- MIT License
-- source: https://github.com/lifelike/pangamebook
-- version: 1.1 (2021-10-05)
-- fossil hash: db17fe61a7e3c56b7afe1132bdbe4c0ea6ec82102fb22b5207d2475eaace35a7
-- version: 1.2 (2022-03-24)
-- fossil hash: 5f58b0d1e74619524ff8f64c17488a0df5e4a4d24ef9a2ceb312311db4be2c33
function name_from_header(b)
local result = ""