public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: "'William Lupton' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Inserting attributes into elements
Date: Wed, 14 Jun 2023 07:38:41 +0100	[thread overview]
Message-ID: <CAEe_xxg8edH5Jqj6CHUseoj2R1nE_W63DDtoF_m+8WfBcJomww@mail.gmail.com> (raw)
In-Reply-To: <CA9D2999-4E90-450E-A709-0ECCA45E3494-FcZObrvlYduBUy7/sJONFg@public.gmane.org>

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

This filter inserts a header before each paragraph.

-- https://pandoc.org/lua-filters.html#lua-filter-structure
function Para(para)
    return {
        -- https://pandoc.org/lua-filters.html#pandoc.header
        -- https://pandoc.org/lua-filters.html#type-attr
        pandoc.Header(2, 'Inserted header', {style='blablabla'}),
        para
    }
end

On Tue, 13 Jun 2023 at 23:00, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote:

> On June 13, 2023 5:38:18 PM EDT, 'William Lupton' via pandoc-discuss <
> pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote:
> >sorry; i was wrong when i said that i thought that you can't add style
> >attributes (i should have checked)
> >
> >of course the style attributes _are_ CSS, but i guess that this is ok
> >for
> >you
> >
> >what do you mean by 'rewriting' a tag?
> >
> >On Tue, 13 Jun 2023 at 22:27, Bastien DUMONT
> ><bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org>
> >wrote:
> >
> >> You call “insert” as if it were a method of “attr”, but attr is a
> >> key-value table. The correct way to add an attribute is:
> >>
> >> if (el.level == 2) then
> >>   local attr = el.attributes
> >>   attr.style = 'color: #112233;'
> >> end
> >>
> >>
> >> Le Tuesday 13 June 2023 à 05:19:14PM, H a écrit :
> >> > On June 13, 2023 5:16:32 PM EDT, H <agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org> wrote:
> >> >
> >> >     On June 13, 2023 5:00:19 PM EDT, 'William Lupton' via
> >pandoc-discuss
> >> >     <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote:
> >> >
> >> >         As far as I know, you can't add 'style' attributes. But you
> >can
> >> embed
> >> >         CSS via header-includes. You'll find an example of this if
> >you
> >> search
> >> >         the manual for 'header-includes' (and you can use a filter
> >to
> >> set the
> >> >         variable; I think Albert gave an example of how to do this
> >a few
> >> weeks
> >> >         ago).
> >> >
> >> >         On Tue, 13 Jun 2023, 21:37 H, <[1]agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org>
> >wrote:
> >> >
> >> >             Continuing my quest to write a custom filter, I now ran
> >into
> >> a need
> >> >             to add attributes to different types of tags as
> >exemplified
> >> below:
> >> >
> >> >             - In header tags such as <h2>, I need to add
> >"style=color:
> >> #112233;
> >> >             " so it becomes <h2 style="color: #112233;">.
> >> >
> >> >             - I analogously also need to add style information to
> >> <image> tags.
> >> >
> >> >             In my filter I tried:
> >> >
> >> >             style_h2 =
> >> >
> >> >             if (el.level == 2) then
> >> >                 local attr = el.attributes
> >> >                 attr.insert = style_h2
> >> >             end
> >> >
> >> >             but ended up with the below in my html output:
> >> >
> >> >             <h2
> >> >             data-insert=" style=&quot;text-transform: uppercase;
> >color: #
> >> >             cc002b;&quot;">
> >> >
> >> >             Clearly not the correct way. Can I add the style
> >information
> >> as
> >> >             above in a filter, in the pandoc function as I am going
> >> through my
> >> >             document block-by-block and modifying the document
> >structure
> >> as
> >> >             needed? I already adding <div> with various style
> >> information as I
> >> >             iterate over the blocks and that works fine but now I
> >need to
> >> >             modify existing tags.
> >> >
> >> >             I guess I could do it similarly to below but then it
> >applies
> >> to all
> >> >             eg H2:
> >> >
> >> >             function Header(el)
> >> >                 --    remove header identifier for all levels
> >> >                 el.identifier = ''
> >> >
> >> >                 --    convert level 1 and 2 to upper case
> >> >                 if (el.level == 1) or (el.level == 2) then
> >> >                     return el:walk {
> >> >                         Str = function(el)
> >> >                             return pandoc.Str(text.upper(el.text))
> >> >                         end
> >> >                     }
> >> >                 else
> >> >                     return el
> >> >                 end
> >> >             end
> >> >
> >> >             How to do it on individual H2 in a filter?
> >> >
> >> >             Thanks.
> >> >
> >> >             --
> >> >             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 [2]
> >> pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >> >             To view this discussion on the web visit [3]https://
> >> >             groups.google.com/d/msgid/pandoc-discuss/
> >> >             76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com.
> >> >
> >> >
> >> >     I need to stay away from css since the software the output is
> >used
> >> in does
> >> >     not allow css info to be added.
> >> >
> >> >
> >> > Can I "rewrite" a tag in the filter?
> >> >
> >> > --
> >> > 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 [4]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> >> > To view this discussion on the web visit [5]
> >> https://groups.google.com/d/msgid/
> >> >
> >pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%40meddatainc.com.
> >> >
> >> > References:
> >> >
> >> > [1] mailto:agents-FcZObrvlYduBUy7/sJONFg@public.gmane.org
> >> > [2] mailto:pandoc-discuss%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> >> > [3]
> >>
> >
> https://groups.google.com/d/msgid/pandoc-discuss/76a72c07-6699-d243-ae20-64808682ec9e%40meddatainc.com
> >> > [4] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> >> > [5]
> >>
> >
> https://groups.google.com/d/msgid/pandoc-discuss/90C7A30F-C0FA-49D8-B0CD-6521B58113F1%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/ZIjfUqabWGUWcZz2%40localhost
> >> .
> >>
>
> I used the phrase ”rewriting a tag” to mean creating a new tag from
> scratch. I then tried pandoc.Header() which does take up to three arguments
> but I could not create something similar to <H2 style=”blablabla”;>.
>
> How do I add style attributes as above?
>
> --
> 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/CA9D2999-4E90-450E-A709-0ECCA45E3494%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/CAEe_xxg8edH5Jqj6CHUseoj2R1nE_W63DDtoF_m%2B8WfBcJomww%40mail.gmail.com.

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

  parent reply	other threads:[~2023-06-14  6:38 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 [this message]
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
     [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=CAEe_xxg8edH5Jqj6CHUseoj2R1nE_W63DDtoF_m+8WfBcJomww@mail.gmail.com \
    --to=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).