diff --git a/_extensions/qquestion/qquestion.lua b/_extensions/qquestion/qquestion.lua index f432d9d..e6764e8 100644 --- a/_extensions/qquestion/qquestion.lua +++ b/_extensions/qquestion/qquestion.lua @@ -28,8 +28,8 @@ SOFTWARE. ]]-- --- local str = pandoc.utils.stringify --- local pout = quarto.log.output +local str = pandoc.utils.stringify +local pout = quarto.log.output -- initiate rendering information and global question number local utelz = require("./renderinfo") @@ -42,7 +42,8 @@ local qnum = 0 function init_qnum(renderinfo) qnum = 0 qcount = 0 - if renderinfo.ishtmlbook then + -- pout("init qnum. current index "..renderinfo.currentindex) + if renderinfo.ishtmlbook and renderinfo.currentindex > 0 then for i, v in ipairs(renderinfo.rendr) do if i < renderinfo.currentindex then if v.qcount then @@ -92,6 +93,7 @@ end -- find {?? bla ??} function Inlines_parse(el) + -- pout("the inlines") for i,ele in pairs(el) do if ele.t == "Str" then if ele.text == "{??" then @@ -109,6 +111,7 @@ end function Pandoc_doit(doc) + -- pout("the pandoc") if rinfo.ishtml then quarto.doc.add_html_dependency({ @@ -121,7 +124,7 @@ function Pandoc_doit(doc) quarto.doc.add_format_resource("Emo_think.png") end - if rinfo.ishtmlbook then + if rinfo.ishtmlbook and rinfo.currentindex > 0 then rinfo.rendr[rinfo.currentindex].qcount = qcount end; utelz.save_info(rinfo) @@ -133,7 +136,9 @@ return{ { -- first get rendering information Meta = function(meta) rinfo = utelz.Meta_getinfo(meta) + -- pout("now init") init_qnum(rinfo) + -- pout("fertig") end }, { diff --git a/_extensions/qquestion/renderinfo.lua b/_extensions/qquestion/renderinfo.lua index e90f5d5..d99fe4c 100644 --- a/_extensions/qquestion/renderinfo.lua +++ b/_extensions/qquestion/renderinfo.lua @@ -65,6 +65,7 @@ local function update_otherchapinfo(rinfo, newinfo) if rinfo.isbook then --pout(newchap) iexclude = rinfo.currentindex + -- pout("update all but "..iexclude) -- double check if chapter lists are compatible, otherwise overwrite and quit for i, v in ipairs(oldchap) do if OK then @@ -95,6 +96,7 @@ local function Meta_projectfiles(meta) local rinfo={} local fname="" local ir = 0 + local chapno = "" -- pout("here we go") rinfo.ispdf = quarto.doc.is_format("pdf") rinfo.ishtml = quarto.doc.is_format("html") @@ -109,11 +111,13 @@ local function Meta_projectfiles(meta) -- rinfo.first = "" -- rinfo.last = "" rinfo.rendr = {} + rinfo.currentindex = 0 for _, v in pairs(meta.book.render) do if str(v.type) == "chapter" then ir = ir+1 - if v.number then chapno = str(v.number) - else chapno = "" end + -- 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)) if fname == processedfile then rinfo.currentindex = ir end -- rinfo.last = fname @@ -130,13 +134,16 @@ local function Meta_projectfiles(meta) end rinfo.chapno = "" if rinfo.isbook then - if meta.chapno then - rinfo.chapno = str(meta.chapno) - rinfo.rendr[rinfo.currentindex].chapno = rinfo.chapno - else - rinfo.chapno = rinfo.rendr[rinfo.currentindex].chapno - end - end + -- pout("current "..rinfo.currentindex.." chapno "..rinfo.chapno) + if rinfo.currentindex > 0 then + if meta.chapno then + rinfo.chapno = str(meta.chapno) + rinfo.rendr[rinfo.currentindex].chapno = rinfo.chapno + else + rinfo.chapno = rinfo.rendr[rinfo.currentindex].chapno + end +-- else rinfo.chapno = "" + end end return(rinfo) end; @@ -146,10 +153,9 @@ local function Meta_getinfo(meta) local rinfo={} local oldinfo=read_info() - -- pout("here we go") rinfo = Meta_projectfiles(meta) -- pout(oldinfo) - if oldinfo then update_otherchapinfo(rinfo, oldinfo) + if oldinfo then if rinfo.chapternumber then update_otherchapinfo(rinfo, oldinfo) end else pout ("no old info available") end return(rinfo) diff --git a/example.qmd b/example.qmd index ce725b2..b22942f 100644 --- a/example.qmd +++ b/example.qmd @@ -17,6 +17,6 @@ And then the lorem ipsum. A question can also stand out and be put in a quote. ??} -\section{Vinks til udvalgte spørgsmål} +\section{Hints to selected questions} \qsolutions \ No newline at end of file