pandoc
pandoc copied to clipboard
Permit adding attributes to all Markdown elements
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:
#{.main} Header
it would generate this:
<h1 class="main" id="header">Header</h1>
rather than this:
<h1 id="main-header">{.main} Header</h1>
Ditto for, say:
Header
----{.main}
...which is probably even legible enough to fit with Markdown's philosophical aversion to looking, well, marked-up.
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 as progress?
John,
I thought that was a terrific step, along with the inline_code_attributes extension. I'm looking forward to when classes and key/value pairs are implemented for headers, since the particular use case I had in mind involved setting an identifier and an onClick event.
Thanks so much for all your work on Pandoc; it's really a thing of beauty.
+++ Daniel Shannon [Mar 15 13 18:04 ]:
John, I thought that was a terrific step, along with the inline_code_attributes extension. I'm looking forward to when classes and key/value pairs are implemented for headers, since the particular use case I had in mind involved setting an identifier and an onClick event.
They are already implemented in 1.11!
% pandoc
# Hi {#foo .bar .baz key=val}
^D
<h1 id="foo" class="bar baz" key="val">Hi</h1>
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 reveal.js could and probably should be set by a new output format for pandoc, however, it's a lot harder to come up with a solution for the transition options. Both Beamer and reveal.js allow the user to configure how and when transitions occur (I don't know about all the other js templates).
Custom attributes would make it simple for reveal.js and even for beamer, the necessary script would not be complicated. Conceptually, such concepts as how and when to reveal an element feel like options rather than some new syntactic element. Alternative solutions would seem to require awkward detection and parsing of (to pandoc) literal string elements.
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 \pause in beamer and using fragment divs in revealjs. Of course, you can also just use a <div class="fragment"> in the markdown source, but this won't be portable if you decide to switch to beamer.
@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. I understand that it would be very work heavy and difficult to implement without ambiguities and messy syntax, so I second @blaenk's suggestion to implement an attribute field to the image element (because I find I almost always need to add some kind of metadata/attribute to it) and leave the rest to div/span solutions.
With image attributes underway, I could take a look at adding attributes to a few more elements if this is desired:
Link#170Table#813BlockQuote(see example in #1242)
While the HTML writers would pass through all attributes, the others would just support the id and classes where appropriate. So beyond referencing tables and blockquotes, it would primarily enable simpler filters.
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! Probably means I will soon be able to write journal article fully in Pandoc Markdown without or almost without manual editing in LaTeX.
On 12/30/2014 01:42 PM, mb21 wrote:
With image attributes underway https://github.com/jgm/pandoc/pull/1806, I could take a look at adding attributes to a few more elements if this is desired:
- |Link| #170 https://github.com/jgm/pandoc/issues/170
- |Table| #813 https://github.com/jgm/pandoc/issues/813
- |BlockQuote| (see example in #1242 https://github.com/jgm/pandoc/issues/1242)
While the HTML writers would pass through all attributes, the others would just support the |id| and |classes| where appropriate. So beyond referencing tables and blockquotes, it would primarily enable simpler filters.
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 http://talk.commonmark.org/t/consistent-attribute-syntax/272/ and proposal https://mb21.github.io/stmd/spec.html#extensions).
— Reply to this email directly or view it on GitHub https://github.com/jgm/pandoc/issues/684#issuecomment-68353338.
This would be fantastic. Even if attributes are mostly only available in the data model for filtering that enables a large number of currently difficult use cases.
Jamie Olson
On Tue, Dec 30, 2014 at 8:59 AM, Thøger Rivera-Thorsen < [email protected]> wrote:
This is really great news! Probably means I will soon be able to write journal article fully in Pandoc Markdown without or almost without manual editing in LaTeX.
On 12/30/2014 01:42 PM, mb21 wrote:
With image attributes underway https://github.com/jgm/pandoc/pull/1806, I could take a look at adding attributes to a few more elements if this is desired:
- |Link| #170 https://github.com/jgm/pandoc/issues/170
- |Table| #813 https://github.com/jgm/pandoc/issues/813
- |BlockQuote| (see example in #1242 https://github.com/jgm/pandoc/issues/1242)
While the HTML writers would pass through all attributes, the others would just support the |id| and |classes| where appropriate. So beyond referencing tables and blockquotes, it would primarily enable simpler filters.
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 http://talk.commonmark.org/t/consistent-attribute-syntax/272/ and proposal https://mb21.github.io/stmd/spec.html#extensions).
— Reply to this email directly or view it on GitHub https://github.com/jgm/pandoc/issues/684#issuecomment-68353338.
— Reply to this email directly or view it on GitHub https://github.com/jgm/pandoc/issues/684#issuecomment-68358079.
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. Looks like {.allowframebreaks} and .fragile by test made in 1.15.0.6. But why not support arbitrary attributes? In particular c, noframenumbering and plain.
+++ fmatheus [Oct 14 15 15:05 ]:
Would be great if any header_attributes was supported in beamer output. Looks like {.allowframebreaks} and .fragile by test made in 1.15.0.6. But why not support arbitrary attributes? In particular c, noframenumbering and plain.
Sounds plausible to me. This just takes a small change in the LaTeX writer.
+++ fmatheus [Oct 14 15 15:05 ]:
Would be great if any header_attributes was supported in beamer output. Looks like {.allowframebreaks} and .fragile by test made in 1.15.0.6. But why not support arbitrary attributes? In particular c, noframenumbering and plain.
I've added support for all frame attributes in commit 504bf3f8e79bd502f406264e2cc2794b129a26c0
Sounds plausible to me. This just takes a small change in the LaTeX writer.
Attributes to all Markdown elements is not only useful to LaTeX and Beamer. I personally can think of many use cases for it as XHTML classes.
+++ Serge Y. Stroobandt [Oct 16 15 06:24 ]:
Sounds plausible to me. This just takes a small change in the LaTeX writer. Attributes to all Markdown elements is not only useful to LaTeX and Beamer. I personally can think of many use cases for it as XHTML classes.
Sure. I was responding to the (misplaced) previous comment which just concerned Beamer attributes on headers, not to this general issue.
@jgm:
% pandoc
# Hi {#foo .bar .baz key=val}
^D
<h1 id="foo" class="bar baz" key="val">Hi</h1>
How can an ID be applied to a link? The following doesn't work:
[Als DOCX downloaden](somewhere.html) {#download_as_docx}
You need the very latest dev version of pandoc to apply an
ID to a link (compile from source). And you can't have a
space before the {.
+++ Joshua Muheim [Nov 25 15 14:38 ]:
[1]@jgm: % pandoc
Hi {#foo .bar .baz key=val}
^D
Hi
How can an ID be applied to a link? The following doesn't work: Als DOCX downloaden {#download_as_docx}
— Reply to this email directly or [2]view it on GitHub.
References
- https://github.com/jgm
- https://github.com/jgm/pandoc/issues/684#issuecomment-159747313
@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:
If Markdown is based on HTML, Markdown should have three basic attributes in all elements.
And sorry, if LaTeX cannot handle this, we should find another way of dealing with XML when using LaTeX.
We have now Attr (i.e. attribute support) also on Image and Link elements, as can be seen on the pandoc-types Definition.hs. To add it to further elements, we'll have to change the types and then change all the writers, which takes a lot of work and is a breaking change for filters etc. Still, I hope we'll be able to add it to more elements in the future... contributions welcome :)
Thanks, @mb21. Good to hear you're still moving on this. Contributions might be forthcoming once I find a friend who can do Haskell (or time to learn myself). I see you have this generic
| Span Attr [Inline] -- ^ Generic inline container with attributes
I can't parse haskell very well, so I apologize if this sounds dumb. What is this generic inline container?
It's literally the native pandoc span element (there's also a div element). Unfortunately there's no markdown syntax yet (but most probably it'll be [my text]{.myClass})—meanwhile you can write inline HTML:
echo 'some _italic_ markdown with <span class="myClass">my text</span>' | pandoc -t native
The Attr means it holds attribute and the [Inline] means a list of Inline elements. see http://learnyouahaskell.com/making-our-own-types-and-typeclasses#algebraic-data-types for an introduction into haskell data types (the whole pandoc internal document AST is such a data type).
Thanks, @mb21. This is very useful. We've decided to use some HTML tags until further notice to deal with poetry. Here's looking forward to having both this new [my text]{.myClass} syntax and the coveted attribute class for any element.
Thanks for the link to this tutorial also. It seems very complete and approachable. I got the gist of the data types right away. Perhaps it will be me or someone in my team who implements, after all.
You know about line blocks, right?
http://pandoc.org/README.html#line-blocks
This will give you control over line breaking and initial indentation, without sacrificing source readability.
If you want more control, you can wrap a line block in a div with a class, and you can wrap individual lines in a span.