public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Inserting attributes into elements
Date: Wed, 14 Jun 2023 19:30:13 +0200	[thread overview]
Message-ID: <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA@mail.gmail.com> (raw)
In-Reply-To: <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 5652 bytes --]

Den ons 14 juni 2023 18:24H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> 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 <image ...> tag? This <image ...> tag is wrapped inside a <figure> tag.
>
>
> Besides adding a style to <img ...> (Image) elements, I also want to add a style to <hr /> (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:
>
> <hr style="border-top-style: solid; border-top-width: thin; border-color: #cc002b;" />
>
> 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 `<head>` 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}
<hr style="...">
```

Para after
``````

You can also use a filter to do things like this:

``````lua
local hr_filter = {
  HorizontalRule = function()
    return pandoc.RawBlock('html', '<hr style="...">')
  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 <hr ... /> 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
> <https://groups.google.com/d/msgid/pandoc-discuss/b696e1f5-0648-c8f0-4117-257896e40f8b%40meddatainc.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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.

[-- Attachment #2: Type: text/html, Size: 8774 bytes --]

  parent reply	other threads:[~2023-06-14 17:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 20:37 H
     [not found] ` <76a72c07-6699-d243-ae20-64808682ec9e-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-13 21:00   ` 'William Lupton' via pandoc-discuss
     [not found]     ` <CAEe_xxgeoT3UjKy0vK2b_w87d-ovNgpL_gRdyDeyb6+4SztxQA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-06-13 21:16       ` H
     [not found]         ` <F6DC033A-83F1-48E8-9947-A372BB0366E7-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-13 21:19           ` H
     [not found]             ` <90C7A30F-C0FA-49D8-B0CD-6521B58113F1-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-13 21:27               ` Bastien DUMONT
2023-06-13 21:38                 ` 'William Lupton' via pandoc-discuss
     [not found]                   ` <CAEe_xxj=P-e03Z6A4BbbqyCAdiCgpxs3cGR8WH_P590Q+bQkWg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-06-13 21:58                     ` H
     [not found]                       ` <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-14  6:38                         ` 'William Lupton' via pandoc-discuss
2023-06-13 22:05                 ` H
     [not found]                   ` <0a6aa41a-fe72-a1e8-2630-ec6070c0bbb3-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-13 22:53                     ` H
     [not found]                       ` <74253f39-02db-dc2e-2ae1-9d27aaab82ea-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-14  0:34                         ` H
     [not found]                           ` <61724767-ada0-133f-6751-5884c7460a25-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-14  6:49                             ` Bastien DUMONT
2023-06-14 16:23                               ` H
     [not found]                                 ` <b696e1f5-0648-c8f0-4117-257896e40f8b-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-14 17:30                                   ` BPJ [this message]
     [not found]                                     ` <CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-06-15  1:19                                       ` H
     [not found]                                         ` <37d8c191-388e-164e-6955-9014b4f0a4a0-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
2023-06-15 10:13                                           ` 'William Lupton' via pandoc-discuss
2023-06-15 13:00                                           ` BPJ
     [not found]                                             ` <CADAJKhBjJTZki4np=oSfbbcmtBjEahCU4440tRfOh_6TMzSAYw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-06-16  1:12                                               ` H

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADAJKhDMVj8SknY2u1mnGOsbQG59sAJqT=vfJcUuiRM-dHempA@mail.gmail.com' \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).