Questions about templates and pollen.rkt

I used to write exclusively on Substack and copy and paste the horribly formatted text back into a google drive for safe keeping but I think pollen + git will be a better solution long term especially if I decide to leave the platform. I also want to serialize my content to a website that uses markdown for posts in addition to Substack, So I figured I’d create a pollen poly document that spits out an html file I can copy and paste into Substack, and a Markdown file. After running through the tutorial, I’m getting close to what I want except for a few issues.

  1. In my markdown document my emojis are not rendered correctly in the preview. For example I always put a line that starts with Call To Action :mega: at the end of my posts. When I look at the html version of the output it looks correct. But when I look at the markdown version it looks like this ## Call To Action 📣

Here is what my pollen.rkt file looks like

(define (cta . elements)
  (case (current-poly-target)
    [(md) `(,@elements ,call-text-md)]
    [else (txexpr 'p empty `(,@elements ,call-text))]))

How do I get the markdown version to render correctly like the html version? Is this just a markdown issue, or a Racket string issue?

  1. Still with the call to action, I’m having a hard time wrapping my head around how to get my cta to include a html link in the text. This works fine in my markdown version of the cta funnily enough. In my pollen.rkt I have two variables that store the text values for the cta
(define call-text-md "## Call To Action 📣\n
If you made it this far thanks for reading! If you are new welcome! I like to talk about technology, niche programming languages, AI, and low-level coding. If this interests you there's more where that came from on [my Substack](https://www.deusinmachina.net/). I’ve recently started a [Twitter](https://twitter.com/deusinmach) and would love for you to check it out. I also have a [Mastodon](https://mastodon.social/@DiegoCrespo) if that is more your jam. If you liked the article, consider liking and subscribing. And if you haven’t why not check out another article of mine! Thank you for your valuable time.")
(define call-text "Call To Action 📣\n
If you made it this far thanks for reading! If you are new welcome! I like to talk about technology, niche programming languages, AI, and low-level coding. If this interests you there's more where that came from on<a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://mastodon.social/@DiegoCrespo\">Mastodon</a>
. I’ve recently started a <a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://twitter.com/deusinmach\">Twitter</a> and would love for you to check it out. I also have a [Mastodon](https://mastodon.social/@DiegoCrespo) if that is more your jam. If you liked the article, consider liking and subscribing. And if you haven’t why not check out another article of mine! Thank you for your valuable time.")

As you can see I just naively embedd the <a tag into the text and it doesn’t do what I expect. How would I mix the tag with the text in the html version of the cta?

  1. I would eventually like to build out my pollen.rkt to support all of GitHub Flavored Markdown as an output, and think there is a better way to support the unordered and ordered list formats. Currently I do this
;; unorderd list
(define (item . elements)
  (case (current-poly-target)
    [(md) `("" ,@elements)]
    [else (txexpr 'ul empty elements)]))

;; unorderd list
(define (items . elements)
  (case (current-poly-target)
    [(md) `("\n* " ,@elements)]
    [else (txexpr 'li empty elements)]))

;; ordered list
(define (orditem . elements)
  (case (current-poly-target)
    [(md) `("" ,@elements)]
    [else (txexpr 'ol empty elements)]))

;; ordered list
(define (orditems . elements)
  (case (current-poly-target)
    [(md) `("\n1. " ,@elements)]
    [else (txexpr 'li empty elements)]))

Which works but is clunky. I’d like to just specify a keyword #:style that takes a value of 'unordered or 'ordered and then have logic in my pollen.rkt to handle the correct formatting, but I’m not sure how to do that. Does anyone know? Here is an example of what I mean

◊item[#: style 'unordered ◊items{We have cookies for you.}
          ◊items{If you want to eat a cookie,
                you must bring your own straw.}]

◊item[#: style 'ordered ◊items{We have cookies for you.}
          ◊items{If you want to eat a cookie,
                you must bring your own straw.}]
  1. Lastly exporting a .pm file to GitHub Flavored Markdown seems like a useful template (even if it’s an inferior format :wink:) so sharing this with people seems like the next step when I’m done. If I just extract the lines in my pollen.rkt file
    from this…
(define (h2 . elements)
  (case (current-poly-target)
    [(md) `("## " ,@elements)]
    [else (txexpr 'h2 empty elements)]))

(define (h2 . elements)
  `("## " ,@elements))

to this…

◊(require racket/list)
◊(define (h2 . elements)
  `("## " ,@elements))
...
◊(apply string-append (filter string? (flatten doc)))

and then add those lines to a template.md.p will that be enough to make this shareable for people who want to target gfm? Or will those functions need to go into a decode-elements block, and run on the doc before the ◊(apply string-append (filter string? (flatten doc))) line?

Btw Thank you @mbutterick for creating Pollen. I love writing stories using it.

Have you tried converting it to an HTML entity?

&#x1f4e3;

I’m not clear how you’re converting to HTML. If you’re using something like ->html, then the input needs to be an X-expression, and something like <a "foo"> should be (a "foo").

If you’re asking how you can support keyword arguments like #:style, you probably want to use define-tag-function rather than define, which will parse the keywords intro X-expression attributes.

I must plead ignorance on this one.

Thank you for the kind words!

Make sure you’re opening the Markdown file as UTF-8 text.