Git Product home page Git Product logo

Comments (5)

mbutterick avatar mbutterick commented on June 17, 2024

You could parse the contents of the ul tag function as markdown. See related example.

from pollen-users.

Eugleo avatar Eugleo commented on June 17, 2024

Thanks, that’s a nice idea! Now that I’m thinking about it, I could also run my own small list-parser, to be able to extend it with additional bullet point types. However, what I didn’t understand from the issue you’ve linked, nor from the discussion on the old mailing list, is whether it is possible to use pollen tags inside that kind of environment (and additionaly how to do it).

◊parse-list{
- first item
- second,
    ◊bold{multiline}
    item
        - first item
        - second,
            multiline
            item
}

from pollen-users.

mbutterick avatar mbutterick commented on June 17, 2024

The tricky issue is how you transmit the result of a tag function, which is an X-expression, through a block of Markdown, which doesn’t know anything about X-expressions. @otherjoel had a clever idea to convert the X-expression to HTML, which will pass through the Markdown parser intact.

Another idea is to make your bold tag function behave differently within a parse-list — it could emit the Markdown-compliant **multiline** rather than '(strong "multiline").

from pollen-users.

Eugleo avatar Eugleo commented on June 17, 2024

The idea with HTML is a good one, thanks.

from pollen-users.

mbutterick avatar mbutterick commented on June 17, 2024

For posterity, here is the original example of reapplying tag functions with eval:

"test.html.pm"

#lang pollen

Hello _world_!

"pollen.rkt"

#lang racket
(require (only-in markdown parse-markdown)
         pollen/decode pollen/tag txexpr/stx
         (prefix-in pt: pollen/top))

(provide (all-defined-out))

(define-tag-function (em attrs elems)
  `(my-em ,attrs  "--Never a dull moment!--" ,@elems))

(define (reapply-tags stx)
  (with-syntax ([XEXPR (let loop ([stx stx])
                         (if (stx-txexpr? stx)
                             (with-syntax ([TAG (stx-txexpr-tag stx)]
                                           [ATTRS (stx-txexpr-attrs stx)]
                                           [ELEMS (map loop (stx-txexpr-elements stx))])
                               #'(TAG 'ATTRS . ELEMS))
                             stx))])
    #'(let-syntax ([#%top (make-rename-transformer #'pt:#%top)])
        XEXPR)))
  
(define (root . xs)
  (define marked-down (decode-elements xs #:string-proc parse-markdown))
  (eval (reapply-tags `(body ,@marked-down))))

What happens here:

  1. Here, the source is not a pollen/markdown dialect. Rather, the Markdown parsing happens in the root function (this is just for the sake of the example — IRL you wouldn’t do it this way — you’d just attach parse-markdown to certain tags)

  2. The result of this parse is an X-expression that looks like this:
    '(body (p () "Hello " (em () "world") "!"))

  3. Then we reapply-tags by using this X-expression as a parse tree and passing it through eval.

  4. In principle you can do this as many times as you want, thereby extending what would ordinarily be one runtime evaluation into more.

  5. There may be a way to do this at compile time too — say, by running parse-markdown as part of a macro rather than a tag function, but that may incur other difficulties I’m not considering for now.

from pollen-users.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.