serialising txexprs? #117

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

Hi, I'm trying to create pages that contain a list of other pages. Like a subject outline and description followed by a list of pages containing material.

In my html template I save metadata to an sqlite database, and in the subject outline I can pick up that data for every page. The problem is that some of the data I want to store, like the title and abstract, can contain arbitrarily nested txexprs. Two possible approaches I've tried but not managed to get working are

  • convert the fields to html in the template with ->html and store that. Then I include those strings in the outline page.
  • serialize the txexprs and store, then deserialize them and insert into the page tags to be interpreted in the usual way.

For the first, I just get the html tags in the text as strings not as html code, which I guess makes sense. The second approach seems more general but I don't know how to serialize some nested txexprs to a string that sqlite accepts. Anyone have some pointers I could try?

Hi, I'm trying to create pages that contain a list of other pages. Like a subject outline and description followed by a list of pages containing material. In my html template I save metadata to an sqlite database, and in the subject outline I can pick up that data for every page. The problem is that some of the data I want to store, like the title and abstract, can contain arbitrarily nested txexprs. Two possible approaches I've tried but not managed to get working are - convert the fields to html in the template with `->html` and store that. Then I include those strings in the outline page. - serialize the txexprs and store, then deserialize them and insert into the page tags to be interpreted in the usual way. For the first, I just get the html tags in the text as strings not as html code, which I guess makes sense. The second approach seems more general but I don't know how to serialize some nested txexprs to a string that sqlite accepts. Anyone have some pointers I could try?
otherjoel commented 3 years ago (Migrated from github.com)

If you write the txexpr to a string, you will be able to read it back in again!

Read those docs carefully and experiment a bit in a REPL. They operate on ports, not strings, so you will need to convert your strings to ports with, e.g., open-input-string and open-output-string.

If you [`write`][1] the txexpr to a string, you will be able to [`read`][2] it back in again! Read those docs carefully and experiment a bit in a REPL. They operate on ports, not strings, so you will need to convert your strings to ports with, e.g., `open-input-string` and `open-output-string`. [1]: https://docs.racket-lang.org/reference/Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29 [2]: https://docs.racket-lang.org/reference/Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29
aalexei commented 3 years ago (Migrated from github.com)

Ahh, thank you for that! Got it working nicely. My bouncing around the docs and experimenting in a REPL just wasn't finding how to connect strings and ports together.

Ahh, thank you for that! Got it working nicely. My bouncing around the docs and experimenting in a REPL just wasn't finding how to connect strings and ports together.
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
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-users#117
Loading…
There is no content yet.