Rendering sequential txexprs #158

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

I'm fairly new to lisp, and I may have coded a tag rendering procedure incorrectly.

I have a css/html element that I need to format as three sequential tags. (For reference, it's the sidenote element in the Tufte CSS (see https://edwardtufte.github.io/tufte-css/)).

Effectively, I need to render a sidenote tag as three sequential sets of tags.

◊sidenote{This is my sidenote}
<label  for="sn-demo"></label>
<input type="checkbox" id="sn-demo" class="margin-toggle"/>
<span class="sidenote">This is my sidenote</span>

I can format the above into a valid txexpr with sequential elements---by using a list append for txexpr elements. However, pollen seems to test for individual txexpr elements (txexpr-element?) when rendering in html. It seems that it could be useful to insert multiple sequential elements during processing. However, the current behavior of rendering a single element might be the desired behavior.

In any case, I thought I'd post this issue, since it may be a useful bug to fix. I'd assist, but I'm still a week away from becoming a decent lisper.

(I can of course get around this by creating rending the txexpr with strings.)

Thank you for your response, and thanks for making a great software package available.

I'm fairly new to lisp, and I may have coded a tag rendering procedure incorrectly. I have a css/html element that I need to format as three sequential tags. (For reference, it's the sidenote element in the Tufte CSS (see https://edwardtufte.github.io/tufte-css/)). Effectively, I need to render a sidenote tag as three sequential sets of tags. ``` ◊sidenote{This is my sidenote} ``` ``` <label for="sn-demo"></label> <input type="checkbox" id="sn-demo" class="margin-toggle"/> <span class="sidenote">This is my sidenote</span> ``` I can format the above into a valid ```txexpr``` with sequential elements---by using a list append for txexpr elements. However, pollen seems to test for individual ```txexpr``` elements (```txexpr-element?```) when rendering in html. It seems that it could be useful to insert multiple sequential elements during processing. However, the current behavior of rendering a single element might be the desired behavior. In any case, I thought I'd post this issue, since it may be a useful bug to fix. I'd assist, but I'm still a week away from becoming a decent lisper. (I can of course get around this by creating rending the txexpr with strings.) Thank you for your response, and thanks for making a great software package available.
otherjoel commented 6 years ago (Migrated from github.com)

Hi @jlorieau I ran into this precise puzzler when doing my own Pollen/Tufte CSS project.

In order to be a valid txexpr, the expression has to be a list with a symbol in the first position, followed by an optional list of attributes and then by any number of elements (any X-expressions). As you are finding, three sequential txexpr don't qualify as a single valid txexpr.

The solution is to use Pollen's @ splicing tag.

Here's the relevant snippet from my pollen.rkt:

`(@ (label [[for ,refid] [class "margin-toggle sidenote-number"]])
    (input [[type "checkbox"] [id ,refid] [class "margin-toggle"]])
    (span [(class "sidenote")] ,@text))]))

By wrapping the three tagged X-expressions in wrapped an @ tag you create a single valid txexpr. When this result gets placed into the doc, the @ evaporates leaving only its contents behind.

Hi @jlorieau I ran into this precise puzzler when doing my own Pollen/Tufte CSS project. In order to be a valid `txexpr`, the expression has to be a list with a symbol in the first position, followed by an optional list of _attributes_ and then by any number of _elements_ (any X-expressions). As you are finding, three sequential `txexpr` don't qualify as a single valid `txexpr`. The solution is to use [Pollen's `@` splicing tag](https://docs.racket-lang.org/pollen/Core.html#%28form._%28%28lib._pollen%2Fcore..rkt%29._~40%29%29). Here's the relevant snippet from [my `pollen.rkt`](https://github.com/otherjoel/try-pollen/blob/master/pollen.rkt): ~~~{racket} `(@ (label [[for ,refid] [class "margin-toggle sidenote-number"]]) (input [[type "checkbox"] [id ,refid] [class "margin-toggle"]]) (span [(class "sidenote")] ,@text))])) ~~~ By wrapping the three tagged X-expressions in wrapped an `@` tag you create a single valid `txexpr`. When this result gets placed into the `doc`, the `@` evaporates leaving only its contents behind.
jlorieau commented 6 years ago (Migrated from github.com)

Great, thanks!

Great, thanks!
mbutterick commented 6 years ago (Migrated from github.com)

FWIW this “splicing” problem also arises in ordinary Lisp / Scheme / Racket code. In that case, you would use begin to wrap the expressions, which allows them to behave syntactically as one S-expression, but at runtime the begin wrapper evaporates. The Pollen @ tag is analogous.

FWIW this “splicing” problem also arises in ordinary Lisp / Scheme / Racket code. In that case, you would use `begin` to wrap the expressions, which allows them to behave syntactically as one S-expression, but at runtime the `begin` wrapper evaporates. The Pollen `@` tag is analogous.
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#158
Loading…
There is no content yet.