X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Freport.git;a=blobdiff_plain;f=pret-haskell.lua;h=ca3a1651d520ae2c13f99426f45af90f2498c4cc;hp=483d660dd2c70c577b64ceaf2a7fef9db475f1a6;hb=0dfecb0be783911fd804436c22bbbf8c79711cc3;hpb=1108517b5c84c5fc7c8aa21ac60cd33e28487519 diff --git a/pret-haskell.lua b/pret-haskell.lua index 483d660..ca3a165 100644 --- a/pret-haskell.lua +++ b/pret-haskell.lua @@ -9,25 +9,47 @@ local utf = unicode.utf8 local visualizer = buffers.newvisualizer('haskell') +-- Print a string or table of strings with the catcodes set to the default +-- context ones. Use this function to print a string that contains context +-- macro's that should be interpreted. Does not insert any automatic +-- linebreaking. +local function ctxsprint(str) + tex.sprint(tex.ctxcatcodes, str) +end + +-- Print a string or table of strings almost literal. Each character in the +-- string will be printed with the "character" catcode, causing it to show up +-- literal in the output. Only the space character is printed with the "space" +-- catcode. +local function texwrite(str) + tex.write(str) +end + function visualizer.flush_line(str,nested) while str ~= '' do - print("Looking at '" .. str .. "'") if utf.match(str, '^ ') then - tex.sprint('\\obs ') + ctxsprint('\\obs ') -- Eat the first character str = utf.sub(str, 2) else local text, rest = utf.match(str, "^%-%-(.-)%-%-(.*)") if text then - tex.sprint('\\strikethrough{') + ctxsprint('\\strikethrough{') -- Recursively call ourselves to handle spaces gracefully. visualizer.flush_line(text) - tex.sprint('}') + ctxsprint('}') -- Eat the processed characters str = rest + elseif utf.match(str, "^%-%-") then + ctxsprint('{\\italic{--') + -- Recursively call ourselves to handle spaces gracefully. + visualizer.flush_line(utf.sub(str, 3)) + ctxsprint('}}') + -- Done with this line + str = '' else -- Write the first character - tex.write(utf.sub(str, 1, 1)) + texwrite(utf.sub(str, 1, 1)) -- Eat the first character str = utf.sub(str, 2) end