Skip to content

Conversation

@tarleb
Copy link
Collaborator

@tarleb tarleb commented Aug 12, 2025

No description provided.

@tarleb
Copy link
Collaborator Author

tarleb commented Aug 12, 2025

I'm not entirely sure if this is really worth the additional code.

@tarleb tarleb force-pushed the lua-pandoc.highlighting branch from e885654 to 2621223 Compare August 12, 2025 11:35
@tarleb
Copy link
Collaborator Author

tarleb commented Aug 12, 2025

I admit that my primary motivation was to a give a one-line answer to a StackOverflow question, because I thought it would be neat to get CSS definitions by running

pandoc lua -e "print(pandoc.highlighting.definitions('espresso', 'css')"

After playing around with this some more, I also really liked the ability to implement a simple syntax highlighter for the console:

local infile       = arg[1]
local _, fileext   = pandoc.path.split_extension(infile)
local style = pandoc.highlighting.style('kate')
local wopts = pandoc.WriterOptions{highlight_style = style}
local codeblock = pandoc.CodeBlock(
  pandoc.system.read_file(infile),
  {class = fileext:sub(2)} -- drop leading dot
)

print(pandoc.highlighting.highlight(codeblock, 'ansi', wopts))

So maybe it is worth the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant