wrap-hanging-quotes only wraps the first instance #246

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

New to Pollen, to Racket, to LISP, and even to hanging quotes, I’m surely doing something stupid. My apologies in advance.

I have this (copy-pasted) snippet inside pollen.rkt:

(define (root . items)
  (decode (txexpr 'root '() items)
          #:txexpr-elements-proc decode-paragraphs
          #:block-txexpr-proc (compose1 hyphenate wrap-hanging-quotes)
          #:string-proc (compose1 smart-quotes smart-dashes)
          #:exclude-tags '(style script)))

I process this:

#lang pollen

"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sollicitudin libero non arcu tincidunt, et sollicitudin odio consequat."

'Duis' elementum ante ut vulputate aliquam. Integer fermentum lacus nisi, bibendum fermentum velit tincidunt quis.

“Donec elementum, lacus in aliquam malesuada, tellus lectus placerat arcu, at vulputate mi purus id libero."

However, the resulting X-expression looks like this:

'(root
  (p
   (dquo
    "“"
    "Lorem ip\u00ADsum do\u00ADlor sit amet, con\u00ADsecte\u00ADtur adip\u00ADisc\u00ADing elit. Cur\u00ADabitur sol\u00ADlic\u00ADi\u00ADtudin libero non arcu tin\u00ADcidunt, et sol\u00ADlic\u00ADi\u00ADtudin odio con\u00ADse\u00ADquat.”"))
  (p
   "‘Duis’ el\u00ADe\u00ADmen\u00ADtum ante ut vulpu\u00ADtate ali\u00ADquam. In\u00ADte\u00ADger fer\u00ADmen\u00ADtum la\u00ADcus nisi, biben\u00ADdum fer\u00ADmen\u00ADtum velit tin\u00ADcidunt quis.")
  (p
   "“Donec el\u00ADe\u00ADmen\u00ADtum, la\u00ADcus in ali\u00ADquam male\u00ADsua\u00ADda, tel\u00ADlus lec\u00ADtus plac\u00ADer\u00ADat arcu, at vulpu\u00ADtate mi pu\u00ADrus id libero.”"))

That is, only the first gets wrapped.

I played with the composition order, and with the other keyword arguments of decode—all in vain.

Could someone lend me a hand?

Thank you so much!

New to Pollen, to Racket, to LISP, and even to hanging quotes, I’m surely doing something stupid. My apologies in advance. I have this (copy-pasted) snippet inside `pollen.rkt`: ``` (define (root . items) (decode (txexpr 'root '() items) #:txexpr-elements-proc decode-paragraphs #:block-txexpr-proc (compose1 hyphenate wrap-hanging-quotes) #:string-proc (compose1 smart-quotes smart-dashes) #:exclude-tags '(style script))) ``` I process this: ``` #lang pollen "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sollicitudin libero non arcu tincidunt, et sollicitudin odio consequat." 'Duis' elementum ante ut vulputate aliquam. Integer fermentum lacus nisi, bibendum fermentum velit tincidunt quis. “Donec elementum, lacus in aliquam malesuada, tellus lectus placerat arcu, at vulputate mi purus id libero." ``` However, the resulting X-expression looks like this: ``` '(root (p (dquo "“" "Lorem ip\u00ADsum do\u00ADlor sit amet, con\u00ADsecte\u00ADtur adip\u00ADisc\u00ADing elit. Cur\u00ADabitur sol\u00ADlic\u00ADi\u00ADtudin libero non arcu tin\u00ADcidunt, et sol\u00ADlic\u00ADi\u00ADtudin odio con\u00ADse\u00ADquat.”")) (p "‘Duis’ el\u00ADe\u00ADmen\u00ADtum ante ut vulpu\u00ADtate ali\u00ADquam. In\u00ADte\u00ADger fer\u00ADmen\u00ADtum la\u00ADcus nisi, biben\u00ADdum fer\u00ADmen\u00ADtum velit tin\u00ADcidunt quis.") (p "“Donec el\u00ADe\u00ADmen\u00ADtum, la\u00ADcus in ali\u00ADquam male\u00ADsua\u00ADda, tel\u00ADlus lec\u00ADtus plac\u00ADer\u00ADat arcu, at vulpu\u00ADtate mi pu\u00ADrus id libero.”")) ``` That is, only the first `“` gets wrapped. I played with the composition order, and with the other keyword arguments of `decode`—all in vain. Could someone lend me a hand? Thank you so much!
otherjoel commented 4 years ago (Migrated from github.com)

Looks like has to do with the order in which decode applies the different -proc functions. I.e. in your example (which admittedly comes straight from the docs) decode-paragraphs probably hasn’t added in all the paragraph elements before wrap-hanging-quotes is called.

I can get it to look right by breaking it up into two successive calls to decode, which allows us to control the order better:

(define (root . items)
  (define first-pass
    (decode (txexpr 'root '() items)
            #:txexpr-elements-proc decode-paragraphs
            #:block-txexpr-proc hyphenate
            #:string-proc (compose1 smart-quotes smart-dashes)
            #:exclude-tags '(style script)))
  (decode first-pass
          #:block-txexpr-proc wrap-hanging-quotes))

This results in:

'(root
  (p
   (dquo
    "“"
    "Lorem ip\u00ADsum do\u00ADlor sit amet, con\u00ADsecte\u00ADtur adip\u00ADisc\u00ADing elit. Cur\u00ADabitur sol\u00ADlic\u00ADi\u00ADtudin libero non arcu tin\u00ADcidunt, et sol\u00ADlic\u00ADi\u00ADtudin odio con\u00ADse\u00ADquat.”"))
  (p
   (squo
    "‘"
    "Duis’ el\u00ADe\u00ADmen\u00ADtum ante ut vulpu\u00ADtate ali\u00ADquam. In\u00ADte\u00ADger fer\u00ADmen\u00ADtum la\u00ADcus nisi, biben\u00ADdum fer\u00ADmen\u00ADtum velit tin\u00ADcidunt quis."))
  (p
   (dquo
    "“"
    "Donec el\u00ADe\u00ADmen\u00ADtum, la\u00ADcus in ali\u00ADquam male\u00ADsua\u00ADda, tel\u00ADlus lec\u00ADtus plac\u00ADer\u00ADat arcu, at vulpu\u00ADtate mi pu\u00ADrus id libero.”")))
Looks like has to do with the order in which `decode` applies the different `-proc` functions. I.e. in your example (which admittedly comes straight from the docs) `decode-paragraphs` probably hasn’t added in all the paragraph elements before `wrap-hanging-quotes` is called. I can get it to look right by breaking it up into two successive calls to `decode`, which allows us to control the order better: ```racket (define (root . items) (define first-pass (decode (txexpr 'root '() items) #:txexpr-elements-proc decode-paragraphs #:block-txexpr-proc hyphenate #:string-proc (compose1 smart-quotes smart-dashes) #:exclude-tags '(style script))) (decode first-pass #:block-txexpr-proc wrap-hanging-quotes)) ``` This results in: ```racket '(root (p (dquo "“" "Lorem ip\u00ADsum do\u00ADlor sit amet, con\u00ADsecte\u00ADtur adip\u00ADisc\u00ADing elit. Cur\u00ADabitur sol\u00ADlic\u00ADi\u00ADtudin libero non arcu tin\u00ADcidunt, et sol\u00ADlic\u00ADi\u00ADtudin odio con\u00ADse\u00ADquat.”")) (p (squo "‘" "Duis’ el\u00ADe\u00ADmen\u00ADtum ante ut vulpu\u00ADtate ali\u00ADquam. In\u00ADte\u00ADger fer\u00ADmen\u00ADtum la\u00ADcus nisi, biben\u00ADdum fer\u00ADmen\u00ADtum velit tin\u00ADcidunt quis.")) (p (dquo "“" "Donec el\u00ADe\u00ADmen\u00ADtum, la\u00ADcus in ali\u00ADquam male\u00ADsua\u00ADda, tel\u00ADlus lec\u00ADtus plac\u00ADer\u00ADat arcu, at vulpu\u00ADtate mi pu\u00ADrus id libero.”"))) ```
otherjoel commented 4 years ago (Migrated from github.com)

Some further notes: the code you see in the documentation for decode probably hasn’t been touched in a while, and might not be accurate to how Practical Typography works any more.

Also, it would be nice for that documentation to describe in more detail the order in which the different -proc functions are called, so it’s more obvious when multiple passes are needed. There are a couple of paragraphs that speak to this topic but there are some gaps in the timeline, so to speak:

Note that each element of an X-expression is subject to two passes through the decoder: once now, as a member of the list of elements, and also later, through its type-specific decoder (i.e., string-proc, entity-proc, and so on).

[…] If the X-expression meets the block-txexpr? test, it’s processed by block-txexpr-proc. Otherwise, it’s inline, so it’s processed by inline-txexpr-proc. […] Then both categories are processed by txexpr-proc.

If Matthew doesn’t do it first, I’ll go spelunking and maybe propose some edits to the docs.

Some further notes: the code you see in [the documentation for `decode`][1] probably hasn’t been touched in a while, and might not be accurate to how Practical Typography works any more. Also, it would be nice for that documentation to describe in more detail the order in which the different `-proc` functions are called, so it’s more obvious when multiple passes are needed. There are a couple of paragraphs that speak to this topic but there are some gaps in the timeline, so to speak: > Note that each element of an X-expression is subject to two passes through the decoder: once now, as a member of the list of elements, and also later, through its type-specific decoder (i.e., `string-proc`, `entity-proc`, and so on). > > […] If the X-expression meets the block-txexpr? test, it’s processed by block-txexpr-proc. Otherwise, it’s inline, so it’s processed by inline-txexpr-proc. […] Then both categories are processed by txexpr-proc. If Matthew doesn’t do it first, I’ll go spelunking and maybe propose some edits to the docs. [1]: https://docs.racket-lang.org/pollen/Decode.html#(def._((lib._pollen%2Fdecode..rkt)._decode))
mbutterick commented 4 years ago (Migrated from github.com)

I agree this example is obsolete. I have removed it. If you want to learn how to write tag functions, I recommend installing the pollen-tfl package and reading through its documentation.

I agree this example is obsolete. I have removed it. If you want to learn how to write tag functions, I recommend installing the `pollen-tfl` package and reading through its documentation.
mbutterick commented 4 years ago (Migrated from github.com)

Closing due to lack of activity. Please reopen if issue persists.

Closing due to lack of activity. Please reopen if issue persists.
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#246
Loading…
There is no content yet.