tlienart / Xranklin.jl

Experimental repo for a refactoring of Franklin.jl
https://tlienart.github.io/Xranklin.jl
MIT License
40 stars 1 forks source link

Where are functions defined? Docstrings not found #265

Open gdalle opened 1 year ago

gdalle commented 1 year ago

Source code:

## Documentation

Even if your code does everything it is supposed to, it will be useless to others (and pretty soon to yourself) without proper documentation.
Adding [docstrings](https://docs.julialang.org/en/v1/manual/documentation/) everywhere needs to be a second nature.

```!
"""
    myfunc(a, b; kwargs...)

One-line sentence describing the purpose of the function,
just below the (indented) signature.

More details if needed.
"""
function myfunc end;

This way, readers and users of your code can query them through the REPL help mode:

myfunc


Result:
![image](https://github.com/tlienart/Xranklin.jl/assets/22795598/a72d060d-10d0-49eb-847d-d6677a4fd597)
tlienart commented 1 year ago

the offending lines are

https://github.com/tlienart/Xranklin.jl/blob/e8ffc37066e5de6fe03aaacb0ba7effacb1730b3/src/convert/markdown/rules/code.jl#L455-L456

I suspect the eval should be run in the page module, this one amounts to Main.eval(...).

could you try swapping this for lc.nb_code.mdl.eval(...)? (I can try myself but am away from my dev laptop)

gdalle commented 1 year ago

Nope, doesn't work, but no rush

tlienart commented 1 year ago

Hmm :'(

this:

julia> module A
       """
       abc
       """
       foo(x) = 0
       end
Main.A

help?> A.foo
  abc

julia> A.eval("@doc foo")
"@doc foo"

julia> A.eval(Meta.parse("@doc foo"))
  abc

works but there's likely something a bit subtle going on... might end up asking this one on Discourse, I don't understand well how docstrings are processed

gdalle commented 1 year ago

It's not just about docstrings, I also have the issue with modules

gdalle commented 1 year ago
Screenshot 2023-09-19 at 21 22 52
tlienart commented 1 year ago

hmm we're wading into tricky territory here in terms of how far Xranklin can go to make code execution inside a module look like the normal REPL, demoing pkg stuff is likely to be on the edge of that..

It looks like if the package is already in your dev path it should work though:

julia> lc = Xranklin.ToyLocalContext()

julia> s = """
       ```>
       using Pkg
       Pkg.develop(path="/Users/tlienart/.julia/dev/FP2")
       using FP2

       FP2.subs("abc", 2:3)
   """

julia> html(s, lc) |> println [ Info: ⏯️ evaluating cell auto_cell_1_1... [ Info: ⏯️ evaluating cell auto_cell_1_2... [ Info: ⏯️ evaluating cell auto_cell_1_3... [ Info: ⏯️ evaluating cell auto_cell_1_4...

julia> using Pkg

julia> Pkg.develop(path="/Users/tlienart/.julia/dev/FP2")
   Resolving package versions...
    Updating `~/.julia/dev/Xranklin/Project.toml`
  [c78977f6] + FP2 v0.1.0 `~/.julia/dev/FP2`
    Updating `~/.julia/dev/Xranklin/Manifest.toml`
  [67c07d97] + Automa v1.0.1
  [c78977f6] + FP2 v0.1.0 `~/.julia/dev/FP2`

julia> using FP2

julia> FP2.subs("abc", 2:3)
bc


maybe give me the full sequence of instructions here? if you take the users through a "create a package" step and then do as above it should work I think. But probably easier for me to try to reproduce this.
gdalle commented 1 year ago

The full sequence of instructions is here: https://github.com/modernjuliaworkflows/modernjuliaworkflows.github.io/blob/main/pages/sharing/sharing.md And strangely it seems to work online.

Honestly at this point it's an extremely niche problem so I wouldn't worry too much