public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: "'Saku Laesvuori' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Syntactically extensible markdown - would something like this work well with pandoc?
Date: Tue, 16 Aug 2022 20:30:30 +0300	[thread overview]
Message-ID: <20220816173030.ijdjy3dxkj2monm5@X-kone> (raw)
In-Reply-To: <9910f586-ee3f-4719-afc4-dd95ffe6e46an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>

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

> but pattern matching will fail if the inner details content is anything but 
> the simplest markup.
> Ideally I would do something like "the first block goes in the summary and 
> the rest gets rendered as usual outside". But I couldn't figure out how to 
> do that - could you give me any ideas?

> details :: Maybe Format -> Block -> Block
> details (Just format) x@(Div (_id, classes, _attributes) [Para [Str summary], Para [Str spoiler]]) = 
>   case "details" `elem` classes of
>     True
>       | format == Format "html" -> RawBlock format $
>         "<details>" <> "<summary>" <> summary <> "</summary>" <> spoiler <> "</details>"
>       | otherwise -> x
>     _ -> x
> details _ x = x

Instead of pattern matching on a list of Para elements with a single
Str element, try matching the head and tail of the list `x@(Div (_id,
classes, _attributes) summary:details)`. Then you can render the summary
and details blocks to html (Text.Pandoc.Writers.HTML).

> (by the way, I'm a very newbie haskeller, so any advice on code style is 
> also welcome, but not required)

You could use guards instead of the case ... of block and test for the
format in pattern matching:

```
details (Just format@(Format "html")) x@(Div ...)
  | "details" `elem` classes = RawBlock format $ ...
  | otherwise = x
details _ x = x
```

  parent reply	other threads:[~2022-08-16 17:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-09 20:15 Daniel Littlewood
     [not found] ` <8645831f-c1c6-4dba-b1af-f63f1e830821n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-09 22:57   ` John MacFarlane
     [not found]     ` <D0F90C99-14A6-42D8-A422-7AF5C9FAB8D7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-08-10 11:55       ` Jiří Wolker
     [not found]         ` <b76f3a32-6922-c132-f999-407b460b30b9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-08-14 21:24           ` Daniel Littlewood
     [not found]             ` <9910f586-ee3f-4719-afc4-dd95ffe6e46an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-16 17:30               ` 'Saku Laesvuori' via pandoc-discuss [this message]
2022-08-17  6:54               ` Daniel Littlewood
     [not found]                 ` <71e804e9-be81-43fc-8c40-4e7a1ce77e1fn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-17  9:41                   ` BPJ

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=20220816173030.ijdjy3dxkj2monm5@X-kone \
    --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).