Meta-data to control output
This commit is contained in:
parent
43e094011b
commit
f98f3362af
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT 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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
22
README.md
22
README.md
|
@ -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
|
Guide](https://pandoc.org/MANUAL.html) for information on all the ways you can
|
||||||
add style to the output document.
|
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)
|
# Gamebook Graph (Graphviz DOT)
|
||||||
The Pandoc filter *pangamebookdot.lua* is included to create a plain-text
|
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*
|
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
|
to read up on how to apply styles to the generated file, for instance by using a
|
||||||
template style Word document.
|
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
|
To generate a graph from the book first create a new Markdown document
|
||||||
using the pangamebook filter and then use the pangamebookdot filter
|
using the pangamebook filter and then use the pangamebookdot filter
|
||||||
on the resulting document, before running the Graphviz dot command.
|
on the resulting document, before running the Graphviz dot command.
|
||||||
|
@ -165,7 +185,7 @@ mirror that is updated with new releases.
|
||||||
# LICENSE
|
# LICENSE
|
||||||
MIT 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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
-- pandoc filter to turn headers and links into numbers
|
-- pandoc filter to turn headers and links into numbers
|
||||||
-- Copyright 2021 Pelle Nilsson
|
-- Copyright 2021-2022 Pelle Nilsson
|
||||||
-- MIT License
|
-- MIT License
|
||||||
-- source: https://github.com/lifelike/pangamebook
|
-- source: https://github.com/lifelike/pangamebook
|
||||||
|
|
||||||
-- version: 1.1 (2021-10-05)
|
-- version: 1.2 (2022-03-24)
|
||||||
-- fossil hash: db17fe61a7e3c56b7afe1132bdbe4c0ea6ec82102fb22b5207d2475eaace35a7
|
-- fossil hash: 5f58b0d1e74619524ff8f64c17488a0df5e4a4d24ef9a2ceb312311db4be2c33
|
||||||
|
|
||||||
local nr = 1
|
local nr = 1
|
||||||
local mapped = {}
|
local mapped = {}
|
||||||
|
|
||||||
|
local strong_links = false
|
||||||
|
local link_pre = ''
|
||||||
|
local link_post = ''
|
||||||
|
|
||||||
function get_nr_for_header(text, identifier)
|
function get_nr_for_header(text, identifier)
|
||||||
local key = "#" .. identifier
|
local key = "#" .. identifier
|
||||||
local name_nr = tonumber(text)
|
local name_nr = tonumber(text)
|
||||||
|
@ -76,11 +80,28 @@ function insert_sections(sections,
|
||||||
table.insert(sections, section)
|
table.insert(sections, section)
|
||||||
end
|
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 sections = {}
|
||||||
local first_section_i = 0
|
local first_section_i = 0
|
||||||
local current_section_start = -1
|
local current_section_start = -1
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
|
|
||||||
for i,el in pairs(doc.blocks) do
|
for i,el in pairs(doc.blocks) do
|
||||||
if (el.t == "Header"
|
if (el.t == "Header"
|
||||||
and el.level == 1) then
|
and el.level == 1) then
|
||||||
|
@ -114,7 +135,19 @@ function Pandoc(doc)
|
||||||
if #sections > 0 then
|
if #sections > 0 then
|
||||||
shuffle_insert(blocks, sections)
|
shuffle_insert(blocks, sections)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function Header(el)
|
function Header(el)
|
||||||
|
@ -146,12 +179,16 @@ function Link(el)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local nr = mapped[el.target]
|
local nr = mapped[el.target]
|
||||||
|
local content
|
||||||
if nr == nil then
|
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
|
else
|
||||||
local content = pandoc.Strong(pandoc.Str(nr))
|
content = pandoc.Str(link_pre .. nr .. link_post)
|
||||||
return pandoc.Link(content, el.target)
|
|
||||||
end
|
end
|
||||||
|
if strong_links then
|
||||||
|
content = pandoc.Strong(content)
|
||||||
|
end
|
||||||
|
return pandoc.Link(content, el.target)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Blocks(blocks)
|
function Blocks(blocks)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
-- pandoc filter to output Graphviz DOT graph from gamebook
|
-- pandoc filter to output Graphviz DOT graph from gamebook
|
||||||
-- Copyright 2021 Pelle Nilsson
|
-- Copyright 2021-2022 Pelle Nilsson
|
||||||
-- MIT License
|
-- MIT License
|
||||||
-- source: https://github.com/lifelike/pangamebook
|
-- source: https://github.com/lifelike/pangamebook
|
||||||
|
|
||||||
-- version: 1.1 (2021-10-05)
|
-- version: 1.2 (2022-03-24)
|
||||||
-- fossil hash: db17fe61a7e3c56b7afe1132bdbe4c0ea6ec82102fb22b5207d2475eaace35a7
|
-- fossil hash: 5f58b0d1e74619524ff8f64c17488a0df5e4a4d24ef9a2ceb312311db4be2c33
|
||||||
|
|
||||||
function name_from_header(b)
|
function name_from_header(b)
|
||||||
local result = ""
|
local result = ""
|
||||||
|
|
Loading…
Reference in a new issue