Closed adamfeuer closed 4 years ago
Yes, there is a way to do this; in fact, the desired behavior you describe is the default behavior unless you write code to change it. Are you by chance using decode-paragraphs
[edit: or decode-linebreaks
] in your pollen.rkt
or other required modules?
@otherjoel Yes, here's an excerpt from my pollen.rkt
:
(define (root . elements)
(txexpr 'root empty (decode-elements elements
#:txexpr-elements-proc decode-paragraphs
#:string-proc (compose1 smart-quotes smart-dashes))))
I'm a pollen and racket newbie, so I'm not sure what all that does. I put that together after reading the pollen tutorials...
@otherjoel Ah, I see. The root
tag function is decoding everything when it shouldn't. If I take out the decode-paragraphs
pollen now does what I want.
When is the right time to add decode-paragraphs
? Where is it usually used?
By default, decode-paragraphs
will also invoke the default decode-linebreaks
for single newlines. If you don’t want that behavior, you can supply a #:linebreak-proc
procedure that will just leave them alone. For instance:
#lang racket
(require pollen/decode rackunit)
(check-equal?
(decode-paragraphs '("para1" "\n\n" "para2 line1" "\n" "para2 line2"))
'((p "para1") (p "para2 line1" (br) "para2 line2")))
(check-equal?
(decode-paragraphs '("para1" "\n\n" "para2 line1" "\n" "para2 line2")
#:linebreak-proc (λ (x) x))
'((p "para1") (p "para2 line1" "\n" "para2 line2")))
You could also replace the linebreaks with a single space " "
. Note, however, that you wouldn’t want to delete them entirely, because the resulting HTML would be rendered without any space between lines (try it and see).
@otherjoel @mbutterick Thank you both!
Hi,
Is there a way to get pollen to not insert
<br>
tags for single linebreaks? That way I can write text with linebreaks in my editor, but use CSS to flow text when it gets rendered to html.Right now if I enter this:
I get this output:
But I want this: