diff --git a/examples/manual-masterdoc/masterdoc.dj b/examples/manual-masterdoc/masterdoc.dj index c9b2535..759bbfa 100644 --- a/examples/manual-masterdoc/masterdoc.dj +++ b/examples/manual-masterdoc/masterdoc.dj @@ -104,4 +104,11 @@ The `sile` object provides intructions for processing the master document with S ## Content files -Quite obviously, the `content` array is an ordered list of filenames defining the content of the book. +Quite obviously, the `content` array is an ordered list of files defining the content of the book. + +Those files may be of any type supported by SILE, the document class or loaded packages.[^masterdoc-nesting] + +[^masterdoc-nesting]: In particular, you can include a master document in another. +In that case, though, a few elements only from the nested document are used (namely, the declared +extra packages and the content files). + diff --git a/inputters/silm.lua b/inputters/silm.lua index 8c95ebd..c10dcd8 100644 --- a/inputters/silm.lua +++ b/inputters/silm.lua @@ -196,37 +196,53 @@ function inputter.parse (_, doc) if not ok then SU.error("Invalid master document (" .. err .. ")") end + if type(master) ~= "table" then + SU.error("Invalid master document (not a table)") + end + + -- Are we the root document, or some included subdocument? + -- in the latter case, we only honor some of the fields. + local isRoot = not SILE.documentState.documentClass local content = {} - -- Document global settings - if master.font then - if type(master.font.family) == "table" then - content[#content+1] = Cc("use", { - module = "packages.font-fallback" - }) - content[#content+1] = Cc("font", { - family = master.font.family[1], - size = master.font.size - }) - for i = 2, #master.font.family do - content[#content+1] = Cc("font:add-fallback", { - family = master.font.family[i], + local sile = master.sile or {} + local metadata = master.metadata or {} + + if isRoot then + -- Document global settings + if master.font then + if type(master.font.family) == "table" then + content[#content+1] = Cc("use", { + module = "packages.font-fallback" + }) + content[#content+1] = Cc("font", { + family = master.font.family[1], + size = master.font.size + }) + for i = 2, #master.font.family do + content[#content+1] = Cc("font:add-fallback", { + family = master.font.family[i], + }) + end + else + content[#content+1] = Cc("font", { + family = master.font.family, + size = master.font.size }) end - else - content[#content+1] = Cc("font", { - family = master.font.family, - size = master.font.size + end + -- FIXME QUESTION: I start too think that main language should + -- be class option so that some decisions could be delegated to + -- the class (e.g. style overrides in the case of resilient classes) + -- Not sure how to behave with legacy classes though... + if master.language then + content[#content+1] = Cc("language", { + main = master.language }) end end - if master.language then - content[#content+1] = Cc("language", { - main = master.language - }) - end - local sile = master.sile or {} + local packages = sile.packages or {} if packages then for _, pkg in ipairs(packages) do @@ -235,63 +251,70 @@ function inputter.parse (_, doc) }) end end - local settings = sile.settings or {} - if settings then - for k, v in pairs(settings) do - content[#content+1] = Cc("set", { - parameter = k, - value = v - }) + + if isRoot then + local settings = sile.settings or {} + if settings then + for k, v in pairs(settings) do + content[#content+1] = Cc("set", { + parameter = k, + value = v + }) + end + end + if metadata.title then + content[#content+1] = Cc("odd-running-header", {}, { metadata.title }) end end - local metadata = master.metadata or {} - if metadata.title then - content[#content+1] = Cc("odd-running-header", {}, { metadata.title }) - end + -- Document content + -- FIXME QUESTION: if not a root document, should we wrap the includes + -- in a language group? for _, inc in ipairs(master.content) do content[#content+1] = Cc("include", { src = inc }) end - -- PDF metadata - -- HACK: inserted at the very end of the document because (at least in SILE 0.14) - -- it introduces hboxes than can affect indents, centering, page breaks and paragraphs... - if metadata.title then - content[#content+1] = Cc("pdf:metadata", { - key = "Title", - value = master.metadata.title - }) - end - if metadata.authors then - content[#content+1] = Cc("pdf:metadata", { - key = "Author", - value = type(metadata.authors) == "table" and table.concat(metadata.authors, "; ") or metadata.authors - }) - end - if metadata.subject then - content[#content+1] = Cc("pdf:metadata", { - key = "Subject", - value = metadata.subject - }) - end - if metadata.keywords then - content[#content+1] = Cc("pdf:metadata", { - key = "Keywords", - value = type(metadata.keywords) == "table" and table.concat(metadata.keywords, "; ") or metadata.keywords - }) + if isRoot then + -- PDF metadata + -- NOTE: inserted at the very end of the document because (at least in SILE 0.14) + -- it introduces hboxes than can affect indents, centering, page breaks and paragraphs... + if metadata.title then + content[#content+1] = Cc("pdf:metadata", { + key = "Title", + value = master.metadata.title + }) + end + if metadata.authors then + content[#content+1] = Cc("pdf:metadata", { + key = "Author", + value = type(metadata.authors) == "table" and table.concat(metadata.authors, "; ") or metadata.authors + }) + end + if metadata.subject then + content[#content+1] = Cc("pdf:metadata", { + key = "Subject", + value = metadata.subject + }) + end + if metadata.keywords then + content[#content+1] = Cc("pdf:metadata", { + key = "Keywords", + value = type(metadata.keywords) == "table" and table.concat(metadata.keywords, "; ") or metadata.keywords + }) + end end + -- Document wrap-up local options = master.sile.options or {} - - local tree = { - Cc("document", { + local classopts = isRoot and { class = options.class or "resilient.book", -- Sane default. We Are Resilient. - layout = options.layout, papersize = options.papersize, + layout = options.layout, resolution = options.resolution - }, { - content - }), + } or {} + + local tree = { + Cc("document", classopts, { content }), } return tree