Skip to content
Discussion options

You must be logged in to vote

Here is a simple Lua filter to add filename using the code cell language.

function CodeBlock(code)
  local lang = code.attr.classes[1] 
  if lang == "cell-code" then 
    _, _, matchedLang = string.find(code.text, "^`+%{%{([^%}]*)%}%}")
    lang = matchedLang or lang
  elseif lang ~= nil and lang:find('{{', 1, true) == 1 then
    _, _, matchedLang = string.find(lang, "{{+(.-)}}+")
    if matchedLang then
      lang = matchedLang
    end
  end
  return quarto.DecoratedCodeBlock({
    filename = lang,
    code_block = code:clone()
  })
end

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@mcanouil
Comment options

@js2264
Comment options

Comment options

You must be logged in to vote
1 reply
@js2264
Comment options

Answer selected by js2264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
websites Issues creating websites lua Issues related to the lua codebase, filter chain, etc
2 participants