On Apr 6, 2016, at 9:31 AM, Li Junsong <
ljs.da...@gmail.com> wrote:
> (select 'simple-tag doc) is affected by the transformation of tag function on simple-tag. I sometimes think `select` (or select-from-doc) function actually should apply on the original doc that tag functions haven't applied yet. That is, (select 'title doc) actually means get the contents of my semantic tag 'title. If my title later converts to h1, or h*, select won't be affected. This definitely complicates Pollen though.
It's a fair point. But when you say that you want "the original doc that tag functions haven't applied yet," that amounts to running the Pollen source file while pretending pollen.rkt doesn't exist. This would solve certain problems, but create others.
Another approach would be to divide your processing into semantic and non-semantic. Remember, when your Pollen source file gets rendered with a template, there are essentially two rounds of processing. The first round is when the source file itself is run, and the `doc` and `metas` exports are produced. The second round is when the template code is run, with the `doc` and `metas` available.
For instance, consider this toy example. When you run "
test.html.pm", it will still have `simple-tag` in the `doc`, and `(select 'simple-tag doc)` will get you "My Title". But when you render the file in the project server, the template will send it through a decoder to convert `simple-tag` to `h1`.
;;;;;;;; "
test.html.pm"
#lang pollen
◊simple-tag{My Title}
That's all.
;;;;;;;; "template.html.p"
<html>
◊(->html (remove-semantic-tags doc))
</html>
;;;;;;;; "pollen.rkt"
#lang racket/base
(require txexpr pollen/decode)
(provide (all-defined-out))
(define (convert-title tx)
(if (eq? (get-tag tx) 'simple-tag)
`(h1 ((class "title")) ,@(get-elements tx))
tx))
(define (remove-semantic-tags doc)
(decode-elements doc #:txexpr-proc convert-title))