tlienart / Franklin.jl

(yet another) static site generator. Simple, customisable, fast, maths with KaTeX, code evaluation, optional pre-rendering, in Julia.
https://franklinjl.org
MIT License
952 stars 112 forks source link

Custom preprocess function for Literate.jl? #639

Open tkf opened 3 years ago

tkf commented 3 years ago

I have a preprocess function (LiterateTest.preprocess) for Literate.jl to strip out test-related code from Literate.jl-compatible source code.

From a quick look, it does not look like Franklin.jl provide a way to pass this to Literate.jl:

https://github.com/tlienart/Franklin.jl/blob/b014623720be8de65d46e21db9e5823ce8d28b92/src/eval/literate.jl#L39-L46

Can we have an API to pass the configuration to Literate.jl?

tlienart commented 3 years ago

Hello @tkf I'm happy to support something like this yes, how would you envisage the entry point? in the config or something? maybe better is to do that at deployment level and so it could be an argument to the optimize function.

Note that in the data science tutorials, I do that at the deployment stage: e.g.: https://github.com/alan-turing-institute/DataScienceTutorials.jl/blob/master/deploy.jl maybe some of it would be useful for your case too

tkf commented 3 years ago

Hi @tlienart. Thanks for the pointer!

Actually, I implemented yet another mechanism to test the correctness of the code using lx_* functions/CSS/etc.: https://juliafolds.github.io/data-parallelism/previews/PR8/tutorials/quick-introduction/?test=show#iterator_comprehensions. So, it's low-priority for me ATM.

(BTW, thanks a lot for creating such a customizable system! Now that started to understand how things work, I'm very excited about flexibility of Franklin.jl!)

In a long run, I started to wonder if it makes to add in-file configuration in Literate.jl itself (cc @fredrikekre). This way, we can reuse the configuration mechanism everywhere (standalone Literate.jl usage and also with Documenter.jl). For example, we can evaluate the following code block and use preprocess defined here as the default keyword option preprocess of Literate.markdown etc.:

#src ```literate-jl
#src preprocess(code) = "using Compat\n" * code
#src ```

If Franklin.jl-specific entrypoint is desirable, is it feasible to implement something like

\literate{
    /_literate/script.jl;
    preprocess = my_preprocess_function,
}

where my_preprocess_function resolved in the namespace in which utils.jl is evaluated?