Den ons 14 juni 2023 18:24H skrev: > On 06/14/2023 02:49 AM, Bastien DUMONT wrote: > > You can learn which elements have an “attributes” field from the doc: https://pandoc.org/lua-filters.html > > Le Tuesday 13 June 2023 à 08:34:05PM, H a écrit : > > On 06/13/2023 06:53 PM, H wrote: > > On 06/13/2023 06:05 PM, H wrote: > > On 06/13/2023 05:27 PM, Bastien DUMONT wrote: > > attr.style = 'color: #112233;' > > Wonderful, many thanks! Btw, I was reading my email in the reverse order or I would have found this before my other post... > > > How can I similarly add a style to an tag? This tag is wrapped inside a
tag. > > > Besides adding a style to (Image) elements, I also want to add a style to
(HorizontalRule). It seems that the following does not work: > > local style_hr = 'border-top-style: solid; border-top-width: thin; border-color: #cc002b;' > > if (el.type == 'HorizontalRule') then > local attr = el.attributes > attr.style = style_hr > end > > The desired output is: > >
> > Pandoc fails assigning the style, however, adding the code to the html file shows it is valid html code. > > Have I missed something or might this be a bug? > > -- > You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/61724767-ada0-133f-6751-5884c7460a25%40meddatainc.com. > > Corre,t in that list HorizontalRule does not have an attributes field but > ought it not to have one? > Pandoc's document module used to not support attributes at all. IIRC attributes were first introduced for fenced code blocks, then extended to inline code. Spans and divs (in the Pandoc sense) were introduced specifically to provide containers for arbitrary content to which attributes can be attached. At the same time (IIRC) attributes were extended to headings ("Header"), links and images. It was decided not to extend attributes to other elements as that would entail huge changes to the code base. Later when Pandoc's table model was changed the new table model included attributes. Code needs attributes to allow to attach highlighting information to it, and headings and images need them too for various reasons, and links probably came along for the ride together with images. Normally divs and spans are enough for all other cases, because in regular CSS in an external file or embedded in the `` of an HTML document you can use a child selector, e.g. in Markdown you type ``````markdown :::class **** ::: `````` and then you style the rule with ``````css div.class hr { ... } `````` Your imposed limitation of not being able to use external CSS creates problems which most users simply don't have. For the horizontal rule case you can use a raw block to insert the HTML directly, if you are not going to generate other formats from the source: ``````markdown Para before. ```{=html}
``` Para after `````` You can also use a filter to do things like this: ``````lua local hr_filter = { HorizontalRule = function() return pandoc.RawBlock('html', '
') end } function Div(div) if div.classes:includes('class') then return div:walk(hr_filter).content end end `````` I sometimes post-process HTML generated by pandoc with with Mojo::Dom < https://metacpan.org/pod/Mojo::DOM> to transfer attributes from wrapping divs/spans to contained elements and remove the wrapper, or just to set attributes to elements contained in wrappers. The API makes such changes very easy. You basically find elements in an HTML document with CSS selectors, then loop through the found elements and change them in-place with Perl code. Adding/removing/changing attributes is very easy: you just treat the element object as if it is a hash (associative array) reference containing the attributes! Then when you are done you print the document object to a file or stdout. My example above is, after all, valid HTML code. I have for now worked > around it by creating the desired
tag in my code but it would be > much more elegant to to be able to add style information to HorizontalRule. > > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/b696e1f5-0648-c8f0-4117-257896e40f8b%40meddatainc.com > > . > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT%3DvfJcUuiRM-dHempA%40mail.gmail.com.