Skip to content

Instantly share code, notes, and snippets.

@jhidding
Last active December 4, 2022 09:41
Show Gist options
  • Save jhidding/673ad67cf7cdbe3d50249d4ee2a315f2 to your computer and use it in GitHub Desktop.
Save jhidding/673ad67cf7cdbe3d50249d4ee2a315f2 to your computer and use it in GitHub Desktop.
push!(LOAD_PATH,"../src/")
using Documenter, ...
function noweb_label_pass(src, target_path)
mkpath(joinpath(target_path, dirname(src)))
script = joinpath(@__DIR__, "noweb_label_pass.awk")
run(pipeline(src, `awk -f $script`, joinpath(target_path, basename(src))))
end
function is_markdown(path)
splitext(path)[2] == ".md"
end
sources = filter(is_markdown, readdir(joinpath(@__DIR__, "src"), join=true))
path = mktempdir()
noweb_label_pass.(sources, path)
makedocs(source = path, ...)
deploydocs(...)
# This Awk scripts scans a Markdown source file for code blocks that match the
# Entangled syntax for defining named code blocks, and then inserts a piece
# of raw HTML to label these code blocks.
# This matches "``` {.julia #my-code}"
match($0, /``` *{[^#}]*#([a-zA-Z0-9\-_]+)[^}]*\}/, a) {
if (!(a[1] in counts))
counts[a[1]] = 0
term = counts[a[1]] == 0 ? "" : ""
print "```@raw html"
print "<div class=\"noweb-label\">⪡" a[1] "" term "</div>"
print "```"
counts[a[1]] = counts[a[1]] + 1
}
# This matches "``` {.julia file=src/my-file.jl}"
match($0, /``` *{[^}]*file=([a-zA-Z0-9\-_\.\/\\]+)[^}]*}/, a) {
print "```@raw html"
print "<div class=\"noweb-label\">file:<i>" a[1] "</i></div>"
print "```"
}
# Print everything else too
{
print
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment