not insert <br> for single linebreak #41

Closed
opened 4 years ago by adamfeuer · 5 comments
adamfeuer commented 4 years ago (Migrated from github.com)

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:

◊p{First sentence.
Second sentence.
Third sentence.}

I get this output:

<p>First sentence<br>
Second sentence.<br>
Third sentence.</p>

But I want this:

<p>First sentence Second sentence. Third sentence.</p>
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: ``` ◊p{First sentence. Second sentence. Third sentence.} ``` I get this output: ``` <p>First sentence<br> Second sentence.<br> Third sentence.</p> ``` But I want this: ``` <p>First sentence Second sentence. Third sentence.</p> ```
otherjoel commented 4 years ago (Migrated from github.com)

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?

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`](https://docs.racket-lang.org/pollen/Decode.html#%28def._%28%28lib._pollen%2Fdecode..rkt%29._decode-paragraphs%29%29) [edit: or `decode-linebreaks`] in your `pollen.rkt` or other required modules?
adamfeuer commented 4 years ago (Migrated from github.com)

@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 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...
adamfeuer commented 4 years ago (Migrated from github.com)

@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?

@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?
mbutterick commented 4 years ago (Migrated from github.com)

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).

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: ```racket #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).
adamfeuer commented 4 years ago (Migrated from github.com)

@otherjoel @mbutterick Thank you both!

@otherjoel @mbutterick Thank you both!
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#41
Loading…
There is no content yet.