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
Permit adding attributes to all Markdown elements #684
Comments
FYI conversations on this topic date back 5 years: I for one think it's surprising that nothing seems to have been done to facilitate this. I understand the desire not to pollute the syntax, but it seems like people are taking extraordinary measures to work around this limitation. |
Would you count 1.11's allowing attributes to be added to headers |
John, Thanks so much for all your work on Pandoc; it's really a thing of beauty. |
+++ Daniel Shannon [Mar 15 13 18:04 ]:
They are already implemented in 1.11!
|
I think attributes for headers are a great and wonderful thing. I also think that there are totally valid reasons for wanting to add attributes to arbitrary elements. For example, in the reports package for R, the author, possibly intimidated by haskell, resorted to a series of fragile regular expressions to try add the necessary classes and attributes to html output. Certainly, the "fragment" class for Custom attributes would make it simple for |
Imho tables are in dire need of that new syntax for attributes. It is not rare to need different tables to be displayed with different styles. |
And there are different LaTeX figure-environments. Allowing to set custom attributes to an image tag would mean one could more easily distinguish different kinds of figure. Other writers could simply ignore it. |
@jamiefolson: pandoc now includes a uniform syntax for transitions, which gets output as @luc-j-bourhis, @thriveth: You can wrap a table or figure with a div that has attributes. Are there reasons the attributes have to be on the table or image itself? |
@jgm I wasn't aware of that, but looking at #1242 I can see it is possible, but also witht he caveats that @blaenk mentions there. |
With image attributes underway, I could take a look at adding attributes to a few more elements if this is desired:
While the HTML writers would pass through all attributes, the others would just support the The exact markdown syntax for tables and blockquotes isn't exactly obvious, but I tend to favour the variant where the attributes have to be on their own line, trailing the actual table or blockquote (see the commonmark discussion and proposal). |
This is really great news! On 12/30/2014 01:42 PM, mb21 wrote:
|
This would be fantastic. Even if attributes are mostly only available in Jamie Olson On Tue, Dec 30, 2014 at 8:59 AM, Thøger Rivera-Thorsen <
|
This issue is also listed as item 2 on this list. (Disclaimer: I have no relation to that web site.) |
Would be great if any header_attributes was supported in beamer output. |
+++ fmatheus [Oct 14 15 15:05 ]:
Sounds plausible to me. This just takes a small change in |
+++ fmatheus [Oct 14 15 15:05 ]:
I've added support for all frame attributes in commit |
Attributes to all Markdown elements is not only useful to LaTeX and Beamer. |
+++ Serge Y. Stroobandt [Oct 16 15 06:24 ]:
Sure. I was responding to the (misplaced) previous comment which just |
@jgm:
How can an ID be applied to a link? The following doesn't work:
|
You need the very latest dev version of pandoc to apply an +++ Joshua Muheim [Nov 25 15 14:38 ]:
|
@jgm, will all elements have attributes in Markdown? |
@jgm, which version is this? I have 1.15.2.1, which came with homebrew. |
It comes in version 1.16.x. Latest released version is 1.16.0.2. |
Any updates on this? We're trying to create a workflow that will produce a web version and a print version from the same markdown file. We're using Jekyll for web deployment. Jekyll usually plays nice with kramdown, but @mfenner has been working on a gem called jekyll-pandoc. We've been knocking our heads silly trying to decide how to handle poetry. (We're lit folks). At issue right now is the inability to handle classes at the line level so we can make the right CSS to wrap our lines nicely, etc. Kramdown handles this exceptionally well, but then we'll be giving up our workflow for pandoc | *TeX which depends on pandoc-markdown. If we can get pandoc-markdown to work well with Jekyll + poetry, we will have devised an excellent solution for a large community of editors and scholars who can now produce nice PDF's and nice websites out of the same files. We're trying at all costs to avoid to have to write filters, or divide the editing workflow into two parts. Can we get attributes at the unnumbered list line and block level, and its corollary the blockquoted unnumbered list? Or is this out with the new implementation and I missed something? |
I think the basic issue is the following:
And sorry, if LaTeX cannot handle this, we should find another way of dealing with XML when using LaTeX. |
Table & Equation Attributes?+1 for the ability to add attributes to additional markdown elements. As of Pandoc version 2.7, it appears from the docs that attributes are supports for headers, code blocks, inline code, links (includes images / figures), divs, and spans. Attributes are not supported however for tables and equations, which I believe is causing several users trouble (see tomduck/pandoc-tablenos#11, this SO, etcetera). Setting anchors for tables and equations is one main use case that comes to mind. Currently, the So while universal attribute support would be great, is it possible table / equation attribute support could be added in the shorter-term, with a syntax that could be forward compatible? |
This might be something worth picking up again (for IR support), now that the CommonMark reader has support for adding attributes to all elements. Having a new data Attr = Attr Text [Text] (Map Text Text)
-- or
data Attr = Attr
{ attrId :: Text
, attrClasses :: [Text]
, attrKeyVals :: Map Text Text
}
-- The Map could be newtyped, as was suggested above That kind of simple As for Possibly Initial |
An enhancement here is to have data ListItem = ListItem Attr [Block]
data ListLabel = ListLabel Attr [Inline] for the lists to use, since in LaTeX these can be labelled and referenced (list items can at least), and in HTML they are elements with the usual attributes. These seem to be the only things that are plausibly |
UPDATE: This is more of a hack but I figured it out and it works. I will post so that it will help someone else in the future. Hopefully, in the future there's an easier way to add classes to elements in pandoc other than just a few. I don't know a lot of lua, so if anyone knows of an easier way feel free to comment. local List = require 'pandoc.List'
function Para(el)
local classes = {coffee = '{.tip}',warn = '{.warn}'}
for k,v in pairs(el.content) do
text = v.text
for name,class in pairs(classes) do
if class == text then
el.content[k].text = ''
local p = List:new{}
p:extend({pandoc.RawBlock('html', '<p class="'.. name .. '">')})
p:extend({pandoc.Plain(el.content)})
p:extend({pandoc.RawBlock('html', '</p>')})
return p
end
end
end
end Has this been resolved? I need to change a class on paragraphs depending on if a word is found in the paragraph. Unfortunately, according to the docs Para only takes one argument which is content. Span takes 2, might need to wrap it with span. Not sure if I can hack this with the following? return pandoc.RawBlock('html','<p>'..element.content..'</p>') Probably not, since I more than likely have to loop and extract everything out of content. Seems like a lot of work just to insert a class into a paragraph. I can easily do this in hugo with {.myclass} after the paragraph. Hopefully this will be adopted by pandoc. OR wrapping it like in this example: function Para(el)
content = el.content
attr = pandoc.Attr("", {".myclass"})
return pandoc.Para(pandoc.Span(content, attr))
end |
Hello @rickalex21, there is a small problem. I have a class containing a hyphen, i.e., |
I notice there is the non-default extension-attributes (https://pandoc.org/MANUAL.html#extension-attributes):
Doesn't it address this issue? |
That extension works with |
I'd like to suggest that Pandoc allow attributes to be attached to any Markdown element, not just code blocks. So for example, if it encountered this:
it would generate this:
rather than this:
Ditto for, say:
...which is probably even legible enough to fit with Markdown's philosophical aversion to looking, well, marked-up.
The text was updated successfully, but these errors were encountered: