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

Weave implementation #1033

Closed
eljfe opened this issue Jul 3, 2023 · 4 comments
Closed

Weave implementation #1033

eljfe opened this issue Jul 3, 2023 · 4 comments

Comments

@eljfe
Copy link

eljfe commented Jul 3, 2023

Hi,
New to Franklin. Experienced enough to be dangerous in Weave. 😄

I have a repository of .jmds with accompanying html files for a self learning project. The repo is getting a little unruly so investigating a Franklin based solution.

Franklin looks great! After initializing a site, I can't get past step 2 though, getting Franklin to serve a .jmd file.

My error,

julia> serve()
  Activating project at `~/my repo/Franklin`
→ Initial full pass...
ERROR: LoadError: ArgumentError: Package Weave [44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.
│   ├── _rss
...

I hunted around some old threads and emulated the weave demo as best I could. Nothing working so far.

My test.md file looks like this,

+++
title="test me"
weave=true
+++
{{insert_weave _assets/ch2.exercises.medium.jmd}}

My Project.toml,

Franklin = "713c75ef-9fc9-4b05-94a9-213340da978e"
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
Weave = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

Finally utils.jl,

# 3 default functions, then...

function hfun_insert_weave(params)
  rpath = params[1]
  fullpath = joinpath(Franklin.path(:folder), rpath)
  (isfile(fullpath) && splitext(fullpath)[2] == ".jmd") || return ""
  print("Weaving... ")
  t = tempname()
  weave(fullpath, out_path=t)
  println("✓ [done].")
  fn = splitext(splitpath(fullpath)[end])[1]
  html = read(joinpath(t, fn * ".html"), String)
  start = findfirst("<BODY>", html)
  finish = findfirst("</BODY>", html)
  range = nextind(html, last(start)):prevind(html, first(finish))
  html = html[range]
  return html
end

Not sure where to take this next.

Many thanks,
Jeff

@tlienart
Copy link
Owner

tlienart commented Jul 5, 2023

Hello @eljfe, if you're just starting with Franklin, I'd suggest you try https://github.com/tlienart/Xranklin.jl which will be the version 0.11 of Franklin (and, eventually, its 1.0). The main things preventing me from releasing it right now are the docs and the templates.

I just played a bit with a demo repo that you can clone and replicate: https://github.com/tlienart/xranklin-weave (you can see the result here: https://tlienart.github.io/xranklin-weave/)

The build time is a bit slow because Weave's FIR demo uses Plots.jl which always takes forever to install and use but apart from that it should work well. Please have a try and let me know if that works for you.

Stuff you'll want to look at:

  • utils.jl
  • _layout/skeleton.html you'll see dedicated conditionals for weave pages to load the weave style, you could easily change all this; note also that weave uses Mathjax so there's a dedicated path to load mathjax in there too
  • index.md is where the .jmd file is loaded
  • the attach(...) function helps indicate that if the source file (.jmd file) changes, then that should trigger a rebuild of the page

@eljfe
Copy link
Author

eljfe commented Jul 7, 2023

Hi @tlienart -
Firstly thanks for answering my post and for Franklin!

I installed Xranklin and ran serve(debug=true) per the Xranklin Readme. Unfortunately serve(debug=true) failed on what looks like a call to bibrefs(). The dump is below.

I'll say here I'm just tinkering with the package. At the very least I hope you find this feedback useful. 🙂

...

┌ Debug: 🚧 ... try_resolve_lxcom > \biblabel
└ @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/misc_utils.jl:129
ERROR: MethodError: no method matching bibrefs()

Closest candidates are:
  bibrefs(::Xranklin.LocalContext)
   @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/context/default_context.jl:237

Stacktrace:
  [1] lx_biblabel(lc::Xranklin.LocalContext, p::Vector{String}; tohtml::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/lxfuns/hyperrefs.jl:93
  [2] outputof(fsymb::Symbol, args::Vector{String}, lc::Xranklin.LocalContext; internal::Bool, tohtml::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/outputof.jl:17
  [3] outputof
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/outputof.jl:6 [inlined]
  [4] from_utils(n::Symbol, i::Int64, blocks::Vector{FranklinParser.Block}, lc::Xranklin.LocalContext; isenv::Bool, tohtml::Bool, brackets::Vector{FranklinParser.Block})
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/latex_objects.jl:403
  [5] from_utils
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/latex_objects.jl:359 [inlined]
  [6] try_resolve_lxcom(i::Int64, blocks::Vector{FranklinParser.Block}, lc::Xranklin.LocalContext; tohtml::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/latex_objects.jl:264
  [7] process_latex_objects!(blocks::Vector{FranklinParser.Block}, ctx::Xranklin.LocalContext; tohtml::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/latex_objects.jl:34
  [8] convert_md(md::SubString{String}, c::Xranklin.LocalContext; tohtml::Bool, nop::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/md_core.jl:61
  [9] process_item!(prev_levels::Vector{Symbol}, init_ind::Base.RefValue{Int64}, io::IOBuffer, ctx::Xranklin.LocalContext, item_str::SubString{String}, cur_marker::RegexMatch, tohtml::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/rules/list.jl:158
 [10] _process_item!
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/rules/list.jl:80 [inlined]
 [11] convert_list(io::IOBuffer, g::FranklinParser.Group, ctx::Xranklin.LocalContext; tohtml::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/rules/list.jl:92
 [12] convert_md(md::SubString{String}, c::Xranklin.LocalContext; tohtml::Bool, nop::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/md_core.jl:75
 [13] convert_md
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/md_core.jl:20 [inlined]
 [14] #convert_md#135
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/md_core.jl:93 [inlined]
 [15] convert_md
    @ ~/.julia/packages/Xranklin/X1rL4/src/convert/markdown/md_core.jl:93 [inlined]
 [16] process_md_file_pass_1(lc::Xranklin.LocalContext, fpath::String; allow_init_skip::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/process/md/pass_1.jl:60
 [17] process_md_file_pass_1
    @ ~/.julia/packages/Xranklin/X1rL4/src/process/md/pass_1.jl:19 [inlined]
 [18] _md_loop_1(gc::Xranklin.GlobalContext{Xranklin.LocalContext}, fp::Pair{String, String}, skip_dict::Dict{Pair{String, String}, Bool}, allow_init_skip::Bool; reproc::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/build/full_pass.jl:306
 [19] _md_loop_1
    @ ~/.julia/packages/Xranklin/X1rL4/src/build/full_pass.jl:297 [inlined]
 [20] full_pass_markdown(gc::Xranklin.GlobalContext{Xranklin.LocalContext}, watched::Dict{Pair{String, String}, Float64}; skip_files::Vector{Pair{String, String}}, allow_init_skip::Bool, final::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/build/full_pass.jl:402
 [21] full_pass_markdown
    @ ~/.julia/packages/Xranklin/X1rL4/src/build/full_pass.jl:347 [inlined]
 [22] full_pass(gc::Xranklin.GlobalContext{Xranklin.LocalContext}, watched_files::Dict{Symbol, Dict{Pair{String, String}, Float64}}; skip_files::Vector{Pair{String, String}}, initial_pass::Bool, config_changed::Bool, utils_changed::Bool, final::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/build/full_pass.jl:164
 [23] serve(d::String; dir::String, folder::String, clear::Bool, final::Bool, single::Bool, eval::Bool, nocode::Bool, threads::Bool, use_threads::Bool, prepath::String, prefix::String, base_url_prefix::String, debug::Bool, cleanup::Bool, skip::Vector{String}, port::Int64, host::String, launch::Bool)
    @ Xranklin ~/.julia/packages/Xranklin/X1rL4/src/build/serve.jl:184
 [24] serve
    @ ~/.julia/packages/Xranklin/X1rL4/src/build/serve.jl:58 [inlined]
 [25] top-level scope
    @ REPL[2]:1

@tlienart
Copy link
Owner

tlienart commented Jul 7, 2023

Wait wait this is not weave, biblabel is a Franklin command, there is not a 100% overlap between the commands offered by Franklin and Xranklin yet (in some cases this is deliberate, in this particular one it'll be added).

If you don't mind, could you check purely the weave stuff separately of special commands and see if it suits your needs? I'll separately open an issue to look into the bibref stuff

@tlienart
Copy link
Owner

@eljfe FYI this is now fixed in Xranklin if you want to try this again. I'll close this issue for now, feel free to re-open one either here if you have an issue with Franklin or at Xranklin if you have an issue with that. Thanks!

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

No branches or pull requests

2 participants