How to hook a decode procedure as xexpr postprocessing
#11
Closed
opened 11 years ago by amirouche
·
7 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?
Héllo,
In the documentation, it's written that it's possible to hook a decode function to an xexpr. I did not find how. The documentation says it needs to be updated.
I want to use to do some typographic corrections, just like it's suggested in the decode documentation (replacing
"
with«
in french for instance, or using dashes to create item lists à la markdown or just create p tags for paragraphs...I have another problem, I use a template.html file with
◊->html{◊doc}
but it embeds aroot
node, see example at http://hypermove.fr/2014/why-nerfed.html#doc thediv#doc
child is aroot
node.My project is simple, the only "extra" feature I've written will browse a directory for blog posts and include them in the index page cf.
index-year
Thanks.
I've updated the documentation with an example of how I use
decode
.You should put
decode
(and other functions you write) in your "project-require.rkt" file (see Quick Tour for an explanation of this file)Replacing French quotes: yes, it would work like
smart-quotes
, mais vous devez le traduire en français, bien sûr;Detecting paragraphs: already part of the
decode
module, you can use that;Using dashes to create lists: yes, but I wouldn't put this in the main
decode
function. I would create a special tag for the list (e.g.,amirouche-list
) so in the markup it appears as◊amirouche-list{ ... }
. Then, in "project-require.rkt", you add a function(define (amirouche-list . items) ... )
. This function will automatically be applied to every◊amirouche-list{...}
. (You can use anotherdecode
within this function, if you like).Yes, you are correct that
◊->html{◊doc}
will embed aroot
node. That's just the default name for the main node of the data structure insidedoc
. You have two choices:ignore it (it will just be treated as an inline tag by web browsers);
rename it in your main
decode
function. So rather than this:Try something like this:
The problem with my suggestion (2) is that it pushes template logic down into your code, which you may not want to do.
A better idea: I just pushed a fix for the
->html
function that allows you to change the tag, or splice it into your page by passing keyword arguments. See the documentation for details.So instead of writing
◊->html{◊doc}
You can rename the tag and id by doing this:
◊->html[#:tag 'div #:attrs '((id "doc"))]{◊doc}
Or strip the outer tag by doing this
◊->html[#:splice #t]{◊doc}
I can't get paragraph displaying correctly. Everyline break is translated to a html br. I failed so far to rework pollen sources, can you help?
Can you show me your
decode
function?Here's a simple working example.
sample.html.pm
project-require.rkt
Output from sample.html.pm in DrRacket:
Thanks for the help, maybe I put it to good use later. I created something "similar" to Pollen in python for the time being https://github.com/amirouche/azoufzouf