smart-quotes fails when surrounding pollen markup #157

Closed
opened 6 years ago by clozach · 1 comments
clozach commented 6 years ago (Migrated from github.com)

Encountered this issue while working through the tutorial.

Steps to reproduce
pollen.rkt

#lang racket
(require pollen/decode)
(provide (all-defined-out)) ;Implicit
(define (root . elements)
   `(root ,@(decode-elements elements
      #:txexpr-elements-proc decode-paragraphs
      #:string-proc (compose1 smart-quotes smart-dashes)
      )))

article.html.pm

#lang pollen

This "word" and this 'word' get smart-quotes.

This "◊code{word}" and this '◊code{one}' don't.

output

<body>
  <root>
    <p>This “word” and this ‘word’ get smart-quotes.</p>
    <p>This "<code>word</code>" and this '<code>one</code>' don’t.</p>
  </root>
</body>

With this carefully-prepared example, the quotes surrounding the two ◊coded words just remain "dumb" quotes.


Even if the above behavior is intentional (and if it is, what's the workaround if one actually wants pretty quotes around markup?), the example below demonstrates a definite bug whereby smart-quotes seems to be only partially applied.

pollen.rkt

#lang racket
(require pollen/decode pollen/misc/tutorial txexpr)
;(provide author _) Explicit
(provide (all-defined-out)) ;Implicit

;Constants
(define author "Trevor Goodchild")

;HTML
(define (_ . elements)
  (txexpr 'em empty elements))

(define (root . elements)
   `(root ,@(decode-elements elements
      #:txexpr-elements-proc decode-paragraphs
      #:string-proc (compose1 smart-quotes smart-dashes)
      )))

article.html.pm

#lang pollen

The "first" line of the 'first' paragraph.
And a new line.

The "◊code{root}" tag is now called '◊code{content}'.
This should have a <br> before it.

The author is — ◊_{◊|author|}.

output

<body>
  <root>
    <p>The “first” line of the ‘first’ paragraph.
      <br>And a new line.</p>
    <p>The "<code>root</code>" tag is now called '<code>content</code>‘.
      <br>This should have a &lt;br&gt; before it.</p>
    <p>The author is—<em>Trevor Goodchild</em>.</p>
  </root>
</body>

Note the opening curly-single-quote after <code>content</code>.

Encountered this issue while working through the [tutorial](https://docs.racket-lang.org/pollen/third-tutorial.html#(part._tutorial-3._.Introducing__pollen_rkt_)). **Steps to reproduce** _pollen.rkt_ ```racket #lang racket (require pollen/decode) (provide (all-defined-out)) ;Implicit (define (root . elements) `(root ,@(decode-elements elements #:txexpr-elements-proc decode-paragraphs #:string-proc (compose1 smart-quotes smart-dashes) ))) ``` _article.html.pm_ ```pollen #lang pollen This "word" and this 'word' get smart-quotes. This "◊code{word}" and this '◊code{one}' don't. ``` _output_ ```html <body> <root> <p>This “word” and this ‘word’ get smart-quotes.</p> <p>This "<code>word</code>" and this '<code>one</code>' don’t.</p> </root> </body> ``` With this carefully-prepared example, the quotes surrounding the two `◊coded` words just remain "dumb" quotes. ---- Even if the above behavior is intentional (and if it is, what's the workaround if one actually _wants_ pretty quotes around markup?), the example below demonstrates a definite bug whereby smart-quotes seems to be only partially applied. _pollen.rkt_ ```racket #lang racket (require pollen/decode pollen/misc/tutorial txexpr) ;(provide author _) Explicit (provide (all-defined-out)) ;Implicit ;Constants (define author "Trevor Goodchild") ;HTML (define (_ . elements) (txexpr 'em empty elements)) (define (root . elements) `(root ,@(decode-elements elements #:txexpr-elements-proc decode-paragraphs #:string-proc (compose1 smart-quotes smart-dashes) ))) ``` _article.html.pm_ ```pollen #lang pollen The "first" line of the 'first' paragraph. And a new line. The "◊code{root}" tag is now called '◊code{content}'. This should have a <br> before it. The author is — ◊_{◊|author|}. ``` _output_ ```html <body> <root> <p>The “first” line of the ‘first’ paragraph. <br>And a new line.</p> <p>The "<code>root</code>" tag is now called '<code>content</code>‘. <br>This should have a &lt;br&gt; before it.</p> <p>The author is—<em>Trevor Goodchild</em>.</p> </root> </body> ``` Note the _opening_ curly-single-quote after `<code>content</code>`.
mbutterick commented 6 years ago (Migrated from github.com)

The behavior is correct. If you want smart-quotes to handle quotes that span multiple elements, you need to attach smart-quotes to decode-elements as a #:txexpr-proc, not as a #:string-proc.

Consider what’s happening in this X-expression:

'(p "This \"" (code "word") "\" and this '" (code "one") "' don’t.")

The p has five elements — three strings and two tagged X-expressions (each of which contains a string). If you use #:string-proc, then smart-quotes processes each of these five strings individually (and consequently doesn’t see any pairs of quotes). Whereas when you use #:txexpr-proc, it looks at the p tag as a whole, and then notices the pairs.

The behavior is correct. If you want `smart-quotes` to handle quotes that span multiple elements, you need to attach `smart-quotes` to `decode-elements` as a `#:txexpr-proc`, not as a `#:string-proc`. Consider what’s happening in this X-expression: ``` '(p "This \"" (code "word") "\" and this '" (code "one") "' don’t.") ``` The `p` has five elements — three strings and two tagged X-expressions (each of which contains a string). If you use `#:string-proc`, then `smart-quotes` processes each of these five strings individually (and consequently doesn’t see any pairs of quotes). Whereas when you use `#:txexpr-proc`, it looks at the `p` tag as a whole, and then notices the pairs.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
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#157
Loading…
There is no content yet.