Skip to content

Commit

Permalink
allow for chapters in subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
ute committed Feb 21, 2024
1 parent 924d04a commit 3da4e02
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*_files/
/.luarc.json
Emo_think.png
_renderinfo.json
quickanswers.tex
5 changes: 3 additions & 2 deletions _extensions/qquestion/qquestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function init_qnum(renderinfo)
for i, v in ipairs(renderinfo.rendr) do
if i < renderinfo.currentindex
then if v.qcount then
-- if v.qcount > 0 then pout("add counts "..v.qcount) end
qnum = qnum + v.qcount
end end
end
Expand Down Expand Up @@ -111,7 +112,6 @@ end


function Pandoc_doit(doc)
-- pout("the pandoc")
if rinfo.ishtml
then
quarto.doc.add_html_dependency({
Expand All @@ -125,8 +125,10 @@ function Pandoc_doit(doc)
end

if rinfo.ishtmlbook and rinfo.currentindex > 0 then
-- pout ("updating render info with counts "..qcount)
rinfo.rendr[rinfo.currentindex].qcount = qcount
end;
-- pout ("save rinfo for current index"..rinfo.currentindex)
utelz.save_info(rinfo)
return(doc)
end
Expand All @@ -136,7 +138,6 @@ return{
{ -- first get rendering information
Meta = function(meta)
rinfo = utelz.Meta_getinfo(meta)
-- pout("now init")
init_qnum(rinfo)
-- pout("fertig")
end
Expand Down
28 changes: 20 additions & 8 deletions _extensions/qquestion/renderinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ SOFTWARE.

local str = pandoc.utils.stringify
local pout = quarto.log.output
local dumpfile = "_renderinfo.json"
local projectdir = os.getenv("QUARTO_PROJECT_DIR")
local dumpfile = projectdir.."/_renderinfo.json"

-- rendering information

Expand All @@ -53,6 +54,7 @@ local function save_info(renderinfo)
local rjson = quarto.json.encode(renderinfo)
local file = io.open(dumpfile,"w")
if file ~= nil then
-- pout ("dumping render info to "..dumpfile)
file:write(rjson)
file:close()
end
Expand All @@ -75,7 +77,7 @@ local function update_otherchapinfo(rinfo, newinfo)
end
end
if not OK then
-- pout("there have been changes in chapters. Overwriting information now!")
pout("there have been changes in chapters. Overwriting render information now.")
save_info(rinfo)
else -- update other information
for i, v in ipairs(oldchap) do
Expand All @@ -85,8 +87,8 @@ local function update_otherchapinfo(rinfo, newinfo)
oldchap[i] = newchap[i]
end
end
-- pout("updated info")
-- pout(rinfo)
-- pout("updated info")
-- pout(rinfo)
end
end
end
Expand All @@ -95,6 +97,7 @@ local function Meta_projectfiles(meta)
local processedfile = pandoc.path.split_extension(PANDOC_STATE.output_file)
local rinfo={}
local fname=""
local file = ""
local ir = 0
local chapno = ""
-- pout("here we go")
Expand All @@ -118,12 +121,14 @@ local function Meta_projectfiles(meta)
-- pout("setup chapter "..ir.." file "..str(v.file))
if v.number then chapno = str(v.number) end;
-- else chapno = "" end
fname = pandoc.path.split_extension(str(v.file))
file = str(v.file)
fname = pandoc.path.filename(pandoc.path.split_extension(file))
-- pout("process "..processedfile.." fname "..fname)
if fname == processedfile then rinfo.currentindex = ir end
-- rinfo.last = fname
-- if rinfo.first == "" then rinfo.first = fname end
rinfo.rendr[ir] ={
file = str(v.file),
file = file,
chapno = chapno,
fname = fname
}
Expand Down Expand Up @@ -155,8 +160,15 @@ local function Meta_getinfo(meta)

rinfo = Meta_projectfiles(meta)
-- pout(oldinfo)
if oldinfo then if rinfo.chapternumber then update_otherchapinfo(rinfo, oldinfo) end
else pout ("no old info available")
if oldinfo
then
-- pout("old info found")
if rinfo.chapno -- is chapter
then
-- pout("is chapter "..rinfo.chapno)
update_otherchapinfo(rinfo, oldinfo)
end
-- else pout ("no old chapter info available ")
end
return(rinfo)
end
Expand Down

0 comments on commit 3da4e02

Please sign in to comment.