diff --git a/.travis.yml b/.travis.yml index 07cde5164..cf071dbc3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,3 @@ notifications: after_success: # push coverage results to Codecov - julia -e 'using Pkg; pkg"add Coverage"; using Coverage; Codecov.submit(Codecov.process_folder())' - -jobs: - include: - - stage: "Documentation" - julia: 1.2 - os: linux - script: - - julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate()' - - julia --project=docs/ docs/make.jl - after_success: skip diff --git a/README.md b/README.md index ff1e16d74..a9eabfb8f 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,52 @@ -# JuDoc - -| | [MacOS/Linux] | Windows | Coverage | Documentation | -| :---: | :-----------: | :-----: | :------: | :-----------: | -| ![Life cycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg) | [![Build Status](https://travis-ci.org/tlienart/JuDoc.jl.svg?branch=master)](https://travis-ci.org/tlienart/JuDoc.jl) | [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/tlienart/JuDoc.jl?branch=master&svg=true)](https://ci.appveyor.com/project/tlienart/JuDoc-jl) | [![codecov.io](http://codecov.io/github/tlienart/JuDoc.jl/coverage.svg?branch=master)](http://codecov.io/github/tlienart/JuDoc.jl?branch=master) | [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://tlienart.github.io/JuDoc.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://tlienart.github.io/JuDoc.jl/dev) | +
+ + JuDoc + +
+ +

A Static Site Generator in Julia. +

+ Lifecycle + + Build Status + + + Coverage + +

+

JuDoc is a simple **static site generator** (SSG) oriented towards technical blogging (code, maths, ...) and light, fast-loading pages. -The base syntax is plain markdown with a few extensions such as the ability to define and use LaTeX-like commands in or outside of maths environments. +The base syntax is plain markdown with a few extensions such as the ability to define and use LaTeX-like commands in or outside of maths environments and the possibility to evaluate code blocks on the fly. + +## Docs + +Go to [JuDoc's main website](https://tlienart.github.io/JuDocWeb/). -See [the docs](https://tlienart.github.io/JuDoc.jl/stable) for more information. +Some examples of websites using JuDoc -A couple of websites using JuDoc: +* the main website is written in JuDoc, [source](https://github.com/tlienart/JuDocWeb), * [@cormullion's website](https://cormullion.github.io), the author of [Luxor.jl](https://github.com/JuliaGraphics/Luxor.jl), * MLJ's [tutorial website](https://alan-turing-institute.github.io/MLJTutorials/) which shows how JuDoc can interact nicely with [Literate.jl](https://github.com/fredrikekre/Literate.jl) +* see also [all julia blog posts](https://julialangblogmirror.netlify.com/) rendered with JuDoc thanks to massive help from [@cormullion](https://github.com/cormullion); see also the [source repo](https://github.com/cormullion/julialangblog) * [my website](https://tlienart.github.io). -* see also how [some julia blog posts](https://tlienart.github.io/julia-blog-migration/) render with JuDoc (note: _focus on the rendering, not the layout/CSS_) see also [the source repo](https://github.com/tlienart/julia-blog-migration). - * actually see [all of them](https://julialangblogmirror.netlify.com/) rendered with JuDoc thanks to massive help from [@cormullion](https://github.com/cormullion); see also the [source repo](https://github.com/cormullion/julialangblog) -### Key features +## Key features * Use standard markdown with the possibility to use LaTeX-style commands, * Simple way to introduce div blocks allowing easy styling on a page (e.g. "Theorem" boxes etc.), * Can execute and show the output of Julia code blocks, -* Simple optimization step to accelerate webpage loading speed: +* Simple optimisation step to accelerate webpage loading speed: - compression of HTML and CSS of the generated pages, - optional pre-rendering of KaTeX and highlighted code blocks to remove javascript dependency, * Easy HTML templating to define or adapt a given layout. -See [the docs](https://tlienart.github.io/JuDoc.jl/stable) for more information and examples. +See [the docs](https://tlienart.github.io/JuDocWeb/) for more information and examples. -### Quick demo +## Getting started With Julia ≥ 1.1: @@ -36,7 +54,7 @@ With Julia ≥ 1.1: pkg> add JuDoc ``` -and then you can get started with +you can then get started with ```julia julia> using JuDoc @@ -52,23 +70,24 @@ julia> serve() (use CTRL+C to shut down) ``` -You can now modify the files in `MyNewSite/src` and see the changes being live-rendered in your browser. -Head to [the docs](https://tlienart.github.io/JuDoc.jl/stable) for more information. +Modify the files in `MyNewSite/src` and see the changes being live-rendered in your browser. +Head to [the docs](https://tlienart.github.io/JuDocWeb/) for more information. ## Associated repositories * [LiveServer.jl](https://github.com/asprionj/LiveServer.jl) a package coded with [Jonas Asprion](https://github.com/asprionj) to render and watch the content of a local folder in the browser. * [JuDocTemplates.jl](https://github.com/tlienart/JuDocTemplates.jl) the repositories where JuDoc themes/templates are developed. +* [JuDocWeb](https://github.com/tlienart/JuDocWeb) the repository for JuDoc's website. ## Licenses **Core**: -* JuDoc, JuDocTemplates and LiveServer are all MIT licensed +* JuDoc, JuDocTemplates and LiveServer are all MIT licensed. **External**: -* KaTeX is [MIT licensed](https://github.com/KaTeX/KaTeX/blob/master/LICENSE) -* Node's is essentially [MIT licensed](https://github.com/nodejs/node/blob/master/LICENSE) -* css-html-js-minify is [LGPL licensed](https://github.com/juancarlospaco/css-html-js-minify/blob/master/LICENCE.lgpl.txt) -* highlight.js is [BSD licensed](https://github.com/highlightjs/highlight.js/blob/master/LICENSE) +* KaTeX is [MIT licensed](https://github.com/KaTeX/KaTeX/blob/master/LICENSE), +* Node's is essentially [MIT licensed](https://github.com/nodejs/node/blob/master/LICENSE), +* css-html-js-minify is [LGPL licensed](https://github.com/juancarlospaco/css-html-js-minify/blob/master/LICENCE.lgpl.txt), +* highlight.js is [BSD licensed](https://github.com/highlightjs/highlight.js/blob/master/LICENSE). diff --git a/docs/Project.toml b/docs/Project.toml deleted file mode 100644 index f51f69ce3..000000000 --- a/docs/Project.toml +++ /dev/null @@ -1,6 +0,0 @@ -[deps] -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -JuDocTemplates = "6793090a-55ae-11e9-0511-73b91164f4ea" - -[compat] -Documenter = "~0.22" diff --git a/docs/make.jl b/docs/make.jl deleted file mode 100644 index fe3084588..000000000 --- a/docs/make.jl +++ /dev/null @@ -1,33 +0,0 @@ -using Documenter, JuDoc, JuDocTemplates - -makedocs( - modules = [JuDoc, JuDocTemplates], - format = Documenter.HTML( - # Use clean URLs, unless built as a "local" build - prettyurls = !("local" in ARGS), - # custom CSS - assets = ["assets/custom.css"] - ), - sitename = "JuDoc.jl", - authors = "Thibaut Lienart", - pages = [ - "Home" => "index.md", - "Manual" => [ - "Workflow" => "man/workflow.md", - "Syntax" => "man/syntax.md", - "Templating" => "man/templating.md", - "Themes" => "man/themes.md", - "Contributing" => "man/contrib.md", - "Troubleshooting" => "man/troubleshooting.md", - ], - "Library" => [ - "Design" => "lib/design.md", - "Public" => "lib/public.md", - "Internals" => "lib/internals.md", - ], - ], # end page -) - -deploydocs( - repo = "github.com/tlienart/JuDoc.jl.git", -) diff --git a/docs/src/assets/custom.css b/docs/src/assets/custom.css deleted file mode 100644 index c0f9612d1..000000000 --- a/docs/src/assets/custom.css +++ /dev/null @@ -1,55 +0,0 @@ -body { - font-family: Helvetica; - text-rendering: optimizeLegibility; - line-height: 1.5; - color: #363636; -} - -article { - margin-left: 16em; -} - -@media only screen and (max-width:768px) { - article { - margin-left: 0; - padding: 3em, 0.9em, 0, 0.9em; - overflow-wrap: break-word; - } -} - -nav.toc { - width: 15em; -} - -nav.toc ul li ul li.current ul.internal li a.toctext:before { - content:"• "; -} - -pre > code.language-judoc { - color: #3030c9; -} - -blockquote { - background-color: #e6f9f2; - font-style: italic; - border-left: 5px solid cadetblue; - padding-left: 5px; -} -blockquote p { - padding-top: 7px; - padding-bottom: 5px; -} - -.admonition.important > .admonition-title { - visibility: hidden; - height: 0; -} - -.admonition.important { - background-color: lemonchiffon; -} - -[href^="http"]:not([href*="github.com/tlienart/JuDoc.jl"]) { - color: #134293; - text-decoration: underline; -} diff --git a/docs/src/assets/ex-definition.png b/docs/src/assets/ex-definition.png deleted file mode 100644 index 87ce11330..000000000 Binary files a/docs/src/assets/ex-definition.png and /dev/null differ diff --git a/docs/src/assets/jemdoc1.png b/docs/src/assets/jemdoc1.png deleted file mode 100644 index 03a83acd1..000000000 Binary files a/docs/src/assets/jemdoc1.png and /dev/null differ diff --git a/docs/src/assets/jemdoc2.png b/docs/src/assets/jemdoc2.png deleted file mode 100644 index 27e6b396b..000000000 Binary files a/docs/src/assets/jemdoc2.png and /dev/null differ diff --git a/docs/src/assets/jemdoc3.png b/docs/src/assets/jemdoc3.png deleted file mode 100644 index 526d47c0e..000000000 Binary files a/docs/src/assets/jemdoc3.png and /dev/null differ diff --git a/docs/src/assets/jemdoc4.png b/docs/src/assets/jemdoc4.png deleted file mode 100644 index aaadd20aa..000000000 Binary files a/docs/src/assets/jemdoc4.png and /dev/null differ diff --git a/docs/src/index.md b/docs/src/index.md deleted file mode 100644 index e46bc57d7..000000000 --- a/docs/src/index.md +++ /dev/null @@ -1,214 +0,0 @@ -# JuDoc.jl - Documentation - -JuDoc is a simple **static site generator** (SSG) oriented towards technical blogging (code, maths, ...) and light, fast-loading pages. -The base syntax is plain markdown with a few extensions such as the ability to define and use LaTeX-like commands in or outside of maths environments (see the [Syntax](@ref) section). - -➡ For a list of the key features see [here](#About-1). - -```@raw html -➡ For a demo of available templates, see here (opens in a new tab). -``` - - -!!! note - - This package is still young and issues should be expected, comments, questions, bug reports etc. are welcome to make it better, see also the [Contributing](@ref) section. - -On this page: - -* [Installation](#Installation-1) - * [External dependencies](#External-dependencies-1) -* [Quick start](#Quick-start-1) -* [About](#About-1) - * [Features](#Features-1) - * [Why?](#Why?-1) - * [Licenses](#Licenses-1) - -## Installation - -With Julia ≥ 1.1, - -```julia-repl -pkg> add JuDoc -``` - -### External dependencies - -JuDoc allows a post-processing step (see [`optimize`](@ref)) which pre-renders highlighted code blocks and math environments and minifies generated HTML and CSS. -This step requires a few external dependencies: - -* [`node.js`](https://nodejs.org/en/) for the pre-rendering of KaTeX and code highlighting, -* [`python3`](https://www.python.org/downloads/) for the minification of the site, -* [`git`](https://git-scm.com/downloads) for automating pushing and pulling to a remote repository. - -Assuming you have those, you will then need to install `highlight.js` via `npm`: - -```bash -[sudo] npm install -g highlight.js -``` - -and the python package [`css_html_js_minify`](https://github.com/juancarlospaco/css-html-js-minify) which you can install with `pip3` (if you have python3, JuDoc will try to do this for you): - -```bash -pip3 install css_html_js_minify # mac/linux -py -3 -m pip install css_html_js_minify # windows -``` - -If you've installed these dependencies _after_ adding JuDoc, you will need to re-build the package with - -```julia-repl -pkg> build JuDoc -``` - -You can subsequently check whether `JuDoc` was able to find them by looking at: - -```julia-repl -julia> using JuDoc -julia> JuDoc.JD_CAN_PRERENDER -true -julia> JuDoc.JD_CAN_HIGHLIGHT -true -julia> JuDoc.JD_CAN_MINIFY -true -``` - -!!! note - - These external dependencies are **not required** to run JuDoc, they are just recommended to benefit from some of the post-processing machinery such as [`optimize`](@ref) or [`publish`](@ref). - -### Troubleshooting - -If JuDoc complains that it can't find a dependency while you believe that it is installed on your computer, you may have to help JuDoc know how to call the dependency. -For this, you can specify in your `.julia/config/startup.jl`: - -```julia -ENV["PYTHON3"] = "python3" -ENV["PIP3"] = "pip3" -ENV["NODE"] = "node" -``` - -replace the values by however python 3, node and pip are called on your computer i.e., whatever makes the following commands work: - -```julia -julia> success(`python3 -V`) -true -julia> success(`pip3 -v`) -true -julia> success(`node -v`) -true -``` - -#### Highlight.js - -If you have issues with getting highlight.js to work, you should give these a try: - -* On Windows you _may_ need to add the following to your environment variables ([source](https://stackoverflow.com/a/26480275)): `NODE_PATH=%AppData%\npm\node_modules` -* You _may_ need to use the `--save` switch ([source](https://stackoverflow.com/a/30886703)): `[sudo] npm install -g --save highlight.js` - -## Quick start - -Change directory to an appropriate sandbox location on your computer, start Julia and: - -```julia-repl -julia> using JuDoc -julia> newsite("test", template="pure-sm") -✓ Website folder generated at "test" (now the current directory). -→ Use serve() from JuDoc to see the website in your browser. - -julia> serve() -→ Initial full pass... -→ Starting the server... -✓ LiveServer listening on http://localhost:8000/ ... - (use CTRL+C to shut down) -``` - -This will generate a folder `test` with overall structure: - -``` -. -├── assets/ -├── css/ -├── index.html -├── libs/ -├── pub/ -└── src - ├── _css/ - ├── _html_parts/ - ├── config.md - ├── index.md - └── pages/ -``` - -You can see what the corresponding website looks like by opening a browser at the given address `http://localhost:8000`. - -The key folder in which you should work is `src/`. -For instance, a good way to become familiar with JuDoc's extended markdown syntax is to head to `src/index.md` and modify its content while keeping an eye in a browser on `http://localhost:8000/index.html`. - -Once you've had a feel for the basic syntax, head over to the [Workflow](@ref) section of the manual for more information on available templates, the folder structure etc. - -## About - -### Features - -This is a partial list of JuDoc's features that you may find interesting/useful; head to the Manual part of the docs for more details. - -* ([docs](man/syntax/#LaTeX-commands-1)) LaTeX-like definition of commands (via `\newcommand{..}[.]{..}`) -* ([docs](man/syntax/#Div-blocks-1)) inclusion of user-defined div-blocks via `@@divname ... @@` and raw-html via `~~~ ... ~~~` -* ([docs](man/syntax/#Maths-1)) maths rendered via [KaTeX](https://katex.org/), code via [highlight.js](https://highlightjs.org) both can be pre-rendered (see further below) -* ([docs](man/syntax/#Hyper-references-1)) hyper-references for equations and citations -* ([docs](man/templating/)) simple html templating -* fast page generation (~5ms per page on warm session) -* live preview (via [LiveServer.jl](https://github.com/asprionj/LiveServer.jl)) -* ([docs](man/workflow/#Optimisation-step-1)) optimisation step to speed up wepage rendering: - * pre-rendered KaTeX (requires `node`) - * pre-rendered code highlighting (requires `node` and `highlight.js`) - * minified output (via [`css-html-js-minify`](https://github.com/juancarlospaco/css-html-js-minify), requires `python3`) -* ([docs](man/workflow/#(git)-synchronisation-1)) all-in-one "publish" step to compile, optimise and push your website - -There are also a few features to deal with code: - -* ([docs](man/syntax/#Insertions-1)) insertion of code blocks with or without live-evaluation (a bit like [Weave.jl](https://github.com/mpastell/Weave.jl)), -* ([docs](man/workflow/#Using-Literate.jl-1)) working with [Literate.jl](https://github.com/fredrikekre/Literate.jl) - - -### Why? - -There is a multitude of [static site generators](https://www.staticgen.com/) out there so why bother with yet another one? and is this one worth your time? - -I didn't start working on JuDoc hoping to "beat" mature and sophisticated generators like Hugo etc. -Rather, a few years back I was using Jacob Mattingley's [Jemdoc](http://jemdoc.jaboc.net/using.html) package in Python with Wonseok Shin's [neat extension](https://github.com/wsshin/jemdoc_mathjax) for MathJax support and decided I wanted to build something similar in Julia (whence the name) and improve on the few things I didn't like. - -!!! aside - - Interestingly, there still seems to be a number of people who use Jemdoc in academia. - For instance [Ben Recht](http://people.eecs.berkeley.edu/~brecht/), [Madeleine Udell](https://people.orie.cornell.edu/mru8/) or [Marco Cuturi](http://marcocuturi.net/index.html). - So working on JuDoc seemed a worthwhile. - - -Among the things I wanted to improve over Jemdoc were: - -* support live-preview with near-instant rendering of modifications, -* generate fast-loading webpages, -* support KaTeX, -* allow LaTeX-like commands including outside of maths environment, -* better control over the layout with a simple templating system. - -When compared with more serious static site generators like Hugo or Jekyll, clearly JuDoc is not in the same league. -One element that may be particularly useful though are the markdown extensions which allow to construct sophisticated commands and thereby effectively define "your own markdown flavour". - -If you just want formatted text and pictures, JuDoc will probably not be very useful to you. -However, if you want to write technical documents with tables, maths, recurring elements etc, then JuDoc may be helpful. - -If you think JuDoc could help you but you're not sure or you seem to be blocked by a missing feature, please [open an issue](https://github.com/tlienart/JuDoc.jl/issues/new). - -### Licenses - -**Core**: JuDoc, JuDocTemplates and LiveServer are all MIT licensed. - -**External**: these libraries are used "as-is": - -* KaTeX is [MIT licensed](https://github.com/KaTeX/KaTeX/blob/master/LICENSE), -* Node's is essentially [MIT licensed](https://github.com/nodejs/node/blob/master/LICENSE), -* css-html-js-minify is [LGPL licensed](https://github.com/juancarlospaco/css-html-js-minify/blob/master/LICENCE.lgpl.txt), -* highlight.js is [BSD licensed](https://github.com/highlightjs/highlight.js/blob/master/LICENSE), -* git is [GPL licensed](https://git-scm.com/about/free-and-open-source). diff --git a/docs/src/lib/design.md b/docs/src/lib/design.md deleted file mode 100644 index 37474ca74..000000000 --- a/docs/src/lib/design.md +++ /dev/null @@ -1,242 +0,0 @@ -# Design - -This page aims to shed some light on how JuDoc works and how the code is structured which could be of interest for anyone willing to contribute to the codebase. - -## Big Picture - -### Compilation - -The overarching sequence for the initial _full pass_ is: - -1. retrieve the paths to files that should be processed ([`JuDoc.jd_setup`](@ref)), -1. process all files ([`JuDoc.jd_fullpass`](@ref)) - * if it's a markdown file convert it to HTML (see below), - * place generated file in appropriate locations. - -In general the user will use `serve()` which triggers a full pass followed by a loop that re-processes files individually upon modifications ([`JuDoc.jd_loop`](@ref)). - -### File processing - -The file processing is controlled by the function [`JuDoc.process_file`](@ref) which, itself, is a thin wrapper around the function [`JuDoc.process_file_err`](@ref) (the first one processes any errors that may be generated during the processing of files). -There are three types of files: - -* markdown files (`.md`) which are parsed and converted into HTML, -* HTML files (`.html`) which are parsed and re-generated after solving any templating commands they may contain, -* other files which are just copied over to the relevant location. - -In the case of markdown files, the function [`JuDoc.write_page`](@ref) is called and is formed of 3 key stages: - -1. parsing of the markdown ([`JuDoc.convert_md`](@ref)) -1. conversion to HTML and assembly of different blocks into one page ([`JuDoc.convert_html`](@ref) and [`JuDoc.build_page`](@ref)), -1. writing the HTML in the appropriate location, possibly after pre-rendering javascript ([`JuDoc.js_prerender_katex`](@ref), [`JuDoc.js_prerender_highlight`](@ref)). - - -## Parsing - -!!! note - - If you wonder why I didn't just use a "standard parser", one of my personal goal was to try to build a parser from scratch to get an idea of how one would work. I don't doubt better can be done though I doubt it's a serious bottleneck at the moment. - -At the very basic level, the parser reads the content from left to right and tries to find "blocks" that should be processed in a specific way. -Once blocks have been found, each block gets processed in turn following the appropriate order in which they appear. -Finally, they are re-assembled after processing. - -The overarching block type is the [`JuDoc.AbstractBlock`](@ref) with as key sub-types `Token` and `OCBlock`: - -* [`JuDoc.Token`](@ref): these correspond to the idea of a _specific sequence of characters_ which typically will denote the _start_ or the _end_ of an environment. The type contains a substring corresponding to the matched token and a name indicating what the token is. - -```julia-repl -julia> s = raw"Hello, $x=5$ end"; -julia> t = JuDoc.find_tokens(s, JuDoc.MD_TOKENS, JuDoc.MD_1C_TOKENS) -2-element Array{JuDoc.Token,1}: - JuDoc.Token(:MATH_A, "\$") - JuDoc.Token(:MATH_A, "\$") - -julia> JuDoc.from(t[1]) -8 -julia> JuDoc.from(t[1]) -12 -``` - -* [`JuDoc.OCBlock`](@ref): these correspond to the idea of an _environment_ delimited by an opening and a closing token. The type contains a substring corresponding to the full block, a name indicating what the environment is and a pair of opening and closing tokens (whence the name "O/C"). - -```julia-repl -julia> ocb, _ = JuDoc.find_all_ocblocks(t, JuDoc.MD_OCB_ALL); -julia> ocb -1-element Array{JuDoc.OCBlock,1}: - JuDoc.OCBlock(:MATH_A, JuDoc.Token(:MATH_A, "\$") => JuDoc.Token(:MATH_A, "\$"), "\$x=5\$", false) - -julia> JuDoc.from(ocb[1]) -8 - -julia> JuDoc.to(ocb[2]) -12 -``` - -### Finding Tokens - -The function [`JuDoc.find_tokens`](@ref) takes content, reads it from left to right and returns a list of `Token`s. -It takes a string, and two "token dictionaries". -The first one describes tokens that span _multiple characters_ while the second one correspond to tokens that span _a single character_. - -Single character tokens are tokens that are exclusively defined by a single character. -These characters **cannot** be part of multi-chars tokens. -For instance, [`JuDoc.MD_1C_TOKENS`](@ref) corresponds to single-char tokens in markdown with entries such as: - -```julia -'{' => :LXB_OPEN, -``` - -The key of these entries is a `Char` and as soon as the function sees that character while it reads the content, a Token is formed with the corresponding name (here `:LXB_OPEN` which stands for _latex-brace-open_). - -As for multi-char tokens, for instance, [`JuDoc.MD_TOKENS`](@ref), entries look like: - -```julia -'<' => [ isexactly("`) with no nesting. - -When nesting is allowed (for instance div blocks can be nested) then the function `find_all_ocblocks` keeps track of the number of opening and closing tokens and returns the outer-most block (which will be decomposed further at a later stage). - -```julia-repl -julia> s = raw"Hello @@d-name-a ... @@d-name-b @@ ... @@ etc"; -julia> t = JuDoc.find_tokens(s, JuDoc.MD_TOKENS, JuDoc.MD_1C_TOKENS); -julia> ocb, _ = JuDoc.find_all_ocblocks(t, JuDoc.MD_OCB); -julia> length(ocb) -1 - -julia> ocb[1].name -:DIV - -julia> ocb[1].ss -"@@d-name-a ... @@d-name-b @@ ... @@" - -``` - -When a token has been snapped up in a ocblock, it is marked as inactive so that it doesn't get re-processed. - -### LaTeX blocks - -When parsing a markdown file, after finding tokens and ocblocks, JuDoc tries to find [`JuDoc.LxDef`](@ref) and [`JuDoc.LxCom`](@ref) blocks (also `AbstractBlock`). - -The first one corresponds to LaTeX _definitions_ of the form `\newcommand{\name}[narg]{def}` while the second one corresponds to LaTeX _commands_ such as `\foo` or `\foo{bar}` or `\foo{bar}{baz}` etc. - -The function [`JuDoc.find_md_lxdefs`](@ref) takes a vector of active tokens and a ocblocks and finds sequences that match the format of a newcommand. -Its counterpart, [`JuDoc.find_md_lxcoms`](@ref) takes a vector of active tokens and definitions and ocblocks and finds sequences that match the format of a command. - -```julia-repl -julia> s = raw"a \newcommand{\foo}[1]{_blah #1_} and \foo{hello} done."; -julia> t = JuDoc.find_tokens(s, JuDoc.MD_TOKENS, JuDoc.MD_1C_TOKENS); -julia> ocb, t = JuDoc.find_all_ocblocks(t, JuDoc.MD_OCB); -julia> lxd, t, braces, blocks = JuDoc.find_md_lxdefs(t, ocb); -julia> lxd[1] -JuDoc.LxDef("\\foo", 1, "_blah #1_", 3, 33) - -julia> lxc, t = JuDoc.find_md_lxcoms(t, lxd, braces); -julia> lxc[1] -JuDoc.LxCom( - "\\foo{hello}", - Base.RefArray{...}(...), - JuDoc.OCBlock[JuDoc.OCBlock(:LXB, JuDoc.Token(:LXB_OPEN, "{") => JuDoc.Token(:LXB_CLOSE, "}"), - "{hello}", true)]) - -``` - -In the `LxCom`, the output was truncated for readability, the second field is a reference to the appropriate LaTeX definition of the command while the final field is a vector formed of ocblocks which correspond to each of the arguments (here only a single one: `{hello}`). - -### HTML blocks - -When parsing a HTML file, JuDoc also tries first to find tokens (see [`JuDoc.HTML_TOKENS`](@ref)) and ocblocks (see [`JuDoc.HTML_OCB`](@ref)). -In particular, it will find ocblocks of the form `{{ ... }}` ("HTML blocks"). -Subsequently, JuDoc will try to _qualify_ those HTML blocks and form a specific block such as a `HIf` or a `HElse` block (see [`JuDoc.qualify_html_hblocks`](@ref)): - -| Form | Name | -| :--- | :--- | -| `{{if var}}` | `HIf` | -| `{{elseif var}}` | `HElseIf` | -| `{{else}}` | `HElse` | -| `{{end}}`| `HEnd` | -| `{{is[not]def var}}` | `HIs[Not]Def` | -| `{{is[not]page path}}`| `HIs[Not]Page` | - -These blocks can then be assembled in larger blocks such as `HCond` (corresponding to an if-elseif-else-end), see [`JuDoc.find_html_cblocks`](@ref), [`JuDoc.JuDoc.find_html_cdblocks`](@ref) and [`JuDoc.JuDoc.find_html_cpblocks`](@ref). - -## Conversion - -### Markdown conversion - -The core function corresponding to the conversion of a markdown document is, as mentioned before, [`JuDoc.convert_md`](@ref). -The first part corresponds to the parsing discussed above to find: - -1. tokens -1. open/close blocks -1. LaTeX-like definitions -1. LaTeX-like commands -1. Markdown definitions (e.g. `@def x = 5`) - -This parsing step creates a number of _blocks_ which each have to be processed in turn. -The function [`JuDoc.form_inter_md`](@ref) takes the vector of all blocks and latex definitions and forms an intermediate markdown where places where an insertion must occur are marked with `##JDINSERT##`. -This intermediate markdown is then fed to the function [`JuDoc.md2html`](@ref) which wraps around Julia's Markdown to HTML. - -Finally the function [`JuDoc.convert_inter_html`](@ref) takes the partial markdown and inserts the appropriately processed blocks where the `##JDINSERT##` are. -The function [`JuDoc.convert_block`](@ref) takes care of how blocks are converted before insertion (for instance how a math block should be properly fenced). - -### HTML conversion - -The core function corresponding to the conversion of a html document is, as mentioned before, [`JuDoc.convert_html`](@ref). -The first part corresponds to the parsing discussed above to find: - -1. tokens -1. open/close blocks -1. conditional blocks (`if ... elseif ... else ... end`) -1. conditional def blocks (`isdef ... end`) -1. conditional page blocks (`ifpage ... end`) - -The final HTML page is written by sequentially writing what's between the blocks and then replacing the blocks by the appropriate content using the function [`JuDoc.convert_hblock`](@ref). diff --git a/docs/src/lib/internals.md b/docs/src/lib/internals.md deleted file mode 100644 index 0a4892ad5..000000000 --- a/docs/src/lib/internals.md +++ /dev/null @@ -1,61 +0,0 @@ -# Internal Interface - -Documentation for `JuDoc.jl`'s internal interface. - -## File processing and compilation - -```@docs -JuDoc.jd_setup -JuDoc.jd_fullpass -JuDoc.jd_loop -JuDoc.process_file -JuDoc.process_file_err -``` - -## Conversion - -```@docs -JuDoc.write_page -JuDoc.convert_md -JuDoc.form_inter_md -JuDoc.md2html -JuDoc.convert_inter_html -JuDoc.convert_block -JuDoc.convert_html -JuDoc.convert_hblock -JuDoc.build_page -``` - -### Pre-rendering - -```@docs -JuDoc.js_prerender_katex -JuDoc.js_prerender_highlight -``` - -## Parsing - -```@docs -JuDoc.AbstractBlock -JuDoc.Token -JuDoc.OCBlock -JuDoc.TokenFinder -JuDoc.MD_TOKENS -JuDoc.MD_1C_TOKENS -JuDoc.LxDef -JuDoc.LxCom -JuDoc.HTML_TOKENS -JuDoc.HTML_OCB -``` - -```@docs -JuDoc.isexactly -JuDoc.find_tokens -JuDoc.find_all_ocblocks -JuDoc.find_md_lxdefs -JuDoc.find_md_lxcoms -JuDoc.qualify_html_hblocks -JuDoc.find_html_cblocks -JuDoc.JuDoc.find_html_cdblocks -JuDoc.JuDoc.find_html_cpblocks -``` diff --git a/docs/src/lib/public.md b/docs/src/lib/public.md deleted file mode 100644 index 80723d5c2..000000000 --- a/docs/src/lib/public.md +++ /dev/null @@ -1,11 +0,0 @@ -# Public Interface - -Documentation for `JuDoc.jl`'s exported functions - -```@docs -JuDoc.newsite -JuDoc.serve -JuDoc.optimize -JuDoc.publish -JuDoc.cleanpull -``` diff --git a/docs/src/man/contrib.md b/docs/src/man/contrib.md deleted file mode 100644 index 111f9dcc0..000000000 --- a/docs/src/man/contrib.md +++ /dev/null @@ -1,32 +0,0 @@ -# Contributing - -Contributions, questions and comments are very welcome. -In particular, I can see two main ways you can contribute: - -1. use JuDoc, ask questions, report bugs or ask for features by [opening issue(s)](https://github.com/tlienart/JuDoc.jl/issues/new), -1. suggest improvements to the code, html generation, or themes. - -The first one is self-explanatory, please just check that your issue is somewhat aligned with the [Judoc spirit](#Judoc-spirit-1). - -For the second one, all suggestions will be welcome though I will prioritise help in the following three areas which I believe would make the user experience better: - -1. _bug fixes_, -1. _error handling_: at the moment the error handling is basic to say the least, anything to would help errors being better/more sensibly handled would be great, -1. _improving the templates_: the current templates are meant to be simple and easily adjustable but there could be more of them and they may be improved to have better cross-browser support, responsiveness etc. For template improvement, please refer to [JuDocTemplates.jl](https://github.com/tlienart/JuDocTemplates.jl). - - -## JuDoc spirit - -Some of the key objectives of JuDoc are to have a package that... - -* can be used easily by people who have little experience with web-dev, -* is in Julia, is fast™ for local editing, and can be easily extended, -* generates pages that are light and load very quickly. - -In particular, for the last point, I would favour theme contributions that minimise the use of complex javascript libraries or intricate CSS stylesheets if possible. -Beyond trying to avoid the [bloated](https://idlewords.com/talks/website_obesity.htm) [web](https://pxlnv.com/blog/bullshit-web/), I will be more supportive of extensions that avoid intruding on people's privacy. -Although it is trivial to plug in elements like Google Analytics, Discourse comments or social media buttons in the templates, it is not done by default for a reason; -I'd prefer writing docs that explains how to add those than to add them by default 😅 . - -If you know of good alternatives, open issues! -For instance the GitHub-issues based comment system [utterances](https://github.com/utterance/utterances) looks great (but I haven't tried it yet). diff --git a/docs/src/man/syntax.md b/docs/src/man/syntax.md deleted file mode 100644 index 739addbdd..000000000 --- a/docs/src/man/syntax.md +++ /dev/null @@ -1,879 +0,0 @@ -# Syntax - -This page is about the modified markdown syntax that is used in JuDoc. -For the HTML templating syntax, see [Templating](@ref). - -A good way to become familiar with the JuDoc syntax is to generate a test-website and modify its `index.md` as explained in the [Quick start](@ref) tutorial. -Most of what is presented here is also shown in that example. - -**Contents**: - -* [Basic syntax](#Basics-1) - * [General](#General-1) - * [Maths](#Maths-1) - * [Div blocks](#Div-blocks-1) - * [Table of contents](#Table-of-contents-1) - * [Using raw HTML](#Using-raw-HTML-1) - * [Comments](#Comments-1) -* [LaTeX commands](#LaTeX-commands-1) - * [Nesting](#Nesting-1) - * [Whitespaces](#Whitespaces-1) - * [Local vs global](#Local-vs-global-1) - * [Hyper-references](#Hyper-references-1) -* [Code insertions](#Code-insertions-1) - * [On-the-fly evaluation](#On-the-fly-evaluation-1) - * [More on paths](#More-on-paths-1) - * [Inserting the output](#Inserting-the-output-1) - * [Hiding lines](#Hiding-lines-1) - * [Separate evaluation](#Separate-evaluation-1) - * [Inserting code](#Inserting-code-1) - * [Plain-text output](#Plain-text-output-1) - * [Plot output](#Plot-output-1) - * [Slicing up](#Slicing-up-1) -* [File insertions](#File-insertions-1) - * [Inserting a figure](#Inserting-a-figure-1) - * [Linking a file](#Linking-a-file-1) - * [Inserting markdown](#Inserting-markdown-1) - * [Inserting a table](#Inserting-a-table-1) -* [Page variables](#Page-variables-1) - * [Local page variables](#Local-page-variables-1) - * [Default variables](#Default-variables-1) - * [Global page variables](#Global-page-variables-1) - -## Basics - -The basic syntax corresponds to standard markdown and the [markdown cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) is a great resource, in particular: - -* how to [insert images](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images), -* how to [insert code](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting), -* how to [insert tables](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables). - -One key difference with Git Flavored Markdown (GFM) is that inline HTML _should not be used_ unless fenced with `~~~` (see the [section on injecting HTML](#Using-raw-HTML-1) below). - -### General - -While you should expect JuDoc to support core [Common Mark](https://commonmark.org/) syntax, there are a few particularities you should be aware of since the markdown parser implemented in JuDoc is the Julia Markdown parser (`Markdown.parse`) from stdlib coupled with a bunch of additions. - -!!! note - - If there is something not mentioned here that you expected to work according to Common Mark but it doesn't, please open an issue in the JuDoc repository. - -#### Symbols - -Outside code environments, there are a few quirks in dealing with symbols: - -* (**dollar sign**) to introduce a dollar sign, you _must_ escape it with a backslash: `\$` as it is otherwise used to open and close inline math blocks, -* (**HTML entity**) you can use HTML entities without issues like `→` for "→" or in fact `$` for "\$", -* (**backslash**) to introduce a backslash, you can just use `\`, a _double backslash_ `\\` can be used to signify a _line break_ in text. - - -#### Other notes - -* (**header**) should _only_ be defined via a number of `#` at the start of a line (this is to help table-of-contents generation), -* (**line break**) use a double backslash `\\` in text to force a line break (`
`), a bit like in LaTeX, -* (**list items**) _must_ be on the same line (_this is due to [a limitation](https://github.com/JuliaLang/julia/issues/30198) of the Julia Markdown parser_), -* (**indented blocks**) you _can_ use indented blocks to delimit code blocks but we _strongly recommend_ you use fenced code blocks (with triple backticks) instead as the language can be made explicit and fenced code blocks can be executed (see the section on [code insertion](#Code-insertions-1)), -* (**link reference**) when using "indirect links" i.e. in the text you use something like `[link name][link A]` and then somewhere else you define `[link A]: some/url/`, we recommend you use unambiguous link identifiers (here `[link A]`). For instance we would recommend you not to use numbers like `[link name][1]`, indeed if on the page you have some code where `[1]` appears, there is an ambiguity which could cause problems for the parser. (_this is due to a hack to bypass [a limitation](https://github.com/JuliaLang/julia/issues/19844) of the Julia Markdown parser_) -* (**link title**) are currently _not supported_ e.g. something like `[link A](some/url/ "link title")`. - - -#### Quirks - -* to introduce a horizontal line, use `----` or `*****` but `- - -` or `* * *` won't work (_this is a limitation of the Julia Markdown parser_) -* if, for some reason, you want to have something like `[...]: ...` somewhere on your page that does _not_ define a link, then you need to toggle ref-links off (`@def reflinks = false`) and only use inline links `[link name](some/url/)` - - -### Maths - -For maths elements the usage is similar to standard LaTeX; whitespaces and new-lines don't matter. -To see what you can and can't do in KaTeX, refer to [their docs](https://katex.org/docs/support_table.html) or [this page](https://utensil-site.github.io/available-in-katex/). - -In JuDoc you can have - -* inline math with `$ ... $` (if you want to write a dollar symbol, you can escape it like so: `\$`) e.g.: - -```judoc -the function $ f(x)=\sin(x) $ is periodic, this is a dollar sign: \$. -``` - -* display math with `$$ ... $$` or `\[ ... \]` e.g.: - -```judoc -the identity -\[ \exp(i\pi)+1=0 \] -is nice -``` - -* display + aligned math (1) with `\begin{align} ... \end{align}` e.g.: - -```judoc -\begin{align} -a&=5 \\ -b&=7 \end{align} -``` - -* display + aligned math (2) with `\begin{eqnarray} ... \end{eqnarray}` e.g.: - -```judoc -\begin{eqnarray} -a &=& 5 \\ -b &=& 7 \end{eqnarray} -``` - -!!! note - - In LaTeX use of `eqnarray` tends to be discouraged due to possible interference with array column spacing. In JuDoc this will not happen. However it is identical with LaTeX in that the spacing around the `=` in a `eqnarray` is larger than in an `align` which you may prefer. - -!!! note - - Currently all display-math equations are numbered by default. - -A final element to keep in mind is that you should surround inequality operators with whitespaces in order to avoid ambiguous commands in KaTeX. -So in particular, both: `$0< C$` or `$0 < C$` are fine but `$0 ... ` block which you can style as you wish in your CSS stylesheet. -For instance, you may want to highlight some content with a light-yellow background, you can do this with: - -```judoc -Some text then -@@important -Some important content -@@ -and the rest of your text -``` - -and then, in your CSS, you could use - -```css -.important { - background-color: lemonchiffon; - padding-left: 0.5em; - padding-top: 0.7em; - padding-bottom: 0.5em; - border-radius: 5px; -} -``` - -which will look like - -!!! important - - Some important content - -These div blocks can be nested as in standard HTML. - -### Table of contents - -JuDoc can insert automatically generated table of contents simply by using `\toc` or `\tableofcontents` somewhere appropriate in your markdown. -The table of contents will be generated in a `jd-toc` div block, so if you would like to modify the styling, you should modify `.jd-toc ol`, `.jd-toc li` etc in your CSS. - -### Using raw HTML - -You can inject HTML by using `~~~ ... ~~~` which can be useful if, for instance, you occasionally want to use a specific layout such as text next to an image: - -```judoc -Some text here in the "standard" layout then you can inject raw HTML: - -~~~ -
-
- -

Marine iguanas are truly splendid creatures.

-

Evolution is cool.

-
-
-
-~~~ - -and subsequently continue with the standard layout. -``` - -!!! note - - In a raw HTML, you cannot use markdown, maths etc. For this reason, it is often preferable to use nested `@@divname...` blocks instead of raw HTML since those _can_ have markdown, maths, etc. in them. (See also the example generated by [`newsite`](@ref).) - -### Comments - -You can add comments in your markdown using HTML-like comments: `` possibly on multiple lines. -Note that comments are _not allowed_ in a math environment. -So this: - -```judoc -Some markdown here $\sin(\alpha+\beta)=\sin\alpha\cos\beta+\cos\alpha\sin\beta$ then - -and then some more markdown -``` - -is fine but: - -```judoc -$$ -\exp(i\pi)+1 = 0 -$$ -``` - -is not. - - -## LaTeX commands - -JuDoc allows the definition of LaTeX-like commands which can be particularly useful for repeating elements be it in or out of math environments. - -Definition of commands is as in LaTeX (with the constraint that you _must_ use the `\newcommand{...}[...]{...}` format; see examples below). - -**Example 1**: a command to get a ``\mathbb R`` in math environments: - -```judoc -\newcommand{\R}{\mathbb R} - -Let $f:\R\to\R$ a function... -``` - -**Example 2**: a command to get a ``\langle x, y \rangle`` in math environments: - -```judoc -\newcommand{\scal}[1]{\left\langle #1 \right\rangle} -``` - -**Example 3**: a command to change the colour of the text outside of a math environment (note that inside a math environment you can use `\textcolor` which is defined in KaTeX; I'm using a different name here so that these two don't clash since commands defined in JuDoc take precedence): - -```judoc -\newcommand{\col}[2]{~~~ #2 ~~~} - -And then you can use \col{tomato}{colours} in your text and -$$x + \textcolor{blue}{y} + z$$ -in your maths. -``` - -!!! note - - Command names should currently only contain letters. This could be relaxed, for instance to allow underscore and numbers (since JuDoc strictly enforces the use of braces around command arguments, it wouldn't be ambiguous). If you think that would be useful, please open an issue. - -### Nesting - -Using commands can be nested --as in LaTeX-- and, moreover, you can throw in some judoc markdown. -Here is a somewhat more sophisticated example for a "definition" environment: - -```judoc -\newcommand{\definition}[2]{@@definition **Definition**: (_!#1_) #2 @@} - -\definition{angle between vectors}{ - Let $x, y \in \R^n$ denote two real vectors and let $\scal{\cdot, \cdot}$ denote - the inner product of two vectors. Then, the angle $\theta$ between $x$ and $y$ is - given by $$ \cos(\theta) = {\scal{x,y}\over \scal{x,x} \scal{y,y}} $$ } -``` - -with CSS - -```css -.definition { - background-color: aliceblue; - border-left: 5px solid cornflowerblue; - border-radius: 10px; - padding: 10px; -} -``` - -it will look like - -![](../assets/ex-definition.png) - -Of course, you can also nest definitions: - -```judoc -\newcommand{\norm}[2]{\left\|#1\right\|_{#2}} -\newcommand{\anorm}[1]{\norm{#1}{1}} -\newcommand{\bnorm}[1]{\norm{#1}{2}} - -Let $x\in\R^n$, there exists $0 < C_1 \le C_2$ such that - -$$ C_1 \anorm{x} \le \bnorm{x} \le C_2\anorm{x}. $$ -``` - -where the final equation would look like ``C_1 \|x\|_1 \le \|x\|_2 \le C_2\|x\|_1``. - -### Whitespaces - -In a JuDoc newcommand, to refer to an argument, you can use `#1` or `!#1`. -There is a subtle difference: the first one introduces a space left of the argument (this allows to avoid ambiguous commands in general) and the second one does not. -In general whitespaces are irrelevant and will not show up and so the usual `#1` is the recommended setting. -However, there are cases where the whitespace does appear and you don't want it to (e.g. outside a math environment if the command is directly preceded by something). -In those cases, and provided there is no ambiguity (e.g.: due to chaining commands), you can use `!#1` which will *not* insert the whitespace. -For instance: - -```judoc -\newcommand{\pathwith}[1]{`/usr/local/bin/#1`} -\newcommand{\pathwithout}[1]{`/usr/local/bin/!#1`} -``` - -* `\pathwith{hello}` will give `/usr/local/bin/ hello` which would be inappropriate whereas -* `\pathwithout{hello}` will give `usr/local/hello`. - -### Local vs global - -The commands you define will be available _only_ within the page you define them in. -However, if you would like to define commands that are _globally_ available to all pages, then you should simply put these definitions in `src/config.md`. - -### Hyper-references - -Three types of hyper-references are supported: - -* for display math, -* for bibliography references, -* for specific anchor points in the page. - -The syntax for all three is close to that of standard LaTeX (see below). - -To style the appearance of the maths or bib links in CSS, use `.jd-content.eqref a` and `.jd-content.bibref a` classes; for instance: - -```css -.jd-content .eqref a {color: blue;} -.jd-content .bibref a {color: green;} -``` - -#### Equations - -To label an equation, just use `\label{some label}` in the math environment and, to refer to it, use `\eqref{some label}`: - -```judoc -Some equation: - -$$\exp(i\pi) + 1 = 0 \label{a cool equation}$$ - -and you can refer to it in the text like so, equation \eqref{a cool equation}. -``` - -As in LaTeX, you can refer to several equations in one by separating names with commas: `\eqref{some label, some other}` (and so you should not use commas in your labels). - -#### Bibliography - -For bibliography references, you can use `\biblabel{short}{name}` to indicate a bibliography reference which will appear as a clickable link `(name)` or `name` and can be referred to by `short`: - -```judoc -In the text you may refer to \citep{noether15, bezanson17} while in a bibliography -section you would have - -* \biblabel{noether15}{Noether (1915)} **Noether**, Korper und Systeme rationaler Funktionen, 1915. -* \biblabel{bezanson17}{Bezanson et al. (2017)} **Bezanson**, **Edelman**, **Karpinski** and **Shah**, [Julia: a fresh approach to numerical computing](https://julialang.org/publications/julia-fresh-approach-BEKS.pdf), SIAM review 2017. -``` - -The `name` argument therefore corresponds to how the bibliography reference will appear in the text. -In the case above, the text will lead to - -``` -... refer to (Noether (1915), Bezanson et al. (2017)) while ... -``` - -You can use - -* `\cite{short1, short2}` or `\citet{short3}`: will not add parentheses around the link(s), -* `\citep{short4, short5}`: will add parentheses around the link(s). - -As in LaTeX, if the reference is undefined, the command will be replaced by **(??)**. - -!!! note - - In the future, there may be a possibility to define specific bibliography styles. - I've not yet come around to it but feel free to open an issue if you would like this or would like to suggest a way to do it. - -#### Anchor points - -You can specify anchor points on the page by using `\label{name of the anchor}` anywhere on the page outside of maths environment. -This will insert an anchor: - -```html - -``` - -You can subsequently add a link to it on the same page: - -```judoc -[link to it](#name-of-the-anchor) -``` - -or from another page by prepending it with the path to the page, for instance: - -```judoc -[link to it](/index.html#name-of-the-anchor) -``` - -Note also that all section headers are anchor points for instance - -```judoc -### Some subtitle -``` - -can be linked to with `#some-subtitle`. - -!!! note - - In the future, a number will be appended to anchor-points corresponding to section headers so that if you have two headers with the same name, the links can be differentiated (issue [#180](https://github.com/tlienart/JuDoc.jl/issues/180)). (Same as Documenter.jl.) - - -## Code insertions - -As per Common Mark specifications, you have multiple ways of inserting code: - -* **inline code**: you can use single backticks (\`) or double backticks (\`\`) (if the code contains single ticks) like so: - -`````judoc -This is some `inline code` or ``inline ` code with a tick``. -````` - -* **code blocks**: it is recommended to use triple backticks (\`\`\`) optionally followed by a language name for highlighting like so: - -`````judoc -This is some julia code: -```julia -a = 2 -@show a -``` -````` - -* **code blocks 2**: you can also use indented code blocks (lines starting with four spaces or a tab) (but _fenced code blocks should be preferred_) - -`````judoc -This is some code: - - a = 2 - @show a -````` - -**Note**: when either using indented code blocks or using fenced code blocks with no language name, then the code language for highlighting can be specified with the local page variable `lang` i.e. `@def lang = "julia"` (which is the default) or `@def lang = ""` if you don't want the code to be highlighted. - -Sometimes, when presenting code in a post, you would like to make sure the code works and it can be annoying to have to copy-paste it around then copy its output, especially if you decide to make modifications on the way in which case you have to repeat the process. - -In JuDoc there are two ways to do this. - -1. For Julia code, a **live-evaluation** of code blocks is supported not unlike the [Weave.jl](https://github.com/mpastell/Weave.jl) package, -1. For all languages, you can run the script separately and insert the code and/or the output of the code in the page. - -### On-the-fly evaluation - -!!! note - - **Evaluation time**: it is important to realise that when the code block is created or modified and the page is saved, it will trigger a page compilation that will _wait_ for the evaluation of the code block to complete. So if your code block takes a long time to execute, the page will not be updated before that's done. - That being said, if you don't modify the code block, it will only be executed **once** as the output is saved to file. - -!!! note - - **Sandboxing**: on-the-fly evaluation of code blocks is still a bit experimental. Among other things, the code is _not sandboxed_ which means that if you have two code blocks one after the other, the second one has access to what's defined in the first. This is natural within the same page, but it also works _across_ pages. However, it would be really bad practice to rely on this as the order in which pages are compiled is not always the same. - In short: take a page as a Julia notebook and make sure all your variables and functions you use are defined on that page. - -Code blocks that should not be evaluated should be added as per standard markdown, so for instance: - -`````judoc -```julia -a = 10 -``` -````` - -Code blocks that should be evaluated should be added with `julia:path/to/script` where `path/to/script` indicates _where_ the script corresponding to the code block will be saved (**note**: the given path _must_ be in UNIX format even if you're using Windows) - -`````judoc -```julia:./code/ex1 -a = 10 -@show a -``` -````` - -What this will do is: - -1. write the code to the file `/assets/[subpath]/code/ex1.jl` -1. run the code and capture its output (`STDOUT`) and write it to `/assets/[subpath]/code/output/ex1.out` - -The `[subpath]` here is the _exact same sub-path structure_ than to the page where the code block is inserted. -To clarify, let's say you wrote the above code-block in - -``` -/src/pages/folder1/page1.md -``` - -then with the syntax above, the script will be saved in - -``` -/assets/pages/folder1/code/ex1.jl -``` - -#### More on paths - -There are three ways you can specify where the script corresponding to a code-block should be saved. - -1. _relative to the page_: `./[p]/script` is as above, it will write the code block to `/assets/[subpath]/p/script.jl` where `subpath` corresponds to the sub-path of the page where the code block is inserted (path below `/src/`) -1. _relative to the assets dir_: `p/script` will write the code block to `/assets/p/script.jl` -1. _full path_: `/p/script` will write the code block to `/p/script.jl` - -**Note**: when code blocks are evaluated, their output (`STDOUT`) is captured and saved at `[path]/output/script.out` where `[path]` is what precedes `script.jl` in the cases above. - -#### Inserting the output - -Let's say you've added the following code block: - -`````judoc -```julia:./code_pg1/ex1 -using LinearAlgebra -a = [1, 2, 3] -@show dot(a, a) -``` -````` - -In order to show the raw output, just write - -```judoc -\output{./code_pg1/ex1} -``` - -which in the present example will introduce exactly the following HTML - -```html -
dot(a, a) = 14
-``` - -and will look like - -``` -dot(a, a) = 14 -``` - -If you now change the vector `a` in the code block, the page will be re-compiled with the code-block re-evaluated and the new output will be shown. - -If you would like the output to appear as text (not a code block), you can use `\textoutput` instead. -Here's an example: - -`````judoc -```julia:./code_pg1/ex2 -using Statistics -temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24) -println("The _average_ temperature is **$(mean(temps))°C**.") -``` -\textoutput{./code_pg1/ex2} -````` - -Which will appear as: - -```julia -using Statistics -temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24) -println("The _average_ temperature is **$(mean(temps))°C**.") -``` - -The _average_ temperature is **16.3°C**. - -#### Hiding lines - -Sometimes you may want to run some lines but hide them from the presentation, for this just use `# hide` at the end of the line (`hide` is not case sensitive so `# HiDe` would be fine too): - -`````judoc -```julia:./code_pg1/ex1 -using LinearAlgebra # hide -a = [1, 2, 3] -@show dot(a, a) -``` -````` - -You could also hide the entire code block if you only care about the output, for this put a `# hideall` on any line: - -`````judoc -```julia:./code_pg1/ex2 -#hideall -using Statistics -temps = (15, 15, 14, 16, 18, 19, 20, 12, 10, 24) -println("The _average_ temperature is **$(mean(temps))°C**.") -``` -\textoutput{./code_pg1/ex2} -````` - -Which will appear as just: - -The _average_ temperature is **16.3°C**. - -### Separate evaluation - -The philosophy here is: - -* keep your code snippets in appropriate subfolders of `/assets/` where they can be run and their output can be saved, this can be compared to a `test/` folder in a Julia package, -* run some or all of the snippets (before running JuDoc), -* use `\input{...}{...}` in your markdown (see below) and when the website is updated, it will plug-in the most recent parts that have been generated. - -That way, if you modify the code, everything will be updated on the website too while ensuring that the code actually runs and generates the output you're displaying. - -Again, the script files can contain `# hide` at the end of lines you do not want to show. - -The `generate_results.jl` file should run the scripts and redirect outputs to the `assets/[path]/output` directory. -You can use something like the script below (if you generate an example website with [`newsite`](@ref), it's already in there) though you can of course modify it as you wish. - -```julia -dir = @__DIR__ -""" - genplain(s) - -Small helper function to run some code and redirect the output (stdout) to a file. -""" -function genplain(s::String) - open(joinpath(dir, "output", "$(splitext(s)[1]).out"), "w") do outf - redirect_stdout(outf) do - include(joinpath(dir, s)) - end - end -end -# run `script1.jl` and redirect what it prints to `output/script1.out` -genplain("script1.jl") -# run `script2.jl` which has a savefig(joinpath(@__DIR__, "output", "script2.png")) -include("script2.jl") -``` - -The function `genplain("scriptname.jl")` just redirects the output of the script to `output/scriptname.out`. -So for instance if you have in `assets/scripts/script1.jl` - -```julia -print("hello") -``` - -Then `genplain("script1.jl")` will generate `/assets/scripts/output/script1.out` with content - -```julia -hello -``` - -!!! note - - You could have scripts in any language here (`R`, `Python`, ...) as long as the folder structure is the same. - -#### Inserting code - -In order to insert the code of a script and have it highlighted you can use - -```judoc -\input{julia}{scripts/script1.jl} -``` - -or `\input{code:julia}{scripts/script1.jl}`. This will insert the content of the file `/assets/scripts/script1.jl` (see also the section earlier on paths) into a block that will be highlighted as julia code. - -#### Plain-text output - -In order to insert the plain-text output of a script, you can use - -```judoc -\input{output}{scripts/script1.jl} -``` - -or `\input{output:plain}{scripts/script1.jl}`. This will insert the content of the file `/assets/scripts/script1.out` into a non-highlighted code-block. - -#### Plot output - -In order to insert a plot generated by a script, you can use - -```judoc -\input{plot}{scripts/script1.jl} -``` - -or `\input{plot:id}{scripts/script1.jl}`. This will look for an image file with root name `/assets/scripts/script1.ext` where `ext` is `gif, png, jp(e)g, svg`. -If you use `plot:id` then it will look for an image file with root name `/assets/scripts/script1id.ext`. - -The `plot:id` option is useful if you have a script that generates several plots for instance. - -#### Slicing up - -The structure in the `generate_results.jl` effectively means that all your code is run as one big script. -This also means that if you want to slice some of your code in several parts and show intermediate outputs (e.g. plots), well you can just do that by having a `script_1_p1.jl`, `script_1_p2.jl` etc. and then just use `\input` multiple times. - -## File insertions - -A few commands are defined to help you with insertions of content; you can also define your own commands using custom HTML as was discussed before. - -### Inserting a figure - -The commands -* `\figalt{alt}{path}`, and -* `\fig{path}` -are convenient commands to insert figures. -Of course you're free to use the default markdown way `![alt](full_path)` instead. -One difference with these commands though is that they allow the use of relative paths (see [the point on paths](#More-on-paths-1)); this can be convenient in order to organise your assets as you organise your pages. - -**Note**: as sometimes figures are generated by code, it is sometimes convenient to save them in a `path/output/` subfolder. -The `\fig` and `\figalt` will try to look both in `path` and `path/output` so that you don't have to think about it. -Likewise, if the extension is not provided, JuDoc will try common ones. -For instance, all of these will work: - -`````judoc -```julia:./ex1 -using PyPlot -figure() -plot([0, 1], [0, 1]) -savefig(joinpath(@__DIR__, "output", "test.png")) -``` -\fig{./test} -\fig{./output/test} -\fig{./test.png} -````` - -### Linking a file - -The command -* `\file{name}{path}` -is a convenient way to link to a local asset (e.g. a pdf file). -Again, you could use the default markdown way `[name](full_path)` but, as for the fig commands, this allows the use of relative paths. - -### Inserting markdown - -In some situation, you may have some markdown in a file which you may want to include somewhere else. -This can be achieved thanks to the `\textinput{path}` commmand. -The path specification is as the other commands, and the text will be formatted. - -As an example you could have in `/assets/ccc/sidefile.md`: - -```judoc -some **markdown** in a side file. -``` - -where in `/src/index.md`: - -```judoc -This is the index then \textinput{ccc/sidefile} -``` - -and this will be equivalent to just having in `/src/index.md`: - -```judoc -This is the index then some **markdown** in a side file. -``` - -**Note**: if you don't specify a file extension, `.md` is appended to the specified path. - -### Inserting a table - -You can insert tables directly from CSV files with the `\tableinput{header}{path}` command. -If you generate the file on-the-fly, you should follow this example: -`````judoc -```julia:./tableinput/gen -testcsv = "h1,h2,h3 -152,some string, 1.5f0 -0,another string,2.87" -write("assets/pages/tableinput/testcsv.csv", testcsv) -``` -````` -Then you can insert the table with: -`````judoc -\tableinput{}{./tableinput/testcsv.csv} -````` -Which will result in: - -| h1 | h2 | h3 | -| --- | -------------- | ----- | -| 152 | some string | 1.5f0 | -| 0 | another string | 2.87 | -In this case given no header was specified in the call, a header was generated from the first line in the CSV (here: h1, h2, h3). - -If your file doesn't have a header, you can specify it in the call: -`````judoc -```julia:./tableinput/gen -testcsv = "152,some string, 1.5f0 -0,another string,2.87" -write("assets/pages/tableinput/testcsv2.csv", testcsv) - -\tableinput{custom h1,custom h2,custom h3}{./tableinput/testcsv2.csv} -````` - -| custom h1 | custom h2 | custom h3 | -| --------- | -------------- | --------- | -| 152 | some string | 1.5f0 | -| 0 | another string | 2.87 | - -With the above in mind, you can also include existing CSV files. - -!!! note - - The look of the table will be defined by your CSS stylesheet. - -There's a couple of rules that you have to keep in mind when using the `\tableinput{}{}` command: - -* Columns must be separated by a comma (`,`). -* If a header is specified, its length must match the number of columns in the file. - -## Page variables - -Page variables are a way to interact with the HTML templating. -In essence, you can define variables in the markdown which can then be called or used in the HTML building blocks that are in `src/_html_parts/`. - -!!! note - - Page variables are still somewhat rudimentary and while the syntax for declaring a variable will likely not change, the way they are used will almost certainly be refined in the future (see also [Templating](@ref)). - -### Local page variables - -The syntax to define a page variable in markdown is to write on a new line: - -```judoc -@def variable_name = ... -``` - -where whatever is after the `=` sign should be a valid Julia expression (Julia will try to parse it and will throw an error if it can't). -Multiline definitions are not (yet) allowed but if you have a need for that, please open an issue. -The idea is that these variables are likely to be rather simple: strings, bools, ints, dates, ... -I don't yet see a usecase for more involved things. - -Once such a variable is defined you can use it with the templating syntax (see [Templating](@ref)). -For instance in your `src/index.md` you could have - -```judoc -@def contributors = "Chuck Norris" -``` - -and in your `src/_html_parts/head.html` you could have - -```html -{{isdef contributors}} -This page was written with the help of {{fill contributors}} -{{end}} -``` - -since `contributors` is a _local page variable_ that is defined in `src/index.md`, the corresponding `index.html` will show "_This page was written with the help of Chuck Norris_"; however on any other page, this will not show (unless, again, you define `@def contributors = ...` there). -See also [Templating](@ref) for how page variables can be used in the HTML. - -#### Default variables - -A few variables are already present and used in the basic templates (you can still modify their value though it has to match the type): - -| Name | Accepted types | Default value | Function | -| :-------- | :------------- | :------------ | :------- | -| `title` | `Nothing`, `String` | `nothing` | title of the page (tab name) -| `hasmath` | `Bool` | `true` | if `true` the KaTeX stylesheet and script will be added to the page -| `hascode` | `Bool` | `false` | if `false` the highlight stylesheet and script will be added to the page -| `date` | `String`, `Date`, `Nothing` | `Date(1)` | a date variable -| `lang` | `String` | `"julia"` | the default language to use for code blocks -| `reflinks`| `Bool` | `true` | whether there may be referred links like like `[link][id]` and `[id]: some/url`, turn this to false if your code has patterns like `[...]: ...` which are **not** link definitions (see also [quirks](#Quirks-1)) - -Then there are some variables that are automatically assigned and that you should therefore **not** assign yourself (but you can use them): - -| Name | Type | Value | Function | -| :--- | :------------- | :------------ | :------- | -| `jd_ctime` | `Date` | `stat(file).ctime` | page creation date -| `jd_mtime` | `Date` | `stat(file).mtime` | last page modification date - - -### Global page variables - -You can also define _global page variables_ by simply putting the definition in the `src/config.md` file. -For instance you may want to have a single main author across all pages and would then write - -```judoc -@def author = "Septimia Zenobia" -``` - -in the `src/config.md` file. - -You can overwrite global variables in any page by redefining it locally. -For instance you could set `hasmath` globally to `false` and `hascode` globally to `true` and then modify it locally as appropriate. - -There are also a few pre-defined global variables: - -| Name | Accepted types | Default value | Function | -| :------------ | :------------- | :------------ | :------- | -| `author` | `String`, `Nothing` | `THE AUTHOR` | author (e.g. may appear in footer) -| `date_format` | `String` | `U dd, yyyy` | a valid date format specifier -| `prepath` | `String` | "" | if the website is meant to be a _project_ website on GitHub for instance corresponding to a repo `github.com/username/repo` as opposed to `github.com/username.github.io`, then all url paths should be prepended with `repo/` which you can do by specifying `@def prepath = "repo"` (see also [hosting the website as a project website](/man/workflow/#Hosting-the-website-as-a-project-website-1))| diff --git a/docs/src/man/templating.md b/docs/src/man/templating.md deleted file mode 100644 index 7b5fdbd57..000000000 --- a/docs/src/man/templating.md +++ /dev/null @@ -1,173 +0,0 @@ -# Templating - -This page is about the templating syntax that is used in JuDoc which allows you to have some control over the generated HTML. -It can be useful as a way to, depending on the page, - -* adjust the layout, -* specify elements that should be inserted in the page such as date of last modification, page author(s), etc., -* specify auxiliary elements that should be loaded with the page such as stylesheets or javascript libraries, -* ... - -!!! note - - The templating system is still rudimentary at this point and is likely to be significantly improved over time (your help and suggestions are welcome!). - -**Contents**: - -* [Basic syntax](#Basic-syntax-1) -* [Conditional blocks](#Conditional-blocks-1) - * [Base conditional blocks](#Base-conditional-blocks-1) - * [`isdef` conditional blocks](#isdef-conditional-blocks-1) - * [`ispage` conditional blocks](#ispage-conditional-blocks-1) -* [Function blocks](#Function-blocks-1) - -## Basic syntax - -When developing your website, you can define global or local page variables using - -```judoc -@def varname = ... -``` - -either in the `src/config.md` file (in which case the variable is global) or in a specific page (in which case the variable is local or overwrites a global one). -See also the page on the markdown [Syntax](@ref). - -These variables can subsequently be called in "HTML Blocks" in a way that is inspired from Hugo's templating system via `{{...}}`. -These blocks would be placed in the HTML layout building blocks files that are in `src/_html_parts/`. - -A simple example is the insertion of a string defining the title of the page (which would appear the tab name). -In the markdown of `src/path/page1.md` you would have: - -```judoc -@def title = "Title for page 1" -``` - -and in `src/_html_parts/head.html` you would have - -```html -{{fill title}} -``` - -This HTML block has the form `{{function_name a b ...}}` where `a`, `b`, ... are page variable names. -Here the `fill` function simply tries to find a page variable `"title"` and places its content here so that in the final generated HTML, there would be: - -```html -Title for page 1 -``` - -See [function blocks](#Function-blocks-1) for additional such functions that can be used. - -!!! note - - Whitespaces in HTML blocks are irrelevant as long as the different parts are separated by at least one so for instance `{{fill title }}` or `{{ fill title}}` would both be fine. - -## Conditional blocks - -It will often be handy to do things in your layout conditional on specific variables. -For instance you may want to highlight elements in your navbar depending on which page you're on. - -Three types of conditional blocks are allowed: - -* a "classical" conditional block with `if`, `elseif`, `else` that accepts page variables that have boolean value, -* a conditional block that does something provided a variable exists (or not), -* a conditional block that does something depending on whether the page is a specific one (or not). - -!!! note - - Nesting of conditional blocks is currently **not allowed** but shouldn't be hard to implement and will likely be supported in the future. - -### Base conditional blocks - -Such blocks have the structure - -```html -{{if vname1}} -... -{{elseif vname2}} -... -{{else}} -... -{{end}} -``` - -where the `{{elseif ... }}` and `{{else}}` blocks are optional. -They work as you would expect: look up the variables `vname1` in the currently available page variables, if it doesn't exist an error will be shown and the whole conditional block will be ignored, otherwise the value is retrieved and depending on whether it is `true` or `false` the relevant blocks will be executed. - -As a simple example consider a variable `draft` which you could use to control the addition of a banner at the top of a page indicating it's still work in progress: - -in `src/pages/pg1.md` you would have - -```julia -@def draft = true -``` - -while in `src/_html_parts/head.html` you could have - -```html -{{if draft}} -
- This is currently work in progress! -
-{{end}} -``` - -### `isdef` conditional blocks - -The `{{isdef vname}}` or `{{isnotdef vname}}` are blocks that do something depending on whether a specific variable exists (or not): - -```html -{{isdef author}} -... -{{end}} -``` - -Such blocks can be useful where you sometimes want something to be defined and sometimes not. - -For instance, you may want to add a title if the variable `title` exists: in the markdown you would then either have `@def title = ...` or not and in the `head.html`: - -```html -{{isdef title}} -{{fill title}} -{{end}} -``` - -!!! note - - Currently these blocks do not accept `{{else}}` statements but this should be supported in the near future. - -### `ispage` conditional blocks - -The `{{ispage path/to/page}}` or `{{isnotpage path/to/page}}` are blocks that do something depending on whether the page is a specific one (or not). -For instance in the `pure-sm` template, in the `head.html` you will see elements for the side menu with - -```html -
  • - Home -
  • -``` - -which add a class to a `
  • ` object depending on the page that indicate which list item should be styled as a "selected" button depending on the page we're on. - -!!! note - - As for the def blocks above, these blocks do not yet accept `{{else}}` statements. - -## Function blocks - -These are blocks of the form - -```html -{{f_name p1 p2}} -``` - -where `f_name` is a function name (see below) and `p1`, `p2` would be variable names that correspond to arguments of the function. - -| Name | #params | Example | Role | -| :------------ | :------------------- | :------ | :--- | -| `fill` | 1 | `{{fill author}}` | replaces the block with the value of the page variable -| `insert` | 1 | `{{insert path/to/file}}` | replaces the block with the content of the file at `path/to/file` - -!!! note - - If you would like to have more of those, please open an issue and explain the use-case, I'll be happy to expand the list. diff --git a/docs/src/man/themes.md b/docs/src/man/themes.md deleted file mode 100644 index 4d49eac6b..000000000 --- a/docs/src/man/themes.md +++ /dev/null @@ -1,290 +0,0 @@ -# Themes - -```@raw html -The pre-defined themes/templates that are currently available can be viewed here (opens in a new tab). -``` - -In this section, you will learn how to build a layout from one online. -It should also help clarify the structure of the files that define the layout. -If you end up doing this yourself and assuming you're happy with the result, a PR to [JuDocTemplates](https://github.com/tlienart/JuDocTemplates.jl) would be very welcome! - -## Adapting a theme to JuDoc - -As an example, I'll take [Jemdoc's site](http://jemdoc.jaboc.net/) both because it's a pretty simple layout and as a way to honour its legacy since JuDoc was inspired from it. - -Jemdoc's layout looks like this: - -![](../assets/jemdoc1.png) - -### Getting started - -In order to get a blueprint for the folder etc, let's first create a site according to the `basic` template: - -```julia-repl -julia> newsite("jemdoc", template="basic") -``` - -You can serve the site in order to see the modifications directly in your browser which can be useful to fine tune the port of the layout. - -We will need to provide the appropriate stylesheet in `src/_css` and adjust the layout part in `src/_html_parts`. - -### Adapting the head and foot - -The file `src/_html_parts/head.html` is the most important one you will have to adjust. - -Let us first change the name of the main stylesheet `src/_css/basic.css` into `src/_css/jemdoc.css` which is more appropriate. -The reference to the stylesheet in `head.html` consequently has to be changed to mention `jemdoc.css` instead of `basic.css`: - -```html - -``` - -The steps here subsequently quite simple: - -1. look at the original html code -2. copy whatever comes before the content into `head.html` - -Let's do this gradually. -The top of the original HTML can be ignored at this point so we can start modifying starting after ``. - -Jemdoc's body starts with a Google analytics script which I'll ignore as well. -We then have effectively one big table element. -Stripped from its content and simplified it looks like: - -```html - - - - - -
    - - - - - - - -

    CONTENT HERE

    - -
    -``` - -Note that I've already filled in the `href=` in the links to sub-menus. - -The "`CONTENT HERE`" part is where what JuDoc generates from Markdown will go. -Therefore, anything that is *after* that should go in `foot.html`; in our current case: - -```html - - - - -``` - -That's basically it (though we still have to modify the stylesheet of course). -The `head.html` should be adapted to: - -```html - - - - - - {{if hasmath}} {{insert head_katex.html }} {{end}} - {{if hascode}} {{insert head_highlight.html }} {{end}} - - - - {{isdef title}} {{fill title}} {{end}} - - - - - - - -
    - - - - - - - - - -``` - -and the `foot.html` should be adapted to: - -```html - -
    - {{ if hasmath }} - {{ insert foot_katex.html }} - {{ end }} - {{ if hascode }} - {{ insert foot_highlight.html }} - {{ end }} - - -``` - -### Adapting the stylesheet - -Of course by now the page looks horrendous: - -![](../assets/jemdoc2.png) - -the content is not centred in its box and overflows on the right, the menu looks ridiculous, time to do some CSS styling! - -Let's start by removing everything from `src/_css/jemdoc.css`. -Most of what's in there was used for the styling of the top navbar which we don't have anymore (note that the styling of the content itself is in `judoc.css`, don't change that for now; note also that `jemdoc.css` is loaded *after* `judoc.css` so that you can overwrite the styles there). - -Let's now just copy paste the content of the [two](http://jemdoc.jaboc.net/jemdoc.css) [original](http://jemdoc.jaboc.net/jacob.css) stylesheets into ours and hope for the best, we may have some fine-tuning to do after this. - -Doing nothing else than copy pasting already starts to look quite civilised: - -![](../assets/jemdoc3.png) - -but a few small things should be fixed: - -1. there's too little space at the top -1. the menu is a bit too narrow and there's a bit too much space between the menu and the content -1. there's not enough space after `
    ` blocks
    -
    -#### Fixing spacing
    -
    -Firefox or Chrome/ium's excellent dev-tools are super helpful to fine tune stylesheets.
    -Here things are pretty straightforward though.
    -
    -Firstly we need to add vertical padding above `

    ` level title: - -```css -h1 { padding-top: 2em; } -``` - -Then, let's widen the menu a little - -```css -td#layout-menu { - padding-left: 15px; - padding-right: 25px; -} -``` - -and let's reduce the padding on the left of the `jd-content` element: - -```css -.jd-content { padding-left: 5%; } -``` - -Thirdly, in the original stylesheet there is this element: - -```css -pre { - padding: 0; - margin: 0; -} -``` - -which you can just remove to have a bit more space around code blocks. - -There's probably still things that could be done to improve the layout overall (and make it more responsive!) but we'll leave it at that. - -![](../assets/jemdoc4.png) - -### Adjusting other files - -Here we don't need to adjust anything else but you could want to adjust the pages in another context: - -* `head_highlight`, `head_katex`, `foot_highlight` and `foot_katex` are probably best left as they are, they will be appended if need be to pages (see in `head` and `foot` the `{{if hasmath}}` and `{{if hascode}}` blocks) -* `page_foot` you may want to change, it defines what goes at the bottom of the `.jd-content` div. - -By default `page_foot` looks like - -```html -
    - -
    -``` - -It should be fairly straightforward to adapt that to your needs. - -## Making a PR to the theme repo - -Let's say you've built your own template and are pretty happy with the result and you'd like to share it for other users, great! thanks for being a good citizen. - -### Create a new folder - -Head to the [JuDocTemplates.jl](https://github.com/tlienart/JuDocTemplates.jl) repository and make a PR. -The key is to keep track of what you've modified and what was left as before so that the repo is not cluttered with copies of the same file. - -In the example above the following files were changed: - -* `head.html` and `foot.html`, -* `jemdoc.css` the stylesheet. - -The JuDocTemplates repository automatically fills in the gap so you just have to provide the files that have changed. -Imitate the structure corresponding to [`basic`](https://github.com/tlienart/JuDocTemplates.jl/tree/master/src/templates/basic/src): - -``` -. -└── src - ├── _css - │   └── basic.css - └── _html_parts - └── head.html -``` - -So in the case of `jemdoc`, I will create a new folder `jemdoc` in `src/templates/` with - -``` -. -└── src - ├── _css - │   └── jemdoc.css - └── _html_parts - ├── foot.html - └── head.html -``` - -### Add your template to the list - -Next, you need to indicate the new template in `JuDocTemplates.jl` by simply adding it to the `LIST_OF_TEMPLATES` constant. - -Then, you need to add a description for your template in `docs/make.jl` (please respect the alphabetical order): - -```julia -"jemdoc" => """ - jemdoc -

    Simple theme with a side navigation bar, no extra javascript and a simple stylesheet. (Adapted from the original Jemdoc theme.)

    - """, -``` - -Lastly you need to take a screenshot of what the template looks like of size 480x480, put it in `docs/thumb` and adjust `docs/index_head.html` following the example of the other templates: - -```css -#jemdoc { - background: url("thumb/jemdoc.png"); - background-size: contain; -} -``` - -### Check that things work - -Finally, you need to check that everything works (which is the first thing I'll do when reviewing your PR). -For that: first run the file `docs/make.jl`; this will generate a website in `docs/build` then using for instance [`LiveServer.jl`](https://github.com/asprionj/LiveServer.jl), check the generated website and that the demo corresponding to your template works as expected. - -And that's it! thanks a lot! diff --git a/docs/src/man/troubleshooting.md b/docs/src/man/troubleshooting.md deleted file mode 100644 index 695565e32..000000000 --- a/docs/src/man/troubleshooting.md +++ /dev/null @@ -1,56 +0,0 @@ -# Troubleshooting - -This page is about some of the known errors you may encounter when using JuDoc and how to deal with them. -If you encounter an error that is not mentioned here, then it's probably a bug and it would be great if you could open an issue! - -* [Error on interruption](#Error-on-interruption-1) -* [IOStream error](#IOStream-error-1) - - -## Error on interruption - -You may (rarely) get an an error thrown at you when interrupting the server with `+C`, particularly when using Juno. -There are a couple of reasons this may happen, both unrelated to JuDoc. - -### Juno - -Juno (very rarely) crashes if you coincidentally press `+C` while Juno is doing something in the background (Juno issue [#309](https://github.com/JunoLab/Juno.jl/issues/309)). - -The stacktrace you will see will seem particularly obscure, for instance: - -``` -InterruptException: -_string_n at string.jl:60 [inlined] -StringVector at iobuffer.jl:31 [inlined] -#IOBuffer#320(::Bool, ::Bool, ::Nothing, ::Bool, ::Int64, ::Int64, ::Type{Base.GenericIOBuffer{Array{UInt8,1}}}) at iobuffer.jl:114 -(...) -``` - -or - -``` -julia> "miniERROR: InterruptException: -Stacktrace: - [1] poptaskref(::Base.InvasiveLinkedListSynchronized{Task}) at ./task.jl:564 - [2] wait() at ./task.jl:591 -(...) -``` - -**Solution**: ignore the error, restart Julia. - -### Not-Juno - -The [`LiveServer.jl`](https://github.com/asprionj/LiveServer.jl) package, which handles the live-serving of the files, is based upon [`HTTP.jl`](https://github.com/asprionj/LiveServer.jl). -The latter has a fairly complex codebase with a number of asynchronous tasks and is known to sometimes crash in (somewhat) mysterious ways. - -If the stacktrace mentions `uv_write`, `uv_write_async`, `libuv` or something of the sorts, then this is it. - -Like the "Juno" case, these errors are caused when you happen to press interrupt just as the package was doing something important in the background. -This is very rare but can happen and you can safely ignore it. - -**Solution**: ignore the error, restart Julia. - - -## IOStream error - -See the comment about HTTP.jl in the [subsection above](#Not-Juno-1). diff --git a/docs/src/man/workflow.md b/docs/src/man/workflow.md deleted file mode 100644 index d0d064b7c..000000000 --- a/docs/src/man/workflow.md +++ /dev/null @@ -1,409 +0,0 @@ -# Workflow - -In this section it is assumed that you will eventually host your website on GitHub or GitLab but it shouldn't be hard to adapt to your particular case if you intend to self-host or use another service. - -**Contents**: - -* [Local editing](#Local-editing-1) - * [Folder structure](#Folder-structure-1) -* [Libraries](#Libraries-1) - * [Highlight](#Highlight-1) -* [Hosting the website](#Hosting-the-website-1) - * [Hosting the website as a project website](#Hosting-the-website-as-a-project-website-1) -* [Optimisation step](#Optimisation-step-1) -* [(git) synchronisation](#(git)-synchronisation-1) - * [Merge conflicts](#Merge-conflicts-1) -* [Using Literate.jl](#Using-Literate.jl-1) - -## Local editing - -To get started, the easiest is to use the [`newsite`](@ref) function to generate a website folder which you can then modify to your heart's content. -The command takes one mandatory argument: the name of the folder, and you can specify a template with `template=...`: - -```julia-repl -julia> newsite("Test"; template="pure-sm") -✓ Website folder generated at Test (now the current directory). -→ Use `serve()` from `JuDoc` to see the website in your browser. -``` - -```@raw html -Click here for a demo of the supported templates (opens in a new tab). -``` - -Once you have created a new site with the template of your choice and are in the corresponding folder (`newsite` will `cd` to the new folder) you can serve your website with - -```julia-repl -julia> serve() -✓ LiveServer listening on http://localhost:8000/ ... - (use CTRL+C to shut down) -``` - -and navigate in a browser to the corresponding address to see the website being rendered. - -!!! note - - If you're using the Atom editor, you may like to use the _Atom browser_ extension which allows you to have a browser in an Atom pane. - -### Folder structure - -The [`newsite`](@ref) command above generates folders and examples files following the appropriate structure, so the easiest is to start with that and modify in place. -The main folders (generated by `newsite`) are: - -``` -. -├── assets/ -├── libs/ -└── src/ -``` - -Once you run [`serve`](@ref) the first time, two additional folders are generated (`css/` and `pub/`) along with the landing page `index.html`. - -Among these folders, - -* the **main folder** is `src/` and its subfolders, this is effectively where the source for your site is, -* you should _ignore_ `css/` and `pub/` these are _generated_ and any changes you'd do there will be silently over-written whenever you modify files in `src/`; the same comment holds for `index.html`, -* the folders `assets/` and `libs/` contain _auxiliary items_ that are useful for your site: `assets/` would contain code snippets, images etc. while `libs/` would contain javascript libraries that you may need (KaTeX and highlight are in there by default). - -In the `src/` folder, the structure is: - -``` -. -├── _css -│   ├── judoc.css -│   └── ... -├── _html_parts -│   ├── foot.html -│   ├── head.html -│   └── ... -├── config.md -├── index.md -└── pages - ├── page1.md - └── ... -``` - -**Pages** - -The `index.md` will generate the site's landing page. -The `pages/page1.md` would correspond to pages on your website (you can have whatever subfolder structure you want in there, and will just have to adapt internal links appropriately). -See also the [Syntax](@ref). - -!!! note - - At any point you can write pages in HTML from scratch if you want to go beyond what JuDoc can offer; these pages will just be copied as they are. - So for instance you may prefer to write an `index.html` file instead of using the `index.md` to generate it. - You would still put it at the exact same place though (`src/index.html`) and let JuDoc copy the files at the appropriate place. - -**HTML parts** - -The files in `_html_parts/` are the building blocks that will go around the (processed) content contained in the `*.md` pages. -So the `head.html` will be inserted before, the `foot.html` after etc. -Adjusting these will help you make sure the site has the exact layout you want. -The layout can also depend on the page you're on if it uses `{{ispage path/to/page}} ... {{end}}` (see [Templating](@ref)). - -**CSS** - -The style sheets in `_css/` will help you tune the way your site looks. -The `judoc.css` is the stylesheet that corresponds more specifically to the styling of the `.jd-content` div and all that goes in it, it is usually the first style-sheet that should be loaded. -The simplest way to adjust the style easily would be to define your own stylesheet `_css/adjustments.css` and it be the last stylesheet loaded in `_html_parts/head.html` so that you can easily overwrite whatever properties you don't like and define your own. -You could also have specific stylesheet that would only be loaded on specific pages using `{{ispages ...}}` (see [Templating](@ref)). - -!!! note - - It wouldn't be hard for JuDoc to use page variables in the CSS stylesheet too. You could then do things like - ```judoc - @def col1 = aliceblue - ``` - and - ```css - .mydiv { color: $col1 } - ``` - I'm not 100% sure how useful that could be though so if you would like to see this happen, please open an issue! - -**Folder organisation** - -Auxiliary assets such as images, code snippets, pdfs etc. should ideally go in the `assets/` folder (or subfolders). -The files that are in `assets/` will not tracked for change and will also not get copied around. - -An alternative approach is to keep auxiliary assets in `src/pages/` (or subfolders). -The main advantage being that some users might find it better to structure their content with the page markdown as well as the page resources in one folder. -If you decide to do this, bear in mind that whatever is in `src/pages/` gets copied to the generated `pub/` folder during the initial website compilation. -While this will be imperceptible if you only have a few light assets, it could slow the initial pass down if you have many heavy assets; if that's the case though, you are probably better off with the first approach putting all resources in `assets/` and subfolders. - -## Libraries - -Assuming you used the [`newsite`](@ref) function to get started, you have a `libs/` folder with - -``` -. -├── highlight/ -└── katex/ -``` - -If you require other libraries to run your website, this is where you should put them while not forgetting to load them in your `_html_parts`; for instance in the default `foot_highlight.html` you will find: - -```html - - -``` - -which loads and applies `highlight.js`. - -### Highlight - -Assuming you used the [`newsite`](@ref) function to get started, you have the `libs/highlight/` folder with - -``` -. -├── github.min.css -└── highlight.pack.js -``` - -If you want to change either how things look or which languages are supported, you should head to [highlightjs.org](https://highlightjs.org/download/), select the languages you want in the **Custom package** section, download the bundle and copy over the relevant files to `libs/highlight/`. -By default, the files that are created with [`newsite`](@ref) allow highlighting for `bash`, `html/xml`, `python`, `julia`, `julia-repl`, `css`, `r`, `markdown`, `ini/TOML`, `ruby` and `yaml`. - -Just remember to refer to the appropriate style-sheet in your HTML building blocks for instance the default `src/_html_parts/head_highlight.html` contains: - -```html - -``` - -## Hosting the website - -In this section, the assumption is that you will host your website on GitHub. -The procedure should be very similar with GitLab. -If you're using your own hosting, you would pretty much just need to copy/clone the content of your folder. - -On GitHub/GitLab, the first step is to create a repository that would be acceptable for a personal webpage. - -* Follow the guide to [do so on GitHub](https://pages.github.com/#user-site). -* Or the guide to [do so on GitLab](https://about.gitlab.com/product/pages/). - -Once the repository is created, clone it on your computer, remove whatever is in it if it wasn't empty and copy over the content of the website folder (so if you had done `newsite("Test/")` then you'd copy over the content of the folder `Test` into the newly cloned folder `username.github.io/`). - -Now just do the usual `git add`, `commit` and `push` and your site will be live in a matter of minutes. - -### Gitlab users - -On Gitlab, there are two small differences: - -1. your website needs to eventually be in a `public/` directory of the repository, -1. you need to specify a CI/CD script that tells Gitlab how to deploy the site. - -Luckily both of these can be done in one shot, all you need to do is add a script as follows in your repository: - -```yaml -pages: - stage: deploy - script: - - mkdir .public - - cp -r * .public - - mv .public public - artifacts: - paths: - - public - only: - - master -``` - -The only non-trivial bit is the `script:` section: the only thing it does is tell the runner to copy all your files in a `public/` "virtual" directory. -Note that this will _not_ physically create a directory in your repo, rather it will, on Gitlab, make sure the files are located in such a way that they can be rendered. - -**Note**: if for some reason your repository is private and you would like to avoid for some files to be in the `public/` folder, then just add a couple of lines in the `script:` part removing (`rm`) the files you don't want to put there (e.g. sensitive data files). - -### Hosting the website as a project website - -You may want to host your website not as a user website on `username.github.io/` but as a project website on `username.github.io/project/`. -For this to work well, the only thing that is required is to have all links start with `/project/` instead of just `/` (the default). -JuDoc makes this easy to do this as a final step before publication. - -The best way to do it is: - -1. specify a `prepath` global variable in your `src/config.md` file by adding a line: `@def prepath = "project"`, -1. use [`optimize`](@ref) and/or [`publish`](@ref) (even if you don't do the minification or the prerendering). - -Alternatively, you can specify the `prepath` when calling `optimize` or `publish` so for instance: - -```julia-repl -julia> optimize(prerender=false, minify=false, prepath="project") -``` - -will do a pass over all generated pages and make sure all paths are prepended with `/project/`. - -## Optimisation step - -The [`optimize`](@ref) function should typically be run before you push your website online. -That step can: - -1. pre-render KaTeX and highlight code to HTML so that the pages don't have to load these javascript libraries, -1. minify all generated HTML and CSS. - -Those steps (which you can opt out of using the appropriate keyword `prerender=false` or `minify=false`) may lead to faster loading pages. - -In order to run this optimisation step, you will need some [dependencies](/#External-dependencies-1) but if you don't have them, JuDoc will tell you and ignore the corresponding step. -Note also that doing a full pass of pre-rendering and minifying may take a few seconds depending on how many pages you have. - -## (git) synchronisation - -The [`publish`](@ref) function helps you wrap the [`optimize`](@ref) step as well as a git `add`, `commit` and `push` all in one (provided the `optimize` step didn't fail). - -So, in short, your full workflow may look like - -```julia -using JuDoc -# cd to the appropriate directory -cd("path/user.github.io") -# start serving -serve() -# ... -# edit things, add pages, tune layout etc. -# while keeping an eye on the browser to check -# ... -# all looks good, stop the server with CTRL+C -^C -# and now the final step to optimize and push: -publish() -``` - -### Merge conflicts - -Since the `pub/` and `css/` and `index.html` folder are _generated_, it can sometimes cause git merge conflicts if, for instance, you have edited your website on computer A, optimised and published it and then subsequently pulled on computer B where -- say -- the content hasn't been minified yet. -This could cause messy merge conflicts that would be annoying to fix. -An easy way to reduce this risk is to simply remove the generated folders and files before pulling. - -The function [`cleanpull`](@ref) does precisely that and should be used if you intend to edit your website from multiple computers. -It simply: - -1. removes all generate folders/files from your current director, -1. pulls. - -So in such a case, your full workflow would be: - -```julia -using JuDoc -cd("path/user.github.io") -cleanpull() -serve() -# ... -publish() -``` - -## Using Literate.jl - -(_Thanks to [@cormullion](https://github.com/cormullion) for this section_) - -You can use Fredrik Ekre's [Literate.jl](https://github.com/fredrikekre/Literate.jl) package to create Markdown pages suitable for including in your JuDoc workflow. Literate.jl lets you write everything in a Julia source file, including your code, comments, tests, generated plots, and so on. When you execute the Julia file, all your code runs, and you can arrange for Literate.jl to write output such as Markdown-formatted text (and/or Jupyter notebooks) to suitable files. -Literate.jl's syntax relies on various different flavours of comment, some of which are shown in the simple example below. - -All non-Julia code has to be commented. -Markdown markup language is applied immediately after the first `# `. -You can see the `>` Markdown quote syntax and the `##` Markdown header level 2 syntax. -Lines preceded by `#jl` are not included in the Markdown output. -Lines ending with `#src` are evaluated when you run the Julia file, but are not copied into the Markdown output file. -Lines beginning with `#src` are Julia comments that don't make it as far as the Markdown file. -Refer to [Literate.jl's docs](https://fredrikekre.github.io/Literate.jl/stable/) for more information. - -You can see from the final five lines in the example that, when you run this file in Julia, the final step is to run the `Literate.markdown` function, taking the name of the Julia source file (`functionoftheweek.jl`) as input, and writing a new Markdown file to the directory `src/pages/` as `fotw_floorceil.md`. -Finally, if the JuDoc server is running, you'll find the generated HTML page as `/pub/fotw_floorceil.html`. - -````` -#jl This is a Julia source file! - -# @def title = "Function of the week: floorceil()" -# @def hascode = true - -# > To be, or not to be. That's what they reckon. - -# ## Function of the week: floorceil() - -# Welcome to another weekly post in which I present a cool Julia function that I've -# just discovered. This week it's the turn of `floorceil()`. It might sound like -# something that comes in a tin, but in fact it's a useful function in the Dates module -# that returns two Dates or DateTimes, one before, and one after, the specified time by -# a certain unit of time. - -# For example: - -using Dates - -Dates.now() - -# -# 2019-05-09T11:29:23.913 -# -#src # would be nice if the output from commands could be included! - -Dates.floorceil(now(), Dates.Month(1)) - -# -# (2019-05-01T00:00:00, 2019-06-01T00:00:00) -# - -# and you can see that the result contains the beginning and the end of the month -# that includes the present time of day. - -a, b = (Dates.floorceil(now(), Dates.Month(1))); -Dates.canonicalize(Dates.CompoundPeriod(b - a)) - -# -# 4 weeks, 3 days -# - -# That's all for today. Until next time! - -#src Lines with this tag appear only in this Julia source file. -using Literate #src -Literate.markdown("functionoftheweek.jl", #src - "src/pages/", #src - name="fotw_floorceil", #src - documenter=false) #src - -````` - -When this Julia file is executed, the resulting Markdown output will look like the listing below. -Notice that the two JuDoc `@def` lines have survived the journey from Julia to Markdown intact, and will now be actively available for the JuDoc generation process. - -````` -@def title = "Function of the week: floorceil()" -@def hascode = true - -> To be, or not to be. That's what they reckon. - -## Function of the week: floorceil() - -Welcome to another weekly post in which I present a cool Julia function that I've -just discovered. This week it's the turn of `floorceil()`. It might sound like -something that comes in a tin, but in fact it's a useful function in the Dates module -that returns two Dates or DateTimes, one before, and one after, the specified time by -a certain unit of time. - -For example: - -```julia -using Dates - -Dates.now() -``` - -2019-05-09T11:29:23.913 - -```julia -Dates.floorceil(now(), Dates.Month(1)) -``` - -(2019-05-01T00:00:00, 2019-06-01T00:00:00) - -and you can see that the result contains the beginning and the end of the month -that includes the present time of day. - -```julia -a, b = (Dates.floorceil(now(), Dates.Month(1))); -Dates.canonicalize(Dates.CompoundPeriod(b - a)) -``` - -4 weeks, 3 days - -That's all for today. Until next time! - -*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* -`````