Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't include files in code blocks #257

Open
cserteGT3 opened this issue Aug 17, 2023 · 4 comments
Open

Can't include files in code blocks #257

cserteGT3 opened this issue Aug 17, 2023 · 4 comments
Labels
documentation Improvements or additions to documentation utils

Comments

@cserteGT3
Copy link

On my site I have a page, where I include a .jl file that contains many definitions. With Xranklin it doesn't work, and I don't understand why.
My MWE is the following:
julia file at _assets/test.jl:

function test()
    return "I am in _assets/test.jl"
end

My index page:

+++
title = "Home"
+++

This is my blog.

```julia:includetest
include("_assets/test.jl")
test()
```

\show{includetest}

But it is rendered as:


This is my blog.

include("_assets/test.jl")
test()
ERROR: UndefVarError: `include` not defined
Stacktrace:


I don't really understand what and why happens.

@tlienart
Copy link
Owner

Please try this:

```!
Base.include(@__MODULE__, "_assets/test.jl")
test()
```

long story short (might even be too short to fully get it), pages are modules themselves, it's not the REPL, so you need to be more explicit with your include (mentioning the @__MODULE__). As for the reason why we have to qualify Base., that's actually not clear to me, might need further investigation but I think we could just ignore it and expose an additional utils function that basically does include(x) = Base.include(@__MODULE__, x). I'll look into this but first please let me know if the above works for you.

@tlienart tlienart added documentation Improvements or additions to documentation utils labels Aug 18, 2023
@cserteGT3
Copy link
Author

Thanks!
Using Base.include(@__MODULE__, "_assets/test.jl") works perfectly. However it seems, that if I put it into utils.jl, it doesn't work. Maybe @__MODULE__ will point to the Utils module in that case?

@tlienart
Copy link
Owner

tlienart commented Aug 18, 2023

In utils.jl you should be able to just do

include("_assets/test.jl")  # say it defines `test()`

and call that anywhere e.g. let's say on test.md with

```!
Utils.test()
```

PS: you can also export stuff in utils.jl so for instance if you add export test you can then just call test() in a code cell on test.md. I tend to think it's a better idea to keep the Utils namespace but up to you.

And thanks for testing this stuff 😅

@cserteGT3
Copy link
Author

Oh, okay, I understand now!

And thanks for testing this stuff 😅

Thanks for writing the stuff to be tested 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation utils
Projects
None yet
Development

No branches or pull requests

2 participants