-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting the language attribute for code blocks for a whole document once #2104
Comments
I solved that particular problem by using a small filter script called ozify.hs (to force any unidentified code to the oz language) The filter adds the #!/usr/bin/env runhaskell
-- ozify.hs
import Text.Pandoc
import Text.Pandoc.JSON
main :: IO ()
main = toJSONFilter ozify
ozify :: Block -> Block
ozify = bottomUp ozifyInline . bottomUp ozifyBlock
ozifyBlock (CodeBlock (id,[],keys) code) = CodeBlock (id, ["oz"], keys) code
ozifyBlock x = x
ozifyInline (Code (id,[],keys) code) = Code (id, ["oz"], keys) code
ozifyInline x = x |
You can set the class for all indented code blocks, so these +++ Lorenzo Bercelli [Apr 21 15 14:04 ]:
|
thanks for the quick reply, this doesn't work for fenced code blocks though. Would be neat to extend it so that it does. |
You could write a simple pandoc filter that adds the class attribute to all code +++ Lorenzo Bercelli [Apr 22 15 02:43 ]:
|
Is there a reason for |
The thought was that it might be useful to have a way of getting a code block without any class, even if you're using |
I believe this issue could be re-opened (as a "feature request", maybe): having a way of specifying the language attribute(s) for all the code (indented, fenced with ` or |
I just came across this scenario today as well. I want to cause to highlight a large number of references in `backticks` with a particular code class so as to emphasize the references, versus specifying each instance with a, e.g. {.blah}. Use case for context- have a large working document that documents Aside, trying |
You may want to report that as a bug? |
It is interesting, because if- currently- using Not sure I would refer to it as a bug but interesting to consider because if it isn't designed to affect/benefit `backtick` references, then why is it affecting them at all? |
Clarifying and correcting myself- it does not appear that specifying So, the input is:
... |
Create a file local default_code_classes = {}
function add_default_code_class(el)
if #(el.classes) == 0 then
el.classes = default_code_classes
return el
end
end
function get_default_code_class(meta)
if meta['default-code-class'] then
default_code_classes = {pandoc.utils.stringify(meta['default-code-class'])}
end
end
return {{Meta = get_default_code_class},
{Code = add_default_code_class},
{CodeBlock = add_default_code_class}} Now you can use |
That's perfect (except that the comment in lua starts with I have two questions:
Test:
produces as expected, when compiled with
|
Is it possible to set in the metadata of a file the language to use to highlight code blocks ? I rarely switch programming languages inside the same document.
The text was updated successfully, but these errors were encountered: