Skip to content

Commit

Permalink
fix to allow for parts
Browse files Browse the repository at this point in the history
  • Loading branch information
ute committed Feb 21, 2024
1 parent 83981cc commit 924d04a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
13 changes: 9 additions & 4 deletions _extensions/qquestion/qquestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -109,6 +111,7 @@ end


function Pandoc_doit(doc)
-- pout("the pandoc")
if rinfo.ishtml
then
quarto.doc.add_html_dependency({
Expand All @@ -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)
Expand All @@ -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
},
{
Expand Down
28 changes: 17 additions & 11 deletions _extensions/qquestion/renderinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 924d04a

Please sign in to comment.