Tips to write lists
#21
Open
opened 5 years ago by Eugleo
·
5 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
I know the traditional Pollen way of writing lists would be someting like this
But that is rather hard to read, I think. I managed to get something like this working
But now the code is hard to extend (i.e. by adding a new kind of bullet, or adding ordered sections). I’m wondering if any of you have already met the same problem and how did you slove it. It could be a concrete piece of code, or even some best-practices regarding these “semi-markdown tags” that you learned the hard way.
You could parse the contents of the
ul
tag function as markdown. See related example.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).
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 aparse-list
— it could emit the Markdown-compliant**multiline**
rather than'(strong "multiline")
.The idea with HTML is a good one, thanks.
For posterity, here is the original example of reapplying tag functions with
eval
:"test.html.pm"
"pollen.rkt"
What happens here:
Here, the source is not a
pollen/markdown
dialect. Rather, the Markdown parsing happens in theroot
function (this is just for the sake of the example — IRL you wouldn’t do it this way — you’d just attachparse-markdown
to certain tags)The result of this parse is an X-expression that looks like this:
'(body (p () "Hello " (em () "world") "!"))
Then we
reapply-tags
by using this X-expression as a parse tree and passing it througheval
.In principle you can do this as many times as you want, thereby extending what would ordinarily be one runtime evaluation into more.
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.