> On Jan 7, 2017, at 1:39 PM, Oliver Taylor <[email protected]> wrote:
> 
> It doesn’t seem that Pollen parses Pollen markup when in markdown-authoring 
> mode. The following does’t work

Right. Pollen has two mutually exclusive authoring modes: Markdown, or Pollen 
markup.

http://docs.racket-lang.org/pollen/second-tutorial.html#%28part._.Authoring_mode%29
 
<http://docs.racket-lang.org/pollen/second-tutorial.html#(part._.Authoring_mode)>



> 
> TEST.html.pmd
> 
> #lang pollen
> ◊(define (sc . words) `(span [[class "small-caps"]] ,@words))
> 
> ## Welcome to ◊sc{CIA}
> 
> - Introduction to ◊sc{CIA}
> - ◊sc{CIA} History


When you invoke Markdown authoring mode, Pollen expects Markdown as input, and 
compiles this to an X-expression. The problem here is that you're trying to 
embed X-expressions in Markdown first. This won't work. 

But you can use tag functions that emit Markdown:

#lang pollen
◊(require racket/string)
◊(define (sc . words) (string-append "**" (string-join words "") "**"))

## Welcome to ◊sc{CIA}

- Introduction to ◊sc{CIA}
- ◊sc{CIA} History


You might object: "But ** doesn't mean small caps in Markdown." True, but there 
are no small caps in Markdown. This is one of the reasons I dislike Markdown: 
it's not author-extensible.

http://docs.racket-lang.org/pollen/second-tutorial.html#%28part._the-case-against-markdown%29
 
<http://docs.racket-lang.org/pollen/second-tutorial.html#(part._the-case-against-markdown)>
 



> It occurs to me that I might be able to to create a ◊markdown tag to parse 
> markdown within or attach markdown decoding to Pollen’s root tag. 

You can use the `parse-markdown` function from the `markdown` package (included 
with Pollen) to decode Markdown from within a tag function:

#lang pollen
◊(require racket/string (only-in markdown parse-markdown) txexpr)
◊(define (markdown . words)
   (txexpr '@ null (parse-markdown (string-join words))))

◊markdown{## Welcome to CIA

 - Introduction to CIA
 - CIA History}




> Or maybe what I need is a way to tweak how decode-paragraphs works, and how 
> to easily generate lists in Pollen without typing all this out:
> 
> ◊ul{
>     ◊li{Item One}
>     ◊li{Item Two}
>     ◊li{Item Three}
> }

Here's an example of a tag function that detects list items:

http://docs.racket-lang.org/pollen-tfl/_pollen_rkt_.html#%28def._%28%28lib._pollen-tfl%2Fpollen..rkt%29._detect-list-items%29%29
 
<http://docs.racket-lang.org/pollen-tfl/_pollen_rkt_.html#(def._((lib._pollen-tfl/pollen..rkt)._detect-list-items))>


Here's another:

#lang pollen
◊(require pollen/decode txexpr)
◊(define (my-list . items)
   `(ul ,@(map (λ(item) `(li ,item))
               (filter (λ(x) (not (equal? "\n" x))) items))))

◊my-list{
 Item one
 Item two
 Item three
}



> 
> The reason I don’t like the decode-paragraphs implementation is that I write 
> using “Semantic Linefeeds”. Where newlines are ignored within paragraphs 
> (like Markdown, HTML, reStructuredText, etc.). Like this:
> 
>> Four score and seven years ago
>> our fathers brought forth on this continent,
>> a new nation, conceived in Liberty,
>> and dedicated to the proposition that
>> all men are created equal.
> 
> 


This is getting into somewhat fancier sauce, but you can use the 
#:linebreak-proc argument in `detect-paragraphs` to change how newlines are 
handled:


#lang pollen/markup
◊(require pollen/decode racket/string)

◊(define (replace-newlines-with-spaces xs)
   (list (string-join (filter (λ(x) (not (equal? "\n" x))) xs) " ")))

◊(define (root . xs)
   `(root
     ,@(decode-paragraphs xs #:linebreak-proc replace-newlines-with-spaces)))

Four score and seven years ago
our fathers brought forth on this continent,
a new nation, conceived in Liberty,
and dedicated to the proposition that
all men are created equal.


> Sadly, I have no idea how to do this. I’m not much of a programmer.

Study the `pollen-tfl` sample project:

http://docs.racket-lang.org/pollen-tfl/ 
<http://docs.racket-lang.org/pollen-tfl/>

For language concepts, read through some of the "explainers" on Beautiful 
Racket:

http://beautifulracket.com/#explainers <http://beautifulracket.com/#explainers>


-- 
You received this message because you are subscribed to the Google Groups 
"Pollen" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to