diff --git a/.clippy.toml b/.clippy.toml
index 4bda813..ee470c2 100644
--- a/.clippy.toml
+++ b/.clippy.toml
@@ -2,3 +2,4 @@ allow-unwrap-in-tests = true
allow-expect-in-tests = true
single-char-binding-names-threshold = 2
upper-case-acronyms-aggressive = true
+allow-indexing-slicing-in-tests = true
diff --git a/.forgejo/workflows/check.yaml b/.forgejo/workflows/check.yaml
deleted file mode 100644
index 18b1d4c..0000000
--- a/.forgejo/workflows/check.yaml
+++ /dev/null
@@ -1,68 +0,0 @@
-on:
- push:
- paths:
- - src/**
- - tests/**
- - .forgejo/**
- - Cargo.toml
- - Cargo.lock
-env:
- JUST_VERSION: 1.45.0
- JUST_SHA256SUM: dc3f958aaf8c6506dd90426e9b03f86dd15e74a6467ee0e54929f750af3d9e49
- CARGO_LLVM_COV_VERSION: 0.6.21
- CARGO_LLVM_COV_SHA256SUM: 57f491aedf7cdb261538ceb49cbb1ee9d27df7ca205a5e1a009caaf5cb911afb
-jobs:
- verify:
- runs-on: docker
- timeout-minutes: 20
- container:
- image: rust:slim
- steps:
- - name: Install action dependencies
- run: |
- apt-get install --no-install-recommends --update -y nodejs curl
-
- - name: Checkout code
- uses: actions/checkout@v6
-
- - name: Setup Rust toolchain
- run: |
- rustup component add rustfmt clippy llvm-tools-preview
-
- - name: Setup additional tooling
- run: |
- fetch() {
- repo="$1"; tag="$2"; filename="$3"; digest="$4"
-
- curl -sSLO -w '%{stderr}HTTP %{response_code} %{url}\n' \
- "https://github.com/$repo/releases/download/$tag/$filename"
-
- printf '%s %s\n' "$digest" "$filename" > digest
- sha256sum --check digest && tar xf "$filename" -C tools
- }
-
- mkdir tools
-
- fetch casey/just ${{ env.JUST_VERSION }} \
- just-${{ env.JUST_VERSION }}-x86_64-unknown-linux-musl.tar.gz \
- ${{ env.JUST_SHA256SUM }}
- fetch taiki-e/cargo-llvm-cov v${{ env.CARGO_LLVM_COV_VERSION }} \
- cargo-llvm-cov-x86_64-unknown-linux-gnu.tar.gz \
- ${{ env.CARGO_LLVM_COV_SHA256SUM }}
-
- mv -v tools/just tools/cargo-llvm-cov /usr/local/bin
-
- - name: Build
- run: just build
-
- - name: Format
- run: just format-assess
- - name: Lint
- run: just lint-assess
- - name: Cargo check
- run: just check
- - name: Test
- run: just test
- - name: Assess test coverage
- run: just cover-assess
-
diff --git a/.forgejo/workflows/publish.yaml b/.forgejo/workflows/publish.yaml
new file mode 100644
index 0000000..6a96939
--- /dev/null
+++ b/.forgejo/workflows/publish.yaml
@@ -0,0 +1,75 @@
+on:
+ push:
+ tags:
+ - 'v*'
+ workflow_dispatch:
+ inputs:
+ upload:
+ description: 'Upload built assets to the git.jutty.dev package registry'
+ type: boolean
+ required: false
+ default: true
+
+jobs:
+ publish:
+ runs-on: docker
+ timeout-minutes: 20
+ container:
+ image: rust:slim
+ steps:
+ - name: Install action dependencies
+ run: apt-get install --no-install-recommends --update -y nodejs curl git
+
+ - name: Checkout code
+ uses: actions/checkout@v6
+ with:
+ fetch-tags: true
+
+ - name: Setup Rust toolchain
+ run: |
+ rustup component add llvm-tools-preview
+ rustup component add --toolchain nightly rustfmt clippy
+ rustup target add x86_64-unknown-linux-gnu
+ rustup target add x86_64-unknown-linux-musl
+
+ - name: Setup additional tooling
+ run: .forgejo/workflows/setup-tools.sh
+
+ - name: Setup CI user
+ run: |
+ useradd -m ci && chown -R ci:ci .
+ git config --global --add safe.directory "$PWD"
+
+ - name: Run all assessments
+ run: just ci verify
+
+ - name: Build x64 glibc release binary
+ run: just release-build x86_64-unknown-linux-gnu
+
+ - name: Build x64 musl release binary
+ run: just release-build x86_64-unknown-linux-musl
+
+ - name: Calculate SHA-256 hashes
+ run: just shasum
+
+ - name: Publish x64 glibc binary to git.jutty.dev registry
+ if: ${{ inputs.upload }}
+ run: |
+ version=$(./target/x86_64-unknown-linux-gnu/release/en --version)
+ api_root=https://git.jutty.dev/api
+ url=$api_root/packages/jutty/generic/en/$version/en-x64-linux-gnu
+
+ curl -fsSL \
+ --user jutty:${{ secrets.GJD_REGISTRY_TOKEN }} \
+ --upload-file target/x86_64-unknown-linux-gnu/release/en $url
+
+ - name: Publish x64 musl binary to git.jutty.dev registry
+ if: ${{ inputs.upload }}
+ run: |
+ version=$(./target/x86_64-unknown-linux-musl/release/en --version)
+ api_root=https://git.jutty.dev/api
+ url=$api_root/packages/jutty/generic/en/$version/en-x64-linux-musl
+
+ curl -fsSL \
+ --user jutty:${{ secrets.GJD_REGISTRY_TOKEN }} \
+ --upload-file target/x86_64-unknown-linux-musl/release/en $url
diff --git a/.forgejo/workflows/setup-tools.sh b/.forgejo/workflows/setup-tools.sh
new file mode 100755
index 0000000..3c71b7c
--- /dev/null
+++ b/.forgejo/workflows/setup-tools.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env sh
+
+set -eu
+
+JUST_VERSION="1.47.1"
+JUST_SHA256SUM="3cb931ae25860f261ee373f32ede3b772ac91f14f588e4071576d3ffcf1a16fd"
+CARGO_LLVM_COV_VERSION="0.6.21"
+CARGO_LLVM_COV_SHA256SUM="57f491aedf7cdb261538ceb49cbb1ee9d27df7ca205a5e1a009caaf5cb911afb"
+CARGO_AUDIT_VERSION="0.22.1"
+CARGO_AUDIT_TAG="cargo-audit%2Fv$CARGO_AUDIT_VERSION"
+CARGO_AUDIT_SHA256SUM="1890badd5f15831a9af4b074399fcd21e6f7c0fe42c84e9254cdffc9f813765c"
+TAPLO_VERSION="0.10.0"
+TAPLO_SHA256SUM="8fe196b894ccf9072f98d4e1013a180306e17d244830b03986ee5e8eabeb6156"
+TYPOS_VERSION="1.47.2"
+TYPOS_SHA256SUM="7aef58932fc123b4cf4b40d86468e89a3297d80169051d7cfd13a235e05fc426"
+CARGO_DENY_VERSION="0.19.8"
+CARGO_DENY_SHA256SUM="70e769ae3872e34d45132b17040859175e11401dc12dddb0303e0b8c7d088f3f"
+
+TRIPLE="x86_64-unknown-linux-gnu"
+TRIPLE_MUSL="x86_64-unknown-linux-musl"
+
+fetch() {
+ repo="$1"
+ tag="$2"
+ filename="$3"
+ digest="$4"
+ binary="$5"
+ renamed_binary="${6:-$binary}"
+
+ [ -d /tmp/tools ] || mkdir -p /tmp/tools
+
+ curl -fsSLO --output-dir /tmp \
+ -w '%{stderr}HTTP %{response_code} %{url}\n' \
+ "https://github.com/$repo/releases/download/$tag/$filename"
+
+ printf '%s %s\n' "$digest" "/tmp/$filename" > /tmp/digest
+ sha256sum --check /tmp/digest
+
+ if printf '%s' "$filename" | grep -qE '\.tar\.|\.tgz$'; then
+ tar xf "/tmp/$filename" -C /tmp/tools
+ elif printf '%s' "$filename" | grep -q '\.gz$'; then
+ gunzip -c "/tmp/$filename" > "/tmp/tools/$binary"
+ else
+ echo "Fatal: can't determine how to unpack $filename"
+ exit 1
+ fi
+
+ find /tmp/tools -type f -name "$binary" \
+ -exec mv -v '{}' "/usr/local/bin/$renamed_binary" ';'
+ chmod +x "/usr/local/bin/$renamed_binary"
+}
+
+fetch casey/just "$JUST_VERSION" \
+ "just-$JUST_VERSION-$TRIPLE_MUSL.tar.gz" \
+ "$JUST_SHA256SUM" just
+
+fetch taiki-e/cargo-llvm-cov "v$CARGO_LLVM_COV_VERSION" \
+ "cargo-llvm-cov-$TRIPLE.tar.gz" \
+ "$CARGO_LLVM_COV_SHA256SUM" cargo-llvm-cov
+
+fetch rustsec/rustsec "$CARGO_AUDIT_TAG" \
+ "cargo-audit-$TRIPLE-v$CARGO_AUDIT_VERSION.tgz" \
+ "$CARGO_AUDIT_SHA256SUM" cargo-audit
+
+fetch tamasfe/taplo "$TAPLO_VERSION" \
+ "taplo-linux-x86_64.gz" \
+ "$TAPLO_SHA256SUM" taplo-linux-x86_64 taplo
+
+fetch crate-ci/typos "v$TYPOS_VERSION" \
+ "typos-v$TYPOS_VERSION-$TRIPLE_MUSL.tar.gz" \
+ "$TYPOS_SHA256SUM" typos
+
+fetch EmbarkStudios/cargo-deny "$CARGO_DENY_VERSION" \
+ cargo-deny-$CARGO_DENY_VERSION-$TRIPLE_MUSL.tar.gz \
+ "$CARGO_DENY_SHA256SUM" cargo-deny
diff --git a/.forgejo/workflows/verify.yaml b/.forgejo/workflows/verify.yaml
new file mode 100644
index 0000000..c37f8e7
--- /dev/null
+++ b/.forgejo/workflows/verify.yaml
@@ -0,0 +1,59 @@
+on:
+ push:
+ branches:
+ - '*'
+ paths:
+ - src/**
+ - tests/**
+ - static/graph.toml
+ - .forgejo/**
+ - Cargo.toml
+ - Cargo.lock
+
+jobs:
+ verify:
+ runs-on: docker
+ timeout-minutes: 20
+ container:
+ image: rust:slim
+ steps:
+ - name: Install action dependencies
+ run: apt-get install --no-install-recommends --update -y nodejs curl git
+
+ - name: Checkout code
+ uses: actions/checkout@v6
+ with:
+ fetch-tags: true
+
+ - name: Setup Rust toolchain
+ run: |
+ rustup component add llvm-tools-preview
+ rustup component add --toolchain nightly rustfmt clippy
+ rustup target add x86_64-unknown-linux-gnu
+ rustup target add x86_64-unknown-linux-musl
+
+ - name: Setup additional tooling
+ run: .forgejo/workflows/setup-tools.sh
+
+ - name: Setup CI user
+ run: |
+ useradd -m ci && chown -R ci:ci .
+ git config --global --add safe.directory "$PWD"
+
+ - name: Text matching checks
+ run: just ci todos-assess version-assess spell
+ - name: Schema lint
+ run: just ci schema-lint
+ - name: Deny
+ run: just ci deny
+ - name: Format
+ run: just ci format-assess
+ - name: Lint
+ run: just ci lint-assess
+ - name: Cargo check
+ run: just ci check
+ - name: Test
+ run: just ci test
+ - name: Assess test coverage
+ run: just ci cover-assess
+
diff --git a/.gitignore b/.gitignore
index ea8c4bf..d787b70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/target
+/result
diff --git a/.justfile b/.justfile
index cd3f175..9c7d7d3 100644
--- a/.justfile
+++ b/.justfile
@@ -5,8 +5,6 @@
update:
cargo update --verbose
-alias u := update
-
# Build and serve
[group: 'develop']
run host='::1' port='3003' *args:
@@ -18,58 +16,108 @@ alias r := run
# Build and serve on changes
[group: 'develop']
run-watch:
- {{ watch_cmd }} {{ just_cmd }} run
+ @{{ watch_cmd }} {{ just_cmd }} run
alias w := run-watch
-[private]
-quick-assess:
- {{ just_cmd }} lint check quick-test-cover
+# Build on changes
+[group: 'develop']
+build-watch target=default_target:
+ @{{ watch_cmd }} {{ just_cmd }} build {{ target }}
+
+alias bw := build-watch
+
+# Build dev container
+[group: 'develop', working-directory: 'containers']
+build-containerized distro="alpine": build
+ ./build.sh {{ distro }}-dev
+
+alias bc := build-containerized
+
+# Run dev container
+[group: 'develop', working-directory: 'containers']
+run-containerized distro="alpine":
+ ./run.sh {{ distro }}-dev
+
+alias rc := run-containerized
+
+# Build dev container and serve from it on changes
+[group: 'develop']
+run-watch-containerized:
+ @{{ watch_cmd }} "{{ just_cmd }} build-containerized \
+ && {{ just_cmd }} run-containerized"
+
+alias wc := run-watch-containerized
[private]
-quick-assess-run:
- -{{ just_cmd }} quick-assess
+assess-quick:
+ {{ just_cmd }} lint check test-cover-quick spell schema-lint
+
+[private]
+assess-run-quick:
+ -{{ just_cmd }} assess-quick
{{ just_cmd }} run
# Run quick assessments on changes
[group: 'develop']
-quick-assess-watch:
- {{ watch_cmd }} {{ just_cmd }} quick-assess
+assess-watch-quick:
+ {{ watch_cmd }} {{ just_cmd }} assess-quick
-alias qa := quick-assess-watch
+alias aq := assess-watch-quick
# Run quick assessments, build and serve on changes
[group: 'develop']
-quick-assess-run-watch:
- {{ watch_cmd }} {{ just_cmd }} quick-assess-run
+assess-run-watch-quick:
+ {{ watch_cmd }} {{ just_cmd }} assess-run-quick
-alias qr := quick-assess-run-watch
+alias rq := assess-run-watch-quick
[private]
-quick-test-cover:
- {{ cover_cmd }} --no-report -- --skip 'serial_tests::'
+test-cover-quick:
{{ cover_cmd }} --no-report -- --test 'serial_tests::' --test-threads 1
+ {{ cover_cmd }} --no-report -- --skip 'serial_tests::'
{{ cover_cmd }} report --html
@{{ cover_cmd }} report | tail -1 | awk '{ print " [ Regions:", $4, "• Functions:", $7, "• Lines:", $10, "]" }'
# Quickly update coverage reports (inaccurate)
[group: 'assess']
-quick-test-cover-watch:
- {{ watch_cmd }} {{ just_cmd }} quick-test-cover
+test-cover-watch-quick:
+ @{{ watch_cmd }} {{ just_cmd_no_ts }} test-cover-quick 2>&1 \
+ | grep -v "process didn't exit successfully:" || true
-alias qo := quick-test-cover-watch
+alias oq := test-cover-watch-quick
# Format all files
[group: 'develop']
format:
- cargo fmt
+ cargo +nightly fmt
alias f := format
+# Test (short output)
+[group: 'develop']
+test-short pattern="":
+ cargo test {{ pattern }} -q --message-format short \
+ -- 'serial_tests::' --test-threads=1 \
+ --format=terse -- quiet
+ cargo test {{ pattern }} -q --message-format short --bin en
+ cargo test {{ pattern }} -q --message-format short --doc
+ cargo test {{ pattern }} --message-format short --lib \
+ -- --format terse --skip 'serial_tests::'
+
+alias ts := test-short
+
+# Test on changes (shorter output)
+[group: 'develop']
+test-short-watch:
+ {{ watch_cmd }} {{ just_cmd }} test-short
+
+alias tsw := test-short-watch
+
# Lint
[group: 'develop']
lint:
- cargo clippy
+ cargo +nightly clippy --timings --all-targets
alias l := lint
@@ -80,6 +128,20 @@ lint-watch:
alias lw := lint-watch
+# Lint (short output)
+[group: 'develop']
+lint-short:
+ cargo +nightly clippy --all-targets -q --message-format short
+
+alias ls := lint-short
+
+# Lint on changes (shorter output)
+[group: 'develop']
+lint-short-watch:
+ {{ watch_cmd }} {{ just_cmd }} lint-short
+
+alias lsw := lint-short-watch
+
# Run cargo check on changes
[group: 'develop']
check-watch:
@@ -94,16 +156,23 @@ rustc-fix:
alias rf := rustc-fix
+# Apply clippy lint fixes
+[group: 'develop']
+clippy-fix:
+ cargo +nightly clippy --fix --allow-dirty
+
+alias cf := clippy-fix
+
# Apply all automatic fixes
[group: 'develop']
-fix: rustc-fix format
+fix: rustc-fix clippy-fix format
alias x := fix
# Run tests on changes
[group: 'develop']
-test-watch:
- {{ watch_cmd }} {{ just_cmd }} test
+test-watch pattern="":
+ {{ watch_cmd }} {{ just_cmd }} test {{ pattern}}
alias tw := test-watch
@@ -129,24 +198,67 @@ cover-open:
alias oo := cover-open
-# Verify and push
+# Perform mutation testing
[group: 'develop']
-push: verify
+mutate:
+ -just mutate-single -- --test-threads=1 serial_tests::
+ -just mutate-single -- --skip serial_tests::
+
+alias m := mutate
+
+[private]
+mutate-single *cargo_test_args:
+ cargo mutants --iterate \
+ -E ' bool' \
+ --output target/mutants \
+ -- {{ cargo_test_args }}
+
+# Tag HEAD with version from Cargo.toml
+[script, group: 'assess']
+tag commit="HEAD": update
+ if [ "{{ last_local_tag }}" = "{{ manifest_version }}" ]; then
+ echo "Last tag {{ last_local_tag }} and manifest ({{ manifest_version }}) already match"
+ exit
+ elif [ "{{ manifest_version }}" != "{{ lockfile_version }}" ]; then
+ echo "Manifest and lockfile versions don't match: update failed?"
+ exit 1
+ fi
+
+ git tag "v{{ manifest_version }}" {{ commit }}
+ {{ just_cmd }} version-assess
+
+# Verify and push
+[group: 'develop', env("JUST", "1")]
+push: verify && (version-assess "true")
git push
+ git push --tags
alias p := push
+# Push without verifying
+[group: 'develop', env("JUST", "1")]
+push-unsafe:
+ git push --no-verify
+ git push --tags --no-verify
+
+alias pu := push-unsafe
+
+# DOCUMENT
+
# Generate crate documentation
[group: 'document']
doc:
- cargo doc --document-private-items --no-deps
+ cargo doc --timings --document-private-items --no-deps
alias d := doc
# Generate crate and dependencies documentation
[group: 'document']
doc-all:
- cargo doc --document-private-items
+ cargo doc --timings --document-private-items
alias da := doc-all
@@ -162,34 +274,47 @@ alias do := doc-open
# Assess formatting
[group: 'assess']
format-assess:
- cargo fmt -- --check
+ cargo +nightly fmt -- --check
-alias fc := format-assess
+alias fa := format-assess
# Assess production lints
[group: 'assess']
lint-assess:
- cargo clippy -- \
- -D clippy::dbg_macro -D clippy::print_stdout -D clippy::print_stderr \
+ cargo +nightly clippy --timings -- \
+ -D clippy::print_stdout -D clippy::print_stderr \
+ -D clippy::dbg_macro -D clippy::use_debug
+ cargo +nightly clippy --timings --all-targets -- \
-D clippy::todo -D clippy::unimplemented -D clippy::unreachable
alias la := lint-assess
+alias lp := lint-assess
# Run cargo check
[group: 'assess']
check:
- {{ debug_vars }} cargo check --workspace
+ {{ debug_vars }} cargo check --workspace --all-targets \
+ --future-incompat-report
alias c := check
# Run tests
[group: 'assess']
-test:
- cargo test -- --skip 'serial_tests::'
- cargo test -- --test 'serial_tests::' --test-threads 1
+test pattern="":
+ cargo test {{ pattern}} --timings -- --test-threads=1 'serial_tests::'
+ cargo test {{ pattern}} --timings --bin en
+ cargo test {{ pattern}} --timings --doc
+ cargo test {{ pattern}} --timings --lib -- --skip 'serial_tests::'
alias t := test
+# Run tests with unfiltered output
+[group: 'assess']
+test-output pattern="":
+ DEBUG=${DEBUG:-debug} cargo test {{ pattern }} -- --no-capture 2>&1
+
+alias to := test-output
+
# Clean test coverage data
[group: 'assess']
test-cover-clean:
@@ -200,8 +325,8 @@ alias oc := test-cover-clean
# Run tests with coverage
[group: 'assess']
test-cover: test-cover-clean
- {{ cover_cmd }} --no-report -- --skip 'serial_tests::'
{{ cover_cmd }} --no-report -- --test 'serial_tests::' --test-threads 1
+ {{ cover_cmd }} --no-report -- --skip 'serial_tests::'
alias o := test-cover
@@ -218,12 +343,60 @@ verify:
export RUSTFLAGS=${RUSTFLAGS:-"-Dwarnings"}
if [ -n "$(git status --porcelain)" ]; then
echo "Git working tree is dirty: Commit or stash your changes first"
+ git status
exit 1
fi
- {{ just_cmd }} format-assess lint-assess check test cover-assess
+ {{ just_cmd }} \
+ todos-assess version-assess spell schema-lint deny \
+ format-assess lint-assess check \
+ test "" cover-assess
alias v := verify
+# Check tag-manifest consistency
+[script, group: 'assess']
+[arg("remote", long="remote", short="r", value="true")]
+version-assess remote="false": update
+ last_remote_tag=$(
+ git ls-remote --tags --sort=-creatordate origin |
+ head -n 1 | tr -d v | cut -d / -f 3
+ )
+ printf 'Local: %s\nRemote: %s\nManifest: %s\nLockfile: %s\n' \
+ "{{ last_local_tag }}" \
+ "$last_remote_tag" \
+ "{{ manifest_version }}" \
+ "{{ lockfile_version }}"
+ test "{{ last_local_tag }}" = "{{ lockfile_version }}"
+ test "{{ last_local_tag }}" = "{{ manifest_version }}"
+ if {{ if remote == "true" { "true" } else { "false" } }}; then
+ test "{{ last_local_tag }}" = "$last_remote_tag"
+ fi
+
+alias va := version-assess
+
+# Find TODOs
+[group: 'assess']
+todos-assess:
+ ! grep -rn TODO src
+
+alias ta := todos-assess
+
+# Check for security advisories, unexpected licenses, allowed registries
+[group: 'assess']
+deny:
+ cargo-deny check
+
+# Check for spelling mistakes
+[group: 'assess']
+spell:
+ typos
+
+# Lint the default and builtin graphs against the schema
+[group: 'assess']
+schema-lint:
+ test -z "$(grep -LF '#:schema ./graph-schema.json' static/*.toml)"
+ taplo lint static/*.toml
+
# BUILD
# Cleanup build artifacts
@@ -233,25 +406,56 @@ clean:
alias cl := clean
-# Build project with Cargo
+# Build
[group: 'build']
-build: update
- cargo build
+build target=default_target:
+ cargo build --timings --target {{ target }} --locked
+
alias b := build
+# glibc build
+[group: 'build']
+build-gnu:
+ cargo build --timings --target {{ glibc_target }} --locked
+
+alias bg := build-gnu
+
+# musl build
+[group: 'build']
+build-musl:
+ cargo build --timings --target {{ musl_target }} --locked
+
+alias bm := build-musl
+
# Release build
[group: 'build']
-release-build: update verify
- cargo build --release
+release-build target=default_target:
+ cargo build --timings --target {{ target }} --locked --release
+ du -h target/{{ target }}/release/en
alias rb := release-build
-# Clean, run assessments, release build
+# glibc release build
[group: 'build']
-full-build: clean update verify release-build
+release-build-gnu:
+ {{ just_cmd }} release-build {{ glibc_target }}
-alias fb := full-build
+alias rbg := release-build-gnu
+
+# musl release build
+[group: 'build']
+release-build-musl:
+ {{ just_cmd }} release-build {{ musl_target }}
+
+alias rbm := release-build-musl
+
+# Calculate SHA 256 hashes for release binaries
+[group: 'build']
+shasum:
+ find target -type d -name 'release' \
+ -exec find '{}' -maxdepth 1 -type f -name en -executable ';' \
+ | xargs sha256sum
## META
@@ -259,11 +463,37 @@ alias fb := full-build
default:
@just --list --unsorted --justfile {{justfile()}}
+choose:
+ @just --choose
+
+alias ch := choose
+
+[script, private, env("CARGO_HOME", "$HOME/.cargo")]
+ci recipe:
+ su ci -c "just {{ recipe }}"
+
+## VARIABLES
+
export CARGO_TERM_COLOR := 'always'
+musl_target := "x86_64-unknown-linux-musl"
+glibc_target := "x86_64-unknown-linux-gnu"
+default_target := musl_target
+
debug_vars := 'DEBUG=${DEBUG:-} DEBUG_FILTER=${DEBUG_FILTER:-} RUST_BACKTRACE=${RUST_BACKTRACE:-} RUSTFLAGS=${RUSTFLAGS:-}'
-watch_cmd := "watchexec -qc -r -e rs,toml,html --color always -- "
-cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|dev\.rs"'
just_cmd := 'just --timestamp --explain --command-color green'
+just_cmd_no_ts := 'just --explain --command-color green'
+watch_cmd := "watchexec -qc -r -e rs,toml,html,css --color always -- "
+cover_cmd := 'cargo llvm-cov --color always --ignore-filename-regex "main\.rs|log\.rs"'
+
+last_local_tag := `git tag --sort=-creatordate | head -n 1 | tr -d v`
+manifest_version := `grep "^version" Cargo.toml | cut -d \" -f 2`
+lockfile_version := ```
+ grep -A 1 'name = "en"' Cargo.lock \
+ | grep version | cut -d '"' -f 2
+ ```
+
+## OPTIONS
set unstable
+set lazy
diff --git a/.rustfmt.toml b/.rustfmt.toml
index 10fe2ff..a09015c 100644
--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -1,25 +1,33 @@
-match_block_trailing_comma = true
+unstable_features = true
max_width = 80
-reorder_imports = false
-reorder_modules = false
+inline_attribute_width = 40
+
+skip_macro_invocations = ["concat"]
+
+imports_granularity = "Crate"
+group_imports = "StdExternalCrate"
+
+fn_single_line = true
+match_block_trailing_comma = true
use_field_init_shorthand = true
use_try_shorthand = true
+hex_literal_case = "Lower"
+where_single_line = true
+condense_wildcard_suffixes = true
+combine_control_expr = false
+empty_item_single_line = true
+reorder_impl_items = true
+trailing_semicolon = false
-# blank_lines_lower_bound = 1
-# not stabilized yet
-# where_single_line = true
-# overflow_delimited_expr = true
-# normalize_doc_attributes = true
-# normalize_comments = true
-# inline_attribute_width = 40
-# imports_granularity = "Crate"
-# hex_literal_case = "Lower"
-# group_imports = "StdExternalCrate"
-# format_strings = true
-# force_multiline_blocks = true
-# error_on_unformatted = true
-# error_on_line_overflow = true
-# condense_wildcard_suffixes = true
-# doc_comment_code_block_width = 70
-# format_code_in_doc_comments = true
-# wrap_comments = true
+wrap_comments = true
+normalize_comments = true
+normalize_doc_attributes = true
+format_code_in_doc_comments = true
+doc_comment_code_block_width = 70
+
+error_on_unformatted = true
+error_on_line_overflow = true
+
+ignore = [
+ "tests/mocks",
+]
diff --git a/Cargo.lock b/Cargo.lock
index 8423a21..06b5d60 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2,12 +2,6 @@
# It is not intended for manual editing.
version = 4
-[[package]]
-name = "adler2"
-version = "2.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
-
[[package]]
name = "aho-corasick"
version = "1.1.4"
@@ -34,15 +28,15 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "autocfg"
-version = "1.5.0"
+version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "axum"
-version = "0.8.8"
+version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
+checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
dependencies = [
"axum-core",
"bytes",
@@ -90,17 +84,11 @@ dependencies = [
"tracing",
]
-[[package]]
-name = "base64"
-version = "0.22.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
-
[[package]]
name = "bitflags"
-version = "2.10.0"
+version = "2.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
+checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
[[package]]
name = "block-buffer"
@@ -123,21 +111,21 @@ dependencies = [
[[package]]
name = "bumpalo"
-version = "3.19.1"
+version = "3.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
+checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
[[package]]
name = "bytes"
-version = "1.11.0"
+version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
+checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
[[package]]
name = "cc"
-version = "1.2.51"
+version = "1.2.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203"
+checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -151,9 +139,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "chrono"
-version = "0.4.42"
+version = "0.4.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
+checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
dependencies = [
"iana-time-zone",
"num-traits",
@@ -197,15 +185,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "crc32fast"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
-dependencies = [
- "cfg-if",
-]
-
[[package]]
name = "crossbeam-deque"
version = "0.8.6"
@@ -259,7 +238,7 @@ dependencies = [
[[package]]
name = "en"
-version = "0.1.0"
+version = "0.4.0-alpha"
dependencies = [
"axum",
"serde",
@@ -268,7 +247,6 @@ dependencies = [
"tokio",
"toml",
"tower",
- "ureq",
]
[[package]]
@@ -279,19 +257,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "find-msvc-tools"
-version = "0.1.6"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff"
-
-[[package]]
-name = "flate2"
-version = "1.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
-dependencies = [
- "crc32fast",
- "miniz_oxide",
-]
+checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "form_urlencoded"
@@ -304,35 +272,35 @@ dependencies = [
[[package]]
name = "futures-channel"
-version = "0.3.31"
+version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
+checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
-version = "0.3.31"
+version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
+checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
name = "futures-task"
-version = "0.3.31"
+version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
+checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
[[package]]
name = "futures-util"
-version = "0.3.31"
+version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
+checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
- "pin-utils",
+ "slab",
]
[[package]]
@@ -347,9 +315,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.16"
+version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"libc",
@@ -382,15 +350,15 @@ dependencies = [
[[package]]
name = "hashbrown"
-version = "0.16.1"
+version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "http"
-version = "1.4.0"
+version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a"
+checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0"
dependencies = [
"bytes",
"itoa",
@@ -442,9 +410,9 @@ dependencies = [
[[package]]
name = "hyper"
-version = "1.8.1"
+version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11"
+checksum = "55281c53a1894c864990125767da440a4e630446785086f52523b20033b74498"
dependencies = [
"atomic-waker",
"bytes",
@@ -456,19 +424,17 @@ dependencies = [
"httpdate",
"itoa",
"pin-project-lite",
- "pin-utils",
"smallvec",
"tokio",
]
[[package]]
name = "hyper-util"
-version = "0.1.19"
+version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f"
+checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
dependencies = [
"bytes",
- "futures-core",
"http",
"http-body",
"hyper",
@@ -479,9 +445,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
-version = "0.1.64"
+version = "0.1.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb"
+checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@@ -503,9 +469,9 @@ dependencies = [
[[package]]
name = "ignore"
-version = "0.4.25"
+version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d3d782a365a015e0f5c04902246139249abf769125006fbe7649e2ee88169b4a"
+checksum = "b915661dd01db3f05050265b2477bcc6527b3792388e2749b41623cc592be67d"
dependencies = [
"crossbeam-deque",
"globset",
@@ -519,9 +485,9 @@ dependencies = [
[[package]]
name = "indexmap"
-version = "2.12.1"
+version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2"
+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"equivalent",
"hashbrown",
@@ -529,16 +495,18 @@ dependencies = [
[[package]]
name = "itoa"
-version = "1.0.17"
+version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "js-sys"
-version = "0.3.83"
+version = "0.3.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
+checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11"
dependencies = [
+ "cfg-if",
+ "futures-util",
"once_cell",
"wasm-bindgen",
]
@@ -551,21 +519,21 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
-version = "0.2.178"
+version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
+checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "libm"
-version = "0.2.15"
+version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
+checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "log"
-version = "0.4.29"
+version = "0.4.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
+checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a"
[[package]]
name = "matchit"
@@ -575,9 +543,9 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]]
name = "memchr"
-version = "2.7.6"
+version = "2.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
+checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
[[package]]
name = "mime"
@@ -585,25 +553,15 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
-[[package]]
-name = "miniz_oxide"
-version = "0.8.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
-dependencies = [
- "adler2",
- "simd-adler32",
-]
-
[[package]]
name = "mio"
-version = "1.1.1"
+version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc"
+checksum = "02bd0af71c67b473010cbbc60715ee815645a4dc942899111f494b4b737d6fda"
dependencies = [
"libc",
"wasi",
- "windows-sys 0.61.2",
+ "windows-sys",
]
[[package]]
@@ -617,9 +575,9 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.21.3"
+version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "parse-zoneinfo"
@@ -638,9 +596,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "pest"
-version = "2.8.4"
+version = "2.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cbcfd20a6d4eeba40179f05735784ad32bdaef05ce8e8af05f180d45bb3e7e22"
+checksum = "e0848c601009d37dfa3430c4666e147e49cdcf1b92ecd3e63657d8a5f19da662"
dependencies = [
"memchr",
"ucd-trie",
@@ -648,9 +606,9 @@ dependencies = [
[[package]]
name = "pest_derive"
-version = "2.8.4"
+version = "2.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51f72981ade67b1ca6adc26ec221be9f463f2b5839c7508998daa17c23d94d7f"
+checksum = "11f486f1ea21e6c10ed15d5a7c77165d0ee443402f0780849d1768e7d9d6fe77"
dependencies = [
"pest",
"pest_generator",
@@ -658,9 +616,9 @@ dependencies = [
[[package]]
name = "pest_generator"
-version = "2.8.4"
+version = "2.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dee9efd8cdb50d719a80088b76f81aec7c41ed6d522ee750178f83883d271625"
+checksum = "8040c4647b13b210a963c1ed407c1ff4fdfa01c31d6d2a098218702e6664f94f"
dependencies = [
"pest",
"pest_meta",
@@ -671,9 +629,9 @@ dependencies = [
[[package]]
name = "pest_meta"
-version = "2.8.4"
+version = "2.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf1d70880e76bdc13ba52eafa6239ce793d85c8e43896507e43dd8984ff05b82"
+checksum = "89815c69d36021a140146f26659a81d6c2afa33d216d736dd4be5381a7362220"
dependencies = [
"pest",
"sha2",
@@ -719,15 +677,9 @@ dependencies = [
[[package]]
name = "pin-project-lite"
-version = "0.2.16"
+version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
-
-[[package]]
-name = "pin-utils"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "ppv-lite86"
@@ -740,27 +692,27 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.104"
+version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.42"
+version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
-version = "0.8.5"
+version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
+checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a"
dependencies = [
"libc",
"rand_chacha",
@@ -788,9 +740,9 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.12.2"
+version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
+checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
dependencies = [
"aho-corasick",
"memchr",
@@ -800,9 +752,9 @@ dependencies = [
[[package]]
name = "regex-automata"
-version = "0.4.13"
+version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
+checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
dependencies = [
"aho-corasick",
"memchr",
@@ -811,58 +763,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
-version = "0.8.8"
+version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
-
-[[package]]
-name = "ring"
-version = "0.17.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
-dependencies = [
- "cc",
- "cfg-if",
- "getrandom",
- "libc",
- "untrusted",
- "windows-sys 0.52.0",
-]
-
-[[package]]
-name = "rustls"
-version = "0.23.35"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f"
-dependencies = [
- "log",
- "once_cell",
- "ring",
- "rustls-pki-types",
- "rustls-webpki",
- "subtle",
- "zeroize",
-]
-
-[[package]]
-name = "rustls-pki-types"
-version = "1.13.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282"
-dependencies = [
- "zeroize",
-]
-
-[[package]]
-name = "rustls-webpki"
-version = "0.103.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52"
-dependencies = [
- "ring",
- "rustls-pki-types",
- "untrusted",
-]
+checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]]
name = "rustversion"
@@ -872,9 +775,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "ryu"
-version = "1.0.22"
+version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"
+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
[[package]]
name = "same-file"
@@ -917,9 +820,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.148"
+version = "1.0.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3084b546a1dd6289475996f182a22aba973866ea8e8b02c51d9f46b1336a22da"
+checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
dependencies = [
"itoa",
"memchr",
@@ -941,9 +844,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
-version = "1.0.4"
+version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
+checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
dependencies = [
"serde_core",
]
@@ -973,21 +876,21 @@ dependencies = [
[[package]]
name = "shlex"
-version = "1.3.0"
+version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
-
-[[package]]
-name = "simd-adler32"
-version = "0.3.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
+checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "siphasher"
-version = "1.0.1"
+version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
+checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
+
+[[package]]
+name = "slab"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "slug"
@@ -1007,25 +910,19 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "socket2"
-version = "0.6.1"
+version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881"
+checksum = "52d1cfed4120b4d927bf7c0f86d2087a4a7d6027c906d9f9d525a80573b9be51"
dependencies = [
"libc",
- "windows-sys 0.60.2",
+ "windows-sys",
]
-[[package]]
-name = "subtle"
-version = "2.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
-
[[package]]
name = "syn"
-version = "2.0.111"
+version = "2.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
dependencies = [
"proc-macro2",
"quote",
@@ -1062,23 +959,23 @@ dependencies = [
[[package]]
name = "tokio"
-version = "1.48.0"
+version = "1.52.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
+checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe"
dependencies = [
"libc",
"mio",
"pin-project-lite",
"socket2",
"tokio-macros",
- "windows-sys 0.61.2",
+ "windows-sys",
]
[[package]]
name = "tokio-macros"
-version = "2.6.0"
+version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
+checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
dependencies = [
"proc-macro2",
"quote",
@@ -1087,9 +984,9 @@ dependencies = [
[[package]]
name = "toml"
-version = "0.9.10+spec-1.1.0"
+version = "0.9.12+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0825052159284a1a8b4d6c0c86cbc801f2da5afd2b225fa548c72f2e74002f48"
+checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863"
dependencies = [
"indexmap",
"serde_core",
@@ -1097,7 +994,7 @@ dependencies = [
"toml_datetime",
"toml_parser",
"toml_writer",
- "winnow",
+ "winnow 0.7.15",
]
[[package]]
@@ -1111,24 +1008,24 @@ dependencies = [
[[package]]
name = "toml_parser"
-version = "1.0.6+spec-1.1.0"
+version = "1.1.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44"
+checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"
dependencies = [
- "winnow",
+ "winnow 1.0.3",
]
[[package]]
name = "toml_writer"
-version = "1.0.6+spec-1.1.0"
+version = "1.1.1+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
+checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
[[package]]
name = "tower"
-version = "0.5.2"
+version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
+checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
dependencies = [
"futures-core",
"futures-util",
@@ -1174,9 +1071,9 @@ dependencies = [
[[package]]
name = "typenum"
-version = "1.19.0"
+version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
+checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
[[package]]
name = "ucd-trie"
@@ -1186,56 +1083,15 @@ checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
[[package]]
name = "unicode-ident"
-version = "1.0.22"
+version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "unicode-segmentation"
-version = "1.12.0"
+version = "1.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
-
-[[package]]
-name = "untrusted"
-version = "0.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
-
-[[package]]
-name = "ureq"
-version = "3.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d39cb1dbab692d82a977c0392ffac19e188bd9186a9f32806f0aaa859d75585a"
-dependencies = [
- "base64",
- "flate2",
- "log",
- "percent-encoding",
- "rustls",
- "rustls-pki-types",
- "ureq-proto",
- "utf-8",
- "webpki-roots",
-]
-
-[[package]]
-name = "ureq-proto"
-version = "0.5.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d81f9efa9df032be5934a46a068815a10a042b494b6a58cb0a1a97bb5467ed6f"
-dependencies = [
- "base64",
- "http",
- "httparse",
- "log",
-]
-
-[[package]]
-name = "utf-8"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
+checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
[[package]]
name = "version_check"
@@ -1261,9 +1117,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasm-bindgen"
-version = "0.2.106"
+version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
+checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409"
dependencies = [
"cfg-if",
"once_cell",
@@ -1274,9 +1130,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.106"
+version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
+checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1284,9 +1140,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.106"
+version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
+checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e"
dependencies = [
"bumpalo",
"proc-macro2",
@@ -1297,29 +1153,20 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.106"
+version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
+checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437"
dependencies = [
"unicode-ident",
]
-[[package]]
-name = "webpki-roots"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e"
-dependencies = [
- "rustls-pki-types",
-]
-
[[package]]
name = "winapi-util"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys",
]
[[package]]
@@ -1381,24 +1228,6 @@ dependencies = [
"windows-link",
]
-[[package]]
-name = "windows-sys"
-version = "0.52.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
-dependencies = [
- "windows-targets 0.52.6",
-]
-
-[[package]]
-name = "windows-sys"
-version = "0.60.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
-dependencies = [
- "windows-targets 0.53.5",
-]
-
[[package]]
name = "windows-sys"
version = "0.61.2"
@@ -1409,168 +1238,39 @@ dependencies = [
]
[[package]]
-name = "windows-targets"
-version = "0.52.6"
+name = "winnow"
+version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
-dependencies = [
- "windows_aarch64_gnullvm 0.52.6",
- "windows_aarch64_msvc 0.52.6",
- "windows_i686_gnu 0.52.6",
- "windows_i686_gnullvm 0.52.6",
- "windows_i686_msvc 0.52.6",
- "windows_x86_64_gnu 0.52.6",
- "windows_x86_64_gnullvm 0.52.6",
- "windows_x86_64_msvc 0.52.6",
-]
-
-[[package]]
-name = "windows-targets"
-version = "0.53.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
-dependencies = [
- "windows-link",
- "windows_aarch64_gnullvm 0.53.1",
- "windows_aarch64_msvc 0.53.1",
- "windows_i686_gnu 0.53.1",
- "windows_i686_gnullvm 0.53.1",
- "windows_i686_msvc 0.53.1",
- "windows_x86_64_gnu 0.53.1",
- "windows_x86_64_gnullvm 0.53.1",
- "windows_x86_64_msvc 0.53.1",
-]
-
-[[package]]
-name = "windows_aarch64_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
-
-[[package]]
-name = "windows_aarch64_gnullvm"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
-
-[[package]]
-name = "windows_aarch64_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
-
-[[package]]
-name = "windows_aarch64_msvc"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
-
-[[package]]
-name = "windows_i686_gnu"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
-
-[[package]]
-name = "windows_i686_gnu"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
-
-[[package]]
-name = "windows_i686_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
-
-[[package]]
-name = "windows_i686_gnullvm"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
-
-[[package]]
-name = "windows_i686_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
-
-[[package]]
-name = "windows_i686_msvc"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
-
-[[package]]
-name = "windows_x86_64_gnu"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
-
-[[package]]
-name = "windows_x86_64_gnu"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
-
-[[package]]
-name = "windows_x86_64_gnullvm"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
-
-[[package]]
-name = "windows_x86_64_gnullvm"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
-
-[[package]]
-name = "windows_x86_64_msvc"
-version = "0.52.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
-
-[[package]]
-name = "windows_x86_64_msvc"
-version = "0.53.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
[[package]]
name = "winnow"
-version = "0.7.14"
+version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
+checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1"
[[package]]
name = "zerocopy"
-version = "0.8.31"
+version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
+checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
-version = "0.8.31"
+version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
+checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
-[[package]]
-name = "zeroize"
-version = "1.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
-
[[package]]
name = "zmij"
-version = "1.0.0"
+version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6d6085d62852e35540689d1f97ad663e3971fc19cf5eceab364d62c646ea167"
+checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
diff --git a/Cargo.toml b/Cargo.toml
index 16a37ef..833205b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "en"
-version = "0.1.0"
+version = "0.4.0-alpha"
description = "A non-linear writing instrument."
license = "AGPL-3.0-only"
@@ -9,7 +9,7 @@ homepage = "https://en.jutty.dev"
documentation = "https://en.jutty.dev/node/Documentation"
edition = "2024"
-rust-version= "1.91.1"
+rust-version= "1.94.0"
[features]
serial-tests = []
@@ -23,7 +23,6 @@ serde = { version = "1.0.228", features = ["derive"] }
toml = "0.9.8"
[dev-dependencies]
-ureq = "3"
tower = { version = "0.5.2", features = ["util"] }
[lints.rust]
@@ -34,176 +33,269 @@ let_underscore= { level = "warn", priority = 10 }
nonstandard-style = "warn"
future-incompatible = "warn"
keyword-idents = "warn"
+non_ascii_idents = "warn"
[lints.clippy]
# levels: allow, warn, deny, forbid
-manual_non_exhaustive = "allow"
-collapsible_if = "allow"
-collapsible_else_if = "allow"
-field_reassign_with_default = "allow"
-
-# pedantic
+allow_attributes = "warn"
+arithmetic_side_effects = "warn"
+as_conversions = "warn"
+as_pointer_underscore = "warn"
+as_underscore = "warn"
assigning_clones = "warn"
-borrow_as_ptr = "warn"
+branches_sharing_code = "warn"
+case_sensitive_file_extension_comparisons = "warn"
cast_lossless = "warn"
+cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
-cast_ptr_alignment = "warn"
+cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
+clear_with_drain = "warn"
cloned_instead_of_copied = "warn"
+cmp_owned = "warn"
+coerce_container_to_any = "warn"
+collapsible_else_if = "allow"
+collapsible_if = "allow"
+collection_is_never_read = "warn"
+comparison_chain = "warn"
copy_iterator = "warn"
default_trait_access = "warn"
+deref_by_slicing = "warn"
+derive_partial_eq_without_eq = "warn"
doc_broken_link = "warn"
doc_comment_double_space_linebreaks = "warn"
+doc_include_without_cfg = "warn"
+doc_link_code = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
-empty_enum = "warn"
-enum_glob_use = "warn"
+doc_paragraphs_missing_punctuation = "warn"
+double_must_use = "warn"
+duration_suboptimal_units = "warn"
+empty_drop = "warn"
+empty_enum_variants_with_brackets = "warn"
+empty_enums = "warn"
+empty_structs_with_brackets = "warn"
+equatable_if_let = "warn"
+error_impl_error = "warn"
+exit = "warn"
+expect_used = "warn"
expl_impl_clone_on_copy = "warn"
+explicit_counter_loop = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
+fallible_impl_from = "warn"
+field_reassign_with_default = "allow"
+filetype_is_file = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp = "warn"
+float_cmp_const = "warn"
+fn_to_numeric_cast_any = "warn"
+format_collect = "warn"
+format_push_string = "warn"
from_iter_instead_of_collect = "warn"
+get_unwrap = "warn"
if_not_else = "warn"
+if_then_some_else_none = "warn"
ignore_without_reason = "warn"
ignored_unit_patterns = "warn"
implicit_clone = "warn"
implicit_hasher = "warn"
+imprecise_flops = "warn"
inconsistent_struct_constructor = "warn"
index_refutable_slice = "warn"
+indexing_slicing = "warn"
inefficient_to_string = "warn"
+infinite_loop = "warn"
+int_plus_one = "warn"
+integer_division = "warn"
+integer_division_remainder_used = "warn"
+into_iter_without_iter = "warn"
invalid_upcast_comparisons = "warn"
ip_constant = "warn"
iter_filter_is_ok = "warn"
iter_filter_is_some = "warn"
+iter_kv_map = "warn"
+iter_not_returning_iterator = "warn"
+iter_on_empty_collections = "warn"
+iter_on_single_items = "warn"
+iter_with_drain = "warn"
+iter_without_into_iter = "warn"
large_digit_groups = "warn"
large_futures = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
+let_underscore_must_use = "warn"
linkedlist = "warn"
+literal_string_with_formatting_args = "warn"
+lossy_float_literal = "warn"
+macro_use_imports = "warn"
manual_assert = "warn"
+manual_checked_ops = "warn"
+manual_ilog2 = "warn"
manual_instant_elapsed = "warn"
+manual_is_multiple_of = "warn"
manual_is_power_of_two = "warn"
manual_is_variant_and = "warn"
manual_let_else = "warn"
manual_midpoint = "warn"
+manual_non_exhaustive = "allow"
+manual_option_zip = "warn"
+manual_pop_if = "warn"
manual_string_new = "warn"
+manual_take = "warn"
many_single_char_names = "warn"
-map_unwrap_or = "warn"
+map_err_ignore = "warn"
+map_with_unused_argument_over_ranges = "warn"
match_bool = "warn"
match_same_arms = "warn"
match_wild_err_arm = "warn"
match_wildcard_for_single_variants = "warn"
maybe_infinite_iter = "warn"
+mem_forget = "warn"
mismatching_type_param_order = "warn"
+missing_assert_message = "warn"
+missing_asserts_for_indexing = "warn"
+missing_const_for_fn = "warn"
missing_errors_doc = "warn"
missing_fields_in_debug = "warn"
missing_panics_doc = "warn"
+mixed_read_write_in_expression = "warn"
+mod_module_files = "warn"
+module_name_repetitions = "warn"
+multiple_inherent_impl = "warn"
mut_mut = "warn"
+mutex_atomic = "warn"
+mutex_integer = "warn"
naive_bytecount = "warn"
+needless_collect = "warn"
needless_continue = "warn"
needless_for_each = "warn"
+needless_pass_by_ref_mut = "warn"
needless_pass_by_value = "warn"
needless_raw_string_hashes = "warn"
+needless_raw_strings = "warn"
+needless_type_cast = "warn"
no_effect_underscore_binding = "warn"
+non_send_fields_in_send_ty = "warn"
+non_std_lazy_statics = "warn"
+non_zero_suggestions = "warn"
+nonstandard_macro_braces = "warn"
option_as_ref_cloned = "warn"
option_option = "warn"
-ptr_as_ptr = "warn"
-ptr_cast_constness = "warn"
+panic_in_result_fn = "warn"
+path_buf_push_overwrite = "warn"
+pathbuf_init_then_push = "warn"
+possible_missing_else = "warn"
pub_underscore_fields = "warn"
+pub_without_shorthand = "warn"
+question_mark = "warn"
range_minus_one = "warn"
range_plus_one = "warn"
+rc_buffer = "warn"
+rc_mutex = "warn"
+read_zero_byte_vec = "warn"
+redundant_clone = "warn"
+redundant_closure = "warn"
redundant_closure_for_method_calls = "warn"
-ref_as_ptr = "warn"
+redundant_iter_cloned = "warn"
+redundant_pub_crate = "warn"
+redundant_test_prefix = "warn"
+redundant_type_annotations = "warn"
ref_binding_to_reference = "warn"
ref_option = "warn"
ref_option_ref = "warn"
+renamed_function_params = "warn"
+replace_box = "warn"
+rest_pat_in_fully_bound_structs = "warn"
+return_and_then = "warn"
return_self_not_must_use = "warn"
same_functions_in_if_condition = "warn"
+same_length_and_capacity = "warn"
+same_name_method = "warn"
+search_is_some = "warn"
+self_only_used_in_recursion = "warn"
semicolon_if_nothing_returned = "warn"
+semicolon_inside_block = "warn"
set_contains_or_insert = "warn"
+shadow_reuse = "warn"
+shadow_same = "warn"
+shadow_unrelated = "warn"
should_panic_without_expect = "warn"
-similar_names = "warn"
+single_char_pattern = "warn"
+single_match_else = "warn"
+single_option_map = "warn"
+stable_sort_primitive = "warn"
str_split_at_newline = "warn"
+string_add = "warn"
+string_add_assign = "warn"
+string_lit_as_bytes = "warn"
+string_lit_chars_any = "warn"
+string_slice = "warn"
struct_field_names = "warn"
+suboptimal_flops = "warn"
+suspicious_operation_groupings = "warn"
+suspicious_xor_used_as_pow = "warn"
+tests_outside_test_module = "warn"
+too_long_first_doc_paragraph = "warn"
+trait_duplication_in_bounds = "warn"
trivially_copy_pass_by_ref = "warn"
+try_err = "warn"
+tuple_array_conversions = "warn"
+type_repetition_in_bounds = "warn"
unchecked_time_subtraction = "warn"
unicode_not_nfc = "warn"
uninlined_format_args = "warn"
unnecessary_box_returns = "warn"
+unnecessary_cast = "warn"
unnecessary_debug_formatting = "warn"
+unnecessary_fold = "warn"
unnecessary_join = "warn"
unnecessary_literal_bound = "warn"
+unnecessary_option_map_or_else = "warn"
+unnecessary_result_map_or_else = "warn"
+unnecessary_self_imports = "warn"
unnecessary_semicolon = "warn"
+unnecessary_struct_initialization = "warn"
+unnecessary_trailing_comma = "warn"
unnecessary_wraps = "warn"
+unneeded_field_pattern = "warn"
unnested_or_patterns = "warn"
unreadable_literal = "warn"
unsafe_derive_deserialize = "warn"
+unseparated_literal_suffix = "warn"
unused_async = "warn"
+unused_peekable = "warn"
+unused_result_ok = "warn"
+unused_rounding = "warn"
unused_self = "warn"
+unused_trait_names = "warn"
+unwrap_in_result = "warn"
+unwrap_used = "warn"
used_underscore_binding = "warn"
+used_underscore_items = "warn"
+useless_concat = "warn"
+useless_conversion = "warn"
+useless_let_if_seq = "warn"
+verbose_file_reads = "warn"
+volatile_composites = "warn"
+wildcard_enum_match_arm = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
-# restrictive
-arithmetic_side_effects = "warn"
-as_conversions = "warn"
-as_pointer_underscore = "warn"
-as_underscore = "warn"
-deref_by_slicing = "warn"
-empty_drop = "warn"
-empty_enum_variants_with_brackets = "warn"
-error_impl_error = "warn"
-exit = "warn"
-expect_used = "warn"
-filetype_is_file = "warn"
-float_cmp_const = "warn"
-fn_to_numeric_cast_any = "warn"
-if_then_some_else_none = "warn"
-indexing_slicing = "warn"
-infinite_loop = "warn"
-integer_division = "warn"
-integer_division_remainder_used = "warn"
-let_underscore_must_use = "warn"
-let_underscore_untyped = "warn"
-lossy_float_literal = "warn"
-map_err_ignore = "warn"
-map_with_unused_argument_over_ranges = "warn"
-missing_assert_message = "warn"
-missing_asserts_for_indexing = "warn"
-mixed_read_write_in_expression = "warn"
-module_name_repetitions = "warn"
-multiple_inherent_impl = "warn"
-needless_raw_strings = "warn"
-non_zero_suggestions = "warn"
-panic_in_result_fn = "warn"
-pathbuf_init_then_push = "warn"
-pub_without_shorthand = "warn"
-redundant_test_prefix = "warn"
-redundant_type_annotations = "warn"
-renamed_function_params = "warn"
-rest_pat_in_fully_bound_structs = "warn"
-return_and_then = "warn"
-same_name_method = "warn"
-semicolon_outside_block = "warn"
-shadow_reuse = "warn"
-shadow_same = "warn"
-shadow_unrelated = "warn"
-string_add = "warn"
-string_lit_chars_any = "warn"
-unnecessary_self_imports = "warn"
-unneeded_field_pattern = "warn"
-unseparated_literal_suffix = "warn"
-unused_result_ok = "warn"
-unused_trait_names = "warn"
-unwrap_used = "warn"
-verbose_file_reads = "warn"
-wildcard_enum_match_arm = "warn"
-
# cargo
negative_feature_names = "warn"
redundant_feature_names = "warn"
+wildcard_dependencies = "warn"
+
+[package.metadata.typos.default]
+extend-ignore-re = [
+ "oficial do Brasil",
+ "Creative Commons ND",
+ "Creative Commons BY-ND",
+ "CC_BY_ND_",
+ "(?ms)^mod tests \\{.*^\\}",
+]
diff --git a/README.md b/README.md
index 685af8e..2416d37 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,19 @@
# en
-en is a tool to write non-linear, connected pieces of text and have their references mapped out as a graph of connected information.
+en is a tool to write non-linear, connected pieces of text and have their references mapped out as a metadata-rich graph of connected information.
-It works by ingesting a TOML file containing your node specification and serving it as a website that allows nodes to be browsed, searched and listed in relation to each other or as a shallow tree of nodes.
-
-## Roadmap
-
-For an outline of planned and completed features, see the [roadmap](https://en.jutty.dev/node/Roadmap).
+It works by ingesting a graph definition that leverages TOML for metadata and a special markup language for prose. en can then serve this textual representation as a website (with other targets planned) that allows nodes to be explored.
## Learn more
You can learn more and see what en looks like by visiting the [homepage](https://en.jutty.dev), which is rendered using en itself.
+## Install and run
+
+See the [Get Started](https://en.jutty.dev/node/GetStarted) page for instructions and how to install and start using en.
+
+## Roadmap
+
+For a high-level view of what's in the future for en, see the [What's ahead section](https://en.jutty.dev/node/Introduction#What's) of the docs Introduction.
+
+For a more detailed outline of what's planned, along with what's already been completed, see the [roadmap](https://en.jutty.dev/node/Roadmap).
diff --git a/containers/Containerfile.alpine b/containers/Containerfile.alpine
new file mode 100644
index 0000000..392d605
--- /dev/null
+++ b/containers/Containerfile.alpine
@@ -0,0 +1,36 @@
+FROM alpine:latest
+MAINTAINER Juno Takano juno@jutty.dev
+ENV DEBUG=debug
+
+# Setup tooling
+RUN apk add curl clang git file
+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
+
+# Install
+RUN < Level {
}
}
-#[allow(clippy::print_stderr)]
+#[expect(clippy::print_stderr)]
pub fn print_state() {
let env_level = env_level();
let version = env!("CARGO_PKG_VERSION");
@@ -90,7 +90,7 @@ pub fn print_state() {
}
}
-#[allow(clippy::print_stderr)]
+#[expect(clippy::print_stderr)]
pub fn timed(past: &Instant, message: &str) -> Instant {
let now = Instant::now();
let env_level = env_level();
@@ -114,15 +114,13 @@ pub fn timed(past: &Instant, message: &str) -> Instant {
#[macro_export]
macro_rules! tlog {
($instant:expr, $fmt:expr $(, $($arg:tt)+ )?) => {{
- $crate::log::timed($instant, &format!($fmt $(, $($arg)+ )?))
+ $crate::dev::log::timed($instant, &format!($fmt $(, $($arg)+ )?))
}};
}
-pub fn now() -> Instant {
- Instant::now()
-}
+pub fn now() -> Instant { Instant::now() }
-#[allow(clippy::print_stderr)]
+#[expect(clippy::print_stderr, clippy::use_debug)]
pub fn elog(function: &str, message: &str) {
eprintln!("{:?} [{function}] {message}", crate::ONSET.elapsed());
}
@@ -131,26 +129,26 @@ pub fn elog(function: &str, message: &str) {
macro_rules! log {
($level:path, $fmt:expr $(, $($arg:tt)+ )?) => {{
- let data = $crate::log::Data::new(
+ let data = $crate::dev::log::Data::new(
Some($level),
std::any::type_name_of_val(&|| {}),
std::backtrace::Backtrace::capture(),
);
if data.should_log {
- $crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
+ $crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
}
}};
($fmt:expr $(, $($arg:tt)+ )?) => {{
- let data = $crate::log::Data::new(
+ let data = $crate::dev::log::Data::new(
None,
std::any::type_name_of_val(&|| {}),
std::backtrace::Backtrace::capture(),
);
if data.should_log {
- $crate::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
+ $crate::dev::log::elog(&data.path, &format!($fmt $(, $($arg)+ )?));
};
}};
@@ -211,13 +209,22 @@ pub fn wrap(s: &str) -> String {
}
}
- fn escape(s: &str) -> String {
- s.escape_debug().collect()
- }
+ fn escape(s: &str) -> String { s.escape_debug().collect() }
symbolize("e(&escape(s)))
}
+#[macro_export]
+macro_rules! write_log {
+ ($buffer:expr, $format_string:expr $(, $format_args:expr)* $(,)?) => {{
+ use std::fmt::Write as _;
+ let result = write!($buffer, $format_string $(, $format_args)*);
+ if let Err(error) = result {
+ log!(ERROR, "Unexpected error writing into {}: ${error}", $buffer);
+ }
+ }};
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -243,7 +250,7 @@ mod tests {
}
fn run_in_debug_level(level: &str) {
- #[allow(unsafe_code)]
+ #[expect(unsafe_code)]
unsafe {
std::env::set_var("DEBUG", level);
log!("Debug is set to {level}");
@@ -265,7 +272,7 @@ mod tests {
fn test(&self);
}
- struct Logger {}
+ struct Logger;
impl Loggable for Logger {
fn test(&self) {
diff --git a/src/dev/log/level.rs b/src/dev/log/level.rs
new file mode 100644
index 0000000..55c3627
--- /dev/null
+++ b/src/dev/log/level.rs
@@ -0,0 +1,194 @@
+#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
+#[repr(u16)]
+pub enum Level {
+ SILENT = 0,
+ FATAL = 1,
+ ERROR = 2,
+ WARN = 3,
+ INFO = 4,
+ DEBUG = 5,
+ VERBOSE = 6,
+ TRACE = 7,
+ META = 37,
+}
+
+pub const ENV_DEFAULT: Level = Level::WARN;
+pub const MESSAGE_DEFAULT: Level = Level::DEBUG;
+
+impl From for u16 {
+ fn from(level: Level) -> u16 {
+ match level {
+ Level::SILENT => 0,
+ Level::FATAL => 1,
+ Level::ERROR => 2,
+ Level::WARN => 3,
+ Level::INFO => 4,
+ Level::DEBUG => 5,
+ Level::VERBOSE => 6,
+ Level::TRACE => 7,
+ Level::META => 37,
+ }
+ }
+}
+
+impl From for Level {
+ fn from(numeric: u16) -> Level {
+ if numeric == 0 {
+ Level::SILENT
+ } else if numeric == 1 {
+ Level::FATAL
+ } else if numeric == 2 {
+ Level::ERROR
+ } else if numeric == 3 {
+ Level::WARN
+ } else if numeric == 4 {
+ Level::INFO
+ } else if numeric == 5 {
+ Level::DEBUG
+ } else if numeric == 6 {
+ Level::VERBOSE
+ } else if numeric == 7 {
+ Level::TRACE
+ } else if numeric == 37 {
+ Level::META
+ } else {
+ super::ENV_DEFAULT
+ }
+ }
+}
+
+impl From<&str> for Level {
+ fn from(s: &str) -> Level {
+ if s == "0" || s.to_uppercase() == "SILENT" {
+ Level::SILENT
+ } else if s == "1" || s.to_uppercase() == "FATAL" {
+ Level::FATAL
+ } else if s == "2" || s.to_uppercase() == "ERROR" {
+ Level::ERROR
+ } else if s == "3"
+ || s.to_uppercase() == "WARN"
+ || s.to_uppercase() == "WARNING"
+ {
+ Level::WARN
+ } else if s == "4" || s.to_uppercase() == "INFO" {
+ Level::INFO
+ } else if s == "5" || s.to_uppercase() == "DEBUG" {
+ Level::DEBUG
+ } else if s == "6" || s.to_uppercase() == "VERBOSE" {
+ Level::VERBOSE
+ } else if s == "7" || s.to_uppercase() == "TRACE" {
+ Level::TRACE
+ } else if s == "37" || s.to_uppercase() == "META" {
+ Level::META
+ } else {
+ super::ENV_DEFAULT
+ }
+ }
+}
+impl std::fmt::Display for Level {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let s = match self {
+ Level::SILENT => "SILENT",
+ Level::FATAL => "FATAL",
+ Level::ERROR => "ERROR",
+ Level::WARN => "WARNING",
+ Level::INFO => "INFO",
+ Level::DEBUG => "DEBUG",
+ Level::VERBOSE => "VERBOSE",
+ Level::TRACE => "TRACE",
+ Level::META => "META",
+ };
+ write!(f, "{s}")
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn u16_from_level() {
+ assert_eq!(u16::from(Level::SILENT), 0);
+ assert_eq!(u16::from(Level::FATAL), 1);
+ assert_eq!(u16::from(Level::ERROR), 2);
+ assert_eq!(u16::from(Level::WARN), 3);
+ assert_eq!(u16::from(Level::INFO), 4);
+ assert_eq!(u16::from(Level::DEBUG), 5);
+ assert_eq!(u16::from(Level::VERBOSE), 6);
+ assert_eq!(u16::from(Level::TRACE), 7);
+ assert_eq!(u16::from(Level::META), 37);
+ }
+
+ #[test]
+ fn level_from_u16() {
+ assert_eq!(Level::from(0), Level::SILENT);
+ assert_eq!(Level::from(1), Level::FATAL);
+ assert_eq!(Level::from(2), Level::ERROR);
+ assert_eq!(Level::from(3), Level::WARN);
+ assert_eq!(Level::from(4), Level::INFO);
+ assert_eq!(Level::from(5), Level::DEBUG);
+ assert_eq!(Level::from(6), Level::VERBOSE);
+ assert_eq!(Level::from(7), Level::TRACE);
+ assert_eq!(Level::from(37), Level::META);
+ assert_eq!(Level::from(99), Level::WARN);
+ }
+
+ #[test]
+ fn level_from_str() {
+ assert_eq!(Level::from("0"), Level::SILENT);
+ assert_eq!(Level::from("SILENT"), Level::SILENT);
+ assert_eq!(Level::from("silent"), Level::SILENT);
+ assert_eq!(Level::from("SiLEnT"), Level::SILENT);
+
+ assert_eq!(Level::from("1"), Level::FATAL);
+ assert_eq!(Level::from("FATAL"), Level::FATAL);
+ assert_eq!(Level::from("fatal"), Level::FATAL);
+ assert_eq!(Level::from("FaTaL"), Level::FATAL);
+
+ assert_eq!(Level::from("3"), Level::WARN);
+ assert_eq!(Level::from("WARN"), Level::WARN);
+ assert_eq!(Level::from("warn"), Level::WARN);
+ assert_eq!(Level::from("WaRn"), Level::WARN);
+ assert_eq!(Level::from("WARNING"), Level::WARN);
+ assert_eq!(Level::from("warning"), Level::WARN);
+ assert_eq!(Level::from("WaRninG"), Level::WARN);
+
+ assert_eq!(Level::from("4"), Level::INFO);
+ assert_eq!(Level::from("INFO"), Level::INFO);
+ assert_eq!(Level::from("info"), Level::INFO);
+ assert_eq!(Level::from("iNFo"), Level::INFO);
+
+ assert_eq!(Level::from("5"), Level::DEBUG);
+ assert_eq!(Level::from("DEBUG"), Level::DEBUG);
+ assert_eq!(Level::from("debug"), Level::DEBUG);
+ assert_eq!(Level::from("deBuG"), Level::DEBUG);
+
+ assert_eq!(Level::from("6"), Level::VERBOSE);
+ assert_eq!(Level::from("VERBOSE"), Level::VERBOSE);
+ assert_eq!(Level::from("verbose"), Level::VERBOSE);
+ assert_eq!(Level::from("VerBosE"), Level::VERBOSE);
+
+ assert_eq!(Level::from("7"), Level::TRACE);
+ assert_eq!(Level::from("TRACE"), Level::TRACE);
+ assert_eq!(Level::from("trace"), Level::TRACE);
+ assert_eq!(Level::from("trAcE"), Level::TRACE);
+
+ assert_eq!(Level::from("37"), Level::META);
+ assert_eq!(Level::from("META"), Level::META);
+ assert_eq!(Level::from("meta"), Level::META);
+ assert_eq!(Level::from("mETa"), Level::META);
+ }
+
+ #[test]
+ fn display_level() {
+ assert_eq!(format!("{}", Level::SILENT), "SILENT");
+ assert_eq!(format!("{}", Level::FATAL), "FATAL");
+ assert_eq!(format!("{}", Level::ERROR), "ERROR");
+ assert_eq!(format!("{}", Level::WARN), "WARNING");
+ assert_eq!(format!("{}", Level::INFO), "INFO");
+ assert_eq!(format!("{}", Level::DEBUG), "DEBUG");
+ assert_eq!(format!("{}", Level::VERBOSE), "VERBOSE");
+ assert_eq!(format!("{}", Level::TRACE), "TRACE");
+ assert_eq!(format!("{}", Level::META), "META");
+ }
+}
diff --git a/src/dev/test.rs b/src/dev/test.rs
new file mode 100644
index 0000000..8a4ec15
--- /dev/null
+++ b/src/dev/test.rs
@@ -0,0 +1,211 @@
+use std::{env, fs, io, path::PathBuf};
+
+use crate::prelude::*;
+
+#[derive(Debug)]
+pub struct Directories {
+ pub original: PathBuf,
+ pub templates: PathBuf,
+ pub assets: PathBuf,
+ pub test: PathBuf,
+}
+
+impl Directories {
+ /// Sets up self-cleaning original, temporary and 'templates' directories.
+ ///
+ /// # Errors
+ /// May return Error when:
+ /// - Current directory does not exist or lacking permissions
+ /// - Several I/O possibilities from directory creation failures
+ /// - Several I/O possibilities from working directory changing failures
+ pub fn setup(dir_name: &str) -> Result {
+ let original = env::current_dir()?;
+ let test = original.join(format!("target/mocks/{dir_name}"));
+ let templates = test.join("templates");
+ let assets = test.join("static").join("public").join("assets");
+
+ drop(fs::remove_dir_all(&test));
+
+ if let Err(error) = fs::create_dir_all(&test) {
+ return Err(Error::with_io(
+ "Failed test's directory creation",
+ error,
+ ))
+ }
+
+ if let Err(error) = fs::create_dir_all(&templates) {
+ return Err(Error::with_io(
+ "Failed 'templates' directory creation",
+ error,
+ ))
+ }
+
+ if let Err(error) = fs::create_dir_all(&assets) {
+ return Err(Error::with_io(
+ "Failed 'assets' directory creation",
+ error,
+ ))
+ }
+
+ if let Err(error) = env::set_current_dir(&test) {
+ return Err(Error::with_io("Failed current directory change", error))
+ }
+
+ Ok(Directories {
+ original,
+ templates,
+ assets,
+ test,
+ })
+ }
+}
+
+impl Drop for Directories {
+ fn drop(&mut self) {
+ if let Err(error) = std::env::set_current_dir(&self.original) {
+ log!(ERROR, "Couldn't reset to original directory: {error}");
+ }
+ if let Err(error) = std::fs::remove_dir_all(&self.test) {
+ log!(WARN, "Couldn't cleanup test directory: {error}");
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct Error {
+ pub message: String,
+ pub inner_io: Option,
+ pub inner_tera: Option,
+}
+
+impl Error {
+ fn with_io(message: &str, inner_error: io::Error) -> Error {
+ Error {
+ message: String::from(message),
+ inner_io: Some(inner_error),
+ inner_tera: None,
+ }
+ }
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let mut message = self.message.clone();
+
+ if let Some(inner_io) = &self.inner_io {
+ message = format!("{message}\n{inner_io}");
+ }
+
+ if let Some(inner_tera) = &self.inner_tera {
+ message = format!("{message}\n{inner_tera}");
+ }
+
+ write!(f, "{message}")
+ }
+}
+
+impl From for Error {
+ fn from(string: String) -> Error {
+ Error {
+ message: string,
+ inner_io: None,
+ inner_tera: None,
+ }
+ }
+}
+
+impl From<&str> for Error {
+ fn from(str: &str) -> Error { Error::from(String::from(str)) }
+}
+
+impl From for Error {
+ fn from(inner: io::Error) -> Error {
+ let mut error = Error::from(inner.to_string());
+ error.inner_io = Some(inner);
+ error
+ }
+}
+
+impl From for Error {
+ fn from(inner: tera::Error) -> Error {
+ let mut error = Error::from(inner.to_string());
+ error.inner_tera = Some(inner);
+ error
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn bad_test_directory_name() {
+ let dirs = Directories::setup("\0");
+ assert!(dirs.is_err());
+ }
+
+ #[test]
+ fn display_contains_str_from_from() {
+ let payload = "rHneusPkYNGW0Ia0";
+ let error = Error::from(payload);
+ assert!(format!("{error}").contains(payload));
+ }
+
+ #[test]
+ fn display_contains_str_from_io_error() {
+ let payload = "SsVi0d3Ywc8kVhwp";
+ let io_payload = "LoPbZP7cJEHzAjGW";
+ let io_error = std::io::Error::other(io_payload);
+ let error = Error::with_io(payload, io_error);
+ assert!(format!("{error}").contains(payload));
+ assert!(format!("{error}").contains(io_payload));
+ }
+
+ #[test]
+ fn display_contains_str_from_tera_error() {
+ let payload = "pA6B0LhiiDMNCl1J";
+ let tera_payload = "5ob8H594dCAQ8pfk";
+ let error = Error {
+ message: payload.to_string(),
+ inner_tera: Some(tera::Error::msg(tera_payload)),
+ inner_io: None,
+ };
+ assert!(format!("{error}").contains(payload));
+ assert!(format!("{error}").contains(tera_payload));
+ }
+ #[test]
+ fn from_io_error() {
+ let payload = "YgmTKBm3VtHt5h3x9";
+ let io_error = std::io::Error::other(payload);
+ let error = Error::from(io_error);
+
+ assert!(error.message.contains(payload));
+ }
+
+ #[test]
+ fn from_tera_error() {
+ let payload = "XEB3dcvYuz0M1lYt";
+ let tera_error = tera::Error::msg(payload);
+ let error = Error::from(tera_error);
+
+ assert!(error.message.contains(payload));
+ }
+}
+
+#[cfg(test)]
+mod serial_tests {
+ use super::*;
+
+ #[test]
+ fn failed_working_directory_reset() {
+ let dirs = Directories::setup("\0");
+
+ let error = dirs.unwrap_err();
+ println!("{error}");
+ assert!(error.message.contains("Failed test's directory creation"));
+ assert!(
+ format!("{error}")
+ .contains("file name contained an unexpected NUL byte")
+ );
+ }
+}
diff --git a/src/graph.rs b/src/graph.rs
index 8a3e01c..9cc62a5 100644
--- a/src/graph.rs
+++ b/src/graph.rs
@@ -1,28 +1,30 @@
-use std::{collections::HashMap, path::PathBuf};
+use std::{collections::HashMap, io, path::PathBuf};
-use serde::{Serialize, Deserialize};
+pub use edge::Edge;
+pub use meta::{Config, Meta};
+pub use node::Node;
+use serde::{Deserialize, Serialize};
-use crate::syntax::{
- command::Arguments,
- content::{
- self,
- parser::{flatten, Token, token::Anchor},
+use crate::{
+ prelude::*,
+ syntax::{
+ command::Arguments,
+ content::{
+ self,
+ parser::{Token, flatten, token::Anchor},
+ },
},
};
-use crate::prelude::*;
-pub use {
- node::Node,
- edge::Edge,
- meta::{Meta, Config},
-};
-pub mod node;
pub mod edge;
pub mod meta;
+pub mod node;
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Graph {
+ #[serde(default)]
pub nodes: HashMap,
+ #[serde(default)]
pub root_node: String,
#[serde(skip_deserializing)]
pub incoming: HashMap>,
@@ -37,9 +39,22 @@ pub struct Graph {
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Stats {
pub detached: HashMap,
+ pub detached_total: u32,
}
impl Graph {
+ fn welcome() -> Graph {
+ let toml = include_str!("../static/welcome.toml");
+ let mut welcome_graph = match Graph::from_serial(toml, &Format::TOML) {
+ Ok(graph) => graph,
+ Err(error) => {
+ panic!("Welcome graph parsing must be infallible: {error:?}")
+ },
+ };
+ welcome_graph.modulate();
+ welcome_graph
+ }
+
pub fn with_message(message: &str) -> Graph {
let graph = Graph::default();
let mut messages = graph.meta.messages;
@@ -63,25 +78,37 @@ impl Graph {
graph
}
- /// Loads a TOML file from the default location and returns a modulated Graph
+ /// Loads a Graph TOML file from CLI arguments or their defaults and
+ /// returns a modulated Graph.
///
- /// Returns a graph with an error message if any errors are propagated to it.
+ /// Loads a default graph with basic usage instructions if no file is found.
+ ///
+ /// Returns a graph with an error message if any errors are propagated.
pub fn load() -> Graph {
let result = Graph::load_file(None);
match result {
Ok(graph) => graph,
- Err(error) => Graph::malformed(Some(&error)),
+ Err(error) => {
+ if error.not_found {
+ return Graph::welcome()
+ }
+ if let Some(message) = error.message {
+ Graph::malformed(Some(&message))
+ } else {
+ Graph::malformed(None)
+ }
+ },
}
}
- /// Takes a file path to a TOML file and returns a modulated Graph
+ /// Takes a file path to a TOML file and returns a modulated Graph.
///
- /// If `path` is an empty string, it will fallback to CLI arguments
+ /// If `path` is None, it will fallback to CLI arguments or their defaults.
///
/// # Errors
/// Propagates errors from `Graph::read_file`.
- pub fn load_file(path: Option<&str>) -> Result {
- let mut graph = Graph::read_file(path)?;
+ pub fn load_file(path: Option<&str>) -> Result {
+ let mut graph = Graph::from_file(path)?;
graph.modulate();
Ok(graph)
}
@@ -91,19 +118,30 @@ impl Graph {
/// # Errors
/// Returns Err if it can't read the contents of `in_path`.
/// Propagates errors from `Graph::from_serial`.
- pub fn read_file(in_path: Option<&str>) -> Result {
+ pub fn from_file(in_path: Option<&str>) -> Result {
let cli_path = Arguments::default().parse().graph_path;
let path = in_path.map_or(cli_path, PathBuf::from);
- let toml_source = match std::fs::read_to_string(path) {
+ let toml_source = match std::fs::read_to_string(&path) {
Ok(s) => s,
- Err(e) => {
- log!(ERROR, "Failed reading {e}");
- return Err("Failed reading file at {path}".to_string());
+ Err(error) => {
+ log!(
+ ERROR,
+ "Error reading path {}: {error}",
+ path.as_path().display(),
+ );
+ return Err(LoadError::from_io_with_message(
+ &format!(
+ "Failed reading file at {}",
+ path.as_path().display(),
+ ),
+ error,
+ ));
},
};
let result = Graph::from_serial(&toml_source, &Format::TOML)?;
+
Ok(result)
}
@@ -116,7 +154,7 @@ impl Graph {
serial: &str,
format: &Format,
) -> Result {
- match *format {
+ let result = match *format {
Format::TOML => match toml::from_str::(serial) {
Ok(graph) => Ok(graph),
Err(error) => Err(SerialError {
@@ -135,6 +173,23 @@ impl Graph {
cause: SerialErrorCause::UnsupportedFormat,
message: "Unsupported format".to_string(),
}),
+ };
+
+ let graph = result?;
+ Graph::print_warnings(&graph);
+ Ok(graph)
+ }
+
+ fn print_warnings(graph: &Graph) {
+ if graph.meta.config.serve_fonts && !graph.meta.config.footer {
+ log!(
+ WARN,
+ "Ignoring 'footer' value of false (hidden) because \
+ 'serve_fonts' is set to true (by default or explicitly). \
+ This is necessary for compliance with the font licenses. \
+ Either set 'serve_fonts' to false to disable serving fonts \
+ or reenable the footer to suppress this warning."
+ );
}
}
@@ -143,19 +198,16 @@ impl Graph {
/// # Errors
/// Errors on unsupported formats.
/// Propagates serialization errors.
- pub fn to_serial(
- graph: &Graph,
- format: &Format,
- ) -> Result {
+ pub fn to_serial(&self, format: &Format) -> Result {
match *format {
- Format::TOML => match toml::to_string(graph) {
+ Format::TOML => match toml::to_string(self) {
Ok(s) => Ok(s),
Err(e) => Err(SerialError {
cause: SerialErrorCause::MalformedInput,
message: e.to_string(),
}),
},
- Format::JSON => match serde_json::to_string(graph) {
+ Format::JSON => match serde_json::to_string(self) {
Ok(s) => Ok(s),
Err(e) => Err(SerialError {
cause: SerialErrorCause::MalformedInput,
@@ -169,6 +221,11 @@ impl Graph {
}
}
+ fn gather_stats(&mut self) {
+ let detached = self.stats.detached.values();
+ self.stats.detached_total = detached.sum();
+ }
+
pub fn modulate(&mut self) {
let mut instant = now();
instant = tlog!(&instant, "Started node modulation");
@@ -180,14 +237,16 @@ impl Graph {
instant = tlog!(&instant, "Modulated edges");
self.map_incoming();
instant = tlog!(&instant, "Mapped incoming edges");
+ self.gather_stats();
+ instant = tlog!(&instant, "Gathered stats");
self.parse_config();
tlog!(&instant, "Parsed configuration");
}
- // Construct a HashMap with incoming connections (reversed edges)
+ /// Construct a `HashMap` with incoming connections (reversed edges).
fn map_incoming(&mut self) {
for node in self.nodes.clone().into_values() {
- for edge in node.connections.clone().unwrap_or_default().values() {
+ for edge in node.connections.clone().values() {
let mut edges = self
.incoming
.get(&edge.to.clone())
@@ -199,24 +258,35 @@ impl Graph {
}
}
+ /// Modulates nodes that have been deserialized and are still unprocessed.
+ ///
+ /// Performs checked arithmetic to the following effect:
+ /// - Stats will saturate at `u32::MAX` (`increment_detached` calls)
fn modulate_nodes(&mut self) {
let in_nodes = self.nodes.clone();
for (key, node) in in_nodes.clone() {
- let connections = node.connections.clone().unwrap_or_default();
+ let connections = node.connections.clone();
let mut new_edges = connections.clone();
// Modulate connections
for (connection_key, edge) in connections {
let mut new_edge = edge.clone();
- // Populate empty "from" IDs in edges with node's ID
+ // Populate empty "to" and "from" IDs
if edge.from.is_empty() {
- new_edge.from.clone_from(&connection_key);
+ new_edge.from.clone_from(&key);
+ }
+
+ if edge.to.is_empty() {
+ new_edge.to.clone_from(&connection_key);
}
// Flag detached edges
- if in_nodes.contains_key(&edge.to) {
+ if (!edge.to.is_empty() && in_nodes.contains_key(&edge.to))
+ || (edge.to.is_empty()
+ && in_nodes.contains_key(&new_edge.to))
+ {
new_edge.detached = false;
} else {
new_edge.detached = true;
@@ -255,7 +325,7 @@ impl Graph {
// Populate empty summaries with the leading part of the node text
let summary = if node.summary.is_empty() {
let first_line = if let Some(first) =
- node.text.lines().find(|s| !s.is_empty())
+ node.text.split("\n\n").find(|s| !s.is_empty())
{
String::from(first)
} else {
@@ -283,7 +353,7 @@ impl Graph {
id: key.clone(),
title: new_title,
summary: flatten(&summary, self),
- connections: Some(new_edges),
+ connections: new_edges,
..node.clone()
};
@@ -291,31 +361,24 @@ impl Graph {
}
}
+ /// Modulates edges that have been deserialized and are still unprocessed.
+ ///
+ /// Performs checked arithmetic to the following effect:
+ /// - Stats will saturate at `u32::MAX`
fn modulate_edges(&mut self) {
let graph = self.clone();
let iterator = self.nodes.iter_mut();
for (key, node) in iterator {
// Parse node text
let parse_output = content::rich_parse(&node.text, &graph);
- node.text = parse_output.text.unwrap_or_default();
+ node.text
+ .clone_from(&parse_output.text.clone().unwrap_or_default());
// Create connections for each anchor
- let mut parsed_anchor_tokens = parse_output
- .tokens
- .iter()
- .filter(|t| matches!(t, Token::Anchor(_)))
- .cloned()
- .collect::>();
- parsed_anchor_tokens.extend_from_slice(
- &parse_output
- .format_tokens
- .iter()
- .filter(|t| matches!(t, Token::Anchor(_)))
- .cloned()
- .collect::>(),
- );
+ let parsed_anchors =
+ parse_output.only(&Token::Anchor(Box::default()));
let mut anchors: Vec = vec![];
- for token in parsed_anchor_tokens {
+ for token in parsed_anchors {
if let Token::Anchor(token_data) = token {
anchors.push(*token_data.clone());
}
@@ -323,27 +386,33 @@ impl Graph {
for anchor in anchors {
if let Some(anchor_node) = anchor.node() {
- if let Some(ref mut connections) = node.connections {
- connections.insert(
- anchor_node.id.clone(),
- Edge {
- from: key.clone(),
- to: anchor_node.id,
- detached: false,
- },
- );
- }
+ node.connections.insert(
+ anchor_node.id.clone(),
+ Edge {
+ from: key.clone(),
+ to: anchor_node.id,
+ detached: false,
+ },
+ );
} else {
if let Some(destination) = anchor.destination()
- && !anchor.external()
+ && !anchor.absolute()
{
+ let trimmed_destination = destination
+ .trim_start_matches("/node/")
+ .to_string();
+ node.connections.insert(
+ trimmed_destination.clone(),
+ Edge {
+ from: key.clone(),
+ to: trimmed_destination.clone(),
+ detached: true,
+ },
+ );
+
self.stats
.detached
- .entry(
- destination
- .trim_start_matches("/node/")
- .to_string(),
- )
+ .entry(trimmed_destination)
.and_modify(|count| {
*count = count.saturating_add(1);
})
@@ -354,6 +423,10 @@ impl Graph {
}
}
+ /// Increments detached node statistics for the given node ID.
+ ///
+ /// Performs checked arithmetic to the following effect:
+ /// - Stats will saturate at `u32::MAX`
fn increment_detached(&mut self, node_id: &str) {
self.stats
.detached
@@ -370,14 +443,14 @@ impl Graph {
}
pub fn find_node(&self, query: &str) -> QueryResult {
- let collapsed_query = query.trim().replace(" ", "");
+ let collapsed_query = query.trim().replace(' ', "");
if query == collapsed_query {
log!(VERBOSE, "Chasing candidate for query {query}");
} else {
log!(
VERBOSE,
- "Chasing candidate for query {query}, collapsed {collapsed_query}"
+ "Chasing candidate: query {query}, collapsed {collapsed_query}"
);
}
@@ -418,7 +491,11 @@ impl Graph {
redirect: true,
}
} else {
- QueryResult::default()
+ QueryResult {
+ node: None,
+ exact: false,
+ redirect: true,
+ }
}
} else {
log!(VERBOSE, "Returning candidate {candidate}");
@@ -438,13 +515,61 @@ impl Graph {
}
}
+#[derive(Debug)]
pub enum Format {
TOML,
JSON,
Unsupported,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Debug)]
+pub struct LoadError {
+ pub message: Option,
+ pub not_found: bool,
+ pub io_error: Option,
+ pub serial_error: Option,
+}
+
+impl LoadError {
+ fn from_io_with_message(message: &str, io_error: io::Error) -> LoadError {
+ LoadError {
+ message: Some(String::from(message)),
+ not_found: io_error.kind() == io::ErrorKind::NotFound,
+ io_error: Some(io_error),
+ serial_error: None,
+ }
+ }
+}
+
+impl From for LoadError {
+ fn from(error: SerialError) -> LoadError {
+ LoadError {
+ message: Some(error.message.clone()),
+ not_found: false,
+ serial_error: Some(error),
+ io_error: None,
+ }
+ }
+}
+
+impl From for LoadError {
+ fn from(error: io::Error) -> LoadError {
+ LoadError {
+ message: Some(error.to_string()),
+ not_found: error.kind() == io::ErrorKind::NotFound,
+ io_error: Some(error),
+ serial_error: None,
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct SerialError {
+ pub cause: SerialErrorCause,
+ pub message: String,
+}
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum SerialErrorCause {
UnsupportedFormat,
MalformedInput,
@@ -460,12 +585,6 @@ impl std::fmt::Display for SerialErrorCause {
}
}
-#[derive(Serialize, Deserialize, Debug)]
-pub struct SerialError {
- pub cause: SerialErrorCause,
- pub message: String,
-}
-
impl From for String {
fn from(error: SerialError) -> String {
format!("{}: {}", error.cause, error.message)
@@ -489,7 +608,7 @@ impl std::fmt::Display for Format {
match self {
Format::TOML => write!(f, "TOML"),
Format::JSON => write!(f, "JSON"),
- Format::Unsupported => write!(f, "Unsupported"),
+ Format::Unsupported => write!(f, "Unsupported format"),
}
}
}
@@ -503,7 +622,15 @@ pub struct QueryResult {
impl std::fmt::Display for QueryResult {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- let meta = if self.redirect { "[redirect] " } else { "" };
+ let meta = if self.redirect && self.exact {
+ "[exact redirect] "
+ } else if !self.redirect && self.exact {
+ "[exact] "
+ } else if self.redirect && !self.exact {
+ "[redirect] "
+ } else {
+ ""
+ };
let node = if let Some(n) = &self.node {
n.id.clone()
} else {
@@ -538,7 +665,7 @@ mod tests {
"title": "JSON",
"links": [],
"id": "JSON",
- "hidden": false,
+ "listed": true,
"connections": {}
}
},
@@ -557,27 +684,710 @@ mod tests {
e.message.contains("expected value at line 1 column 1")
},));
}
+
+ #[test]
+ fn with_message() {
+ let payload = "QmMxohuLe9DZCOzcaxH2wzZGqOot1In6";
+ let graph = Graph::with_message(payload);
+ assert_eq!(payload, graph.meta.messages.first().unwrap());
+ }
+
+ #[test]
+ fn malformed_without_message() {
+ let graph = Graph::malformed(None);
+ assert!(graph.meta.messages.is_empty());
+ }
+
+ #[test]
+ fn malformed_with_message() {
+ let payload = "s8LuGwRQA4GdNGvAlaIUrryZYBGkY5Ev";
+ let graph = Graph::malformed(Some(payload));
+ assert_eq!(payload, graph.meta.messages.first().unwrap());
+ }
+
+ #[test]
+ fn bad_deserial_input() {
+ let result = Graph::from_serial("not toml", &Format::TOML);
+ assert!(result.is_err());
+ assert!(matches!(
+ result.unwrap_err().cause,
+ SerialErrorCause::MalformedInput
+ ));
+ }
+
+ #[test]
+ fn bad_deserial_format() {
+ let result = Graph::from_serial("not toml", &Format::Unsupported);
+ assert!(result.is_err());
+ assert!(matches!(
+ result.unwrap_err().cause,
+ SerialErrorCause::UnsupportedFormat
+ ));
+ }
+
+ #[test]
+ fn bad_serial_format() {
+ let result = Graph::load().to_serial(&Format::Unsupported);
+ assert!(result.is_err());
+ assert!(matches!(
+ result.unwrap_err().cause,
+ SerialErrorCause::UnsupportedFormat
+ ));
+ }
+
+ #[test]
+ fn empty_modulated_graph_is_empty() {
+ let mut graph = Graph::from_serial("", &Format::TOML).unwrap();
+ graph.modulate();
+
+ assert!(graph.nodes.is_empty());
+ assert!(graph.incoming.is_empty());
+ }
+
+ #[test]
+ fn title_population_from_id() {
+ let mut graph = Graph::from_serial(
+ concat!("[nodes.TitlelessNode]\n", r#"text = "Some text""#,),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let node = graph.nodes.get("TitlelessNode");
+ assert_eq!(node.unwrap().title, "TitlelessNode");
+ }
+
+ #[test]
+ fn no_title_population_from_id_if_title_set() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.TitlefulNode]\n",
+ r#"title = "A Title""#,
+ "\n",
+ r#"text = "Some text""#,
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let node = graph.nodes.get("TitlefulNode");
+ assert_eq!(node.unwrap().title, "A Title");
+ }
+
+ #[test]
+ fn detached_edge_is_flagged() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.Node]\n",
+ r#"text = "Some text here""#,
+ "\n\n",
+ "[nodes.Node.connections.Nowhere]\n",
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let node = &graph.nodes["Node"];
+ let connection = &node.connections["Nowhere"];
+ assert!(connection.detached);
+ }
+
+ #[test]
+ fn attached_edge_is_not_flagged() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.NodeOne]\n",
+ r#"text = "Some text here""#,
+ "\n\n",
+ "[nodes.NodeOne.connections.NodeTwo]\n\n",
+ "[nodes.NodeTwo]\n",
+ r#"text = "Some other text here""#,
+ "\n\n",
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let node = &graph.nodes["NodeOne"];
+ let connection = &node.connections["NodeTwo"];
+ println!("{connection:#?}");
+ assert!(!connection.detached);
+ }
+
+ #[test]
+ fn to_and_from_population() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.n01]\n",
+ "[nodes.n01.connections.n02]\n\n",
+ "[nodes.n02]\n",
+ "[nodes.n02.connections.n03]\n\n",
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let n01 = &graph.nodes["n01"];
+ let n02 = &graph.nodes["n02"];
+ let n01_to_n02 = &n01.connections["n02"];
+ let n02_to_n03 = &n02.connections["n03"];
+
+ assert_eq!(n01_to_n02.from, "n01");
+ assert_eq!(n01_to_n02.to, "n02");
+ assert!(!n01_to_n02.detached);
+ assert_eq!(n02_to_n03.from, "n02");
+ assert_eq!(n02_to_n03.to, "n03");
+ assert!(n02_to_n03.detached);
+ }
+
+ #[test]
+ fn links_become_connections() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.n01]\n",
+ r#"links = [ "n02", "n03", "n04" ]"#,
+ "\n\n",
+ "[nodes.n02]\n",
+ "[nodes.n04]\n",
+ r#"links = [ "n01", "n03" ]"#,
+ "\n\n",
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let n01 = &graph.nodes["n01"];
+ let n02 = &graph.nodes["n02"];
+ let n04 = &graph.nodes["n04"];
+
+ let n01_to_n02 = &n01.connections["n02"];
+ let n01_to_n03 = &n01.connections["n03"];
+ let n01_to_n04 = &n01.connections["n04"];
+
+ let n04_to_n01 = &n04.connections["n01"];
+ let n04_to_n03 = &n04.connections["n03"];
+
+ assert_eq!(n01_to_n02.from, "n01");
+ assert_eq!(n01_to_n02.to, "n02");
+ assert!(!n01_to_n02.detached);
+
+ assert_eq!(n01_to_n03.from, "n01");
+ assert_eq!(n01_to_n03.to, "n03");
+ assert!(n01_to_n03.detached);
+
+ assert_eq!(n01_to_n04.from, "n01");
+ assert_eq!(n01_to_n04.to, "n04");
+ assert!(!n01_to_n04.detached);
+
+ assert!(n02.connections.is_empty());
+
+ assert_eq!(n04_to_n01.from, "n04");
+ assert_eq!(n04_to_n01.to, "n01");
+ assert!(!n04_to_n01.detached);
+
+ assert_eq!(n04_to_n03.from, "n04");
+ assert_eq!(n04_to_n03.to, "n03");
+ assert!(n04_to_n03.detached);
+ }
+
+ #[test]
+ fn detached_count_increments() {
+ let mut graph = Graph::from_serial(
+ concat!(
+ "[nodes.n01]\n",
+ r#"links = [ "n02", "n03", "n04", "n05", "n06", "n10" ]"#,
+ "\n\n",
+ "[nodes.n02]\n",
+ "[nodes.n04]\n",
+ r#"links = [ "n01", "n02", "n03", "n06", "n11", "n15" ]"#,
+ "\n\n"
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(graph.stats.detached_total, 8);
+ }
+
+ #[test]
+ fn populated_summary() {
+ let text = "vh18qEUN22X2SxLj6lpOOzMBB4N6S0UG";
+ let mut graph = Graph::from_serial(
+ &format!(
+ "[nodes.n01]\n\
+ text = \"{text}\"\n\
+ "
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert!(&graph.nodes["n01"].summary.contains(text));
+ assert!(&graph.nodes["n01"].text.contains(text));
+ }
+
+ #[test]
+ fn supplied_summary() {
+ let text = "vh18qEUN22X2SxLj6lpOOzMBB4N6S0UG";
+ let summary = "W5dhPgNs7S1Zsq6uPK47MAw8xXyNxwep";
+ let mut graph = Graph::from_serial(
+ &format!(
+ "[nodes.n01]\n\
+ summary = \"{summary}\"\n\
+ text = \"{text}\"\n\
+ ",
+ ),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(&graph.nodes["n01"].summary, summary);
+ assert!(&graph.nodes["n01"].text.contains(text));
+ }
+
+ #[test]
+ fn summary_from_first_sentence() {
+ let first_sentence = "zTWFX0a8 tYTO2g.";
+ let text = format!(
+ "{first_sentence} QoGa PtDsJ vh18qE U N22 X2S. MBB4N6S0UG\n\n\
+ 6FokUX o OCEc LzZFfR1nkqa hWIF LdrtD3G. PDQwv Ba2PnZ yEBVpqQdt\n\n\
+ Py6aoPK FV7iU UdrYB vD UeMvvg u 5kbt 9ZW9x7MR"
+ );
+ let mut graph = Graph::from_serial(
+ &format!("[nodes.n01]\ntext = \"\"\"{text}\"\"\"\n"),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(&graph.nodes["n01"].summary, first_sentence);
+ }
+
+ #[test]
+ fn summary_from_first_paragraph() {
+ let first_paragraph = "EGR6IS fTQsRp rv7 g jvItnYU 2HNciS MID\n\
+ iz3vx vXxa vW4JI6l E5itd6qm2Yx gFw 1D Nq0805 bXHe3h iqABe ilnHKl\n\
+ F4AHvMLto cz3C Z279r9 jtIbBnY JqjwZPQdepf cdv6";
+ let text = format!(
+ "{first_paragraph}\n\nn0D CvHcIU7R oPcZy V1Iy9PgXO gOw lfeDy\n\n\
+ jrOSq 0uVtJLd Idx08Bpy BBj 4PVS R9lt RqjTs s AURUx93 Xu9WiI0rP.\n"
+ );
+ let mut graph = Graph::from_serial(
+ format!("[nodes.n01]\ntext = \"\"\"{text}\"\"\"\n").as_str(),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(&graph.nodes["n01"].summary, first_paragraph);
+ }
+
+ #[test]
+ fn summary_from_first_300_chars() {
+ let first_300 = concat!(
+ "Primis, quod, cum in rerum natura duo ",
+ "quaerenda sint, unum, quae materia sit, ex qua quaeque res ",
+ "efficiatur, alterum, quae naturales essent nec tamen id, cuius ",
+ "causa haec finxerat, assecutus est: Nam si omnes veri erunt, ut ",
+ "Epicuri ratio docet, tum denique poterit aliquid cognosci et ",
+ "percipi? Quos q"
+ );
+ let tail = concat!(
+ "uam autem et praeterita grate meminit et ",
+ "praesentibus ita potitur, ut animadvertat quanta sint ea ",
+ "quamque iucunda, neque pendet ex futuris, sed expectat illa, ",
+ "fruitur praesentibus ab iisque vitii"
+ );
+ let text = format!("{first_300}{tail}");
+ let summary = format!("{first_300}…");
+
+ let mut graph = Graph::from_serial(
+ format!("[nodes.n01]\ntext = \"\"\"{text}\"\"\"\n").as_str(),
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(graph.nodes["n01"].summary, summary);
+ }
+
+ #[test]
+ fn anchors_become_connections() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]
+ text = 'an anchor to |n2|, the existing node'
+
+ [nodes.n2]
+ text = 'an anchor to |n0|, the nonexistent node'
+
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let n1_to_n2 = &graph.nodes["n1"].connections.get("n2");
+
+ let n2_to_n0 = &graph.nodes["n2"].connections.get("n0");
+
+ println!("{n1_to_n2:#?}");
+ println!("{n2_to_n0:#?}");
+
+ assert!(!n1_to_n2.unwrap().detached);
+ assert!(n2_to_n0.unwrap().detached);
+ }
+
+ #[test]
+ fn detached_anchors_increase_counts() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ text = 'this |anchor| is detached, as is |this one|.'\n\
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(graph.stats.detached_total, 2);
+ assert_eq!(graph.stats.detached["anchor"], 1);
+ assert_eq!(graph.stats.detached["this one"], 1);
+ }
+
+ #[test]
+ fn repeated_detached_anchors_increase_counts() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ text = 'this |anchor| is detached, as appears twice: |anchor|.'\n\
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ assert_eq!(graph.stats.detached_total, 2);
+ assert_eq!(graph.stats.detached["anchor"], 2);
+ }
+
+ #[test]
+ fn find_exact() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n1");
+ assert_eq!(query_result.node.unwrap().id, "n1");
+ assert!(query_result.exact);
+ assert!(!query_result.redirect);
+ }
+
+ #[test]
+ fn find_inexact() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n 1");
+ println!("{query_result}");
+
+ assert_eq!(query_result.node.unwrap().id, "n1");
+ assert!(!query_result.exact);
+ assert!(!query_result.redirect);
+ }
+
+ #[test]
+ fn find_inexact_to_redirect() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ redirect = 'n3'
+ \n\
+ [nodes.n3]
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n 1");
+ println!("{query_result}");
+
+ assert_eq!(query_result.node.unwrap().id, "n3");
+ assert!(!query_result.exact);
+ assert!(query_result.redirect);
+ }
+
+ #[test]
+ fn double_recursion_to_redirect() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ redirect = 'n2'
+ \n\
+ [nodes.n2]\n\
+ redirect = 'n 3'
+ \n\
+ [nodes.n3]
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n 1");
+ println!("{query_result}");
+
+ assert_eq!(query_result.node.unwrap().id, "n3");
+ assert!(!query_result.exact);
+ assert!(query_result.redirect);
+ }
+
+ #[test]
+ fn find_redirect_to_inexisting() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ redirect = 'n0'\n\
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n1");
+ println!("{query_result}");
+
+ assert!(query_result.node.is_none());
+ assert!(query_result.redirect);
+ assert!(!query_result.exact);
+ }
+
+ #[test]
+ fn find_redirect_to_existing() {
+ let mut graph = Graph::from_serial(
+ "\
+ [nodes.n1]\n\
+ redirect = 'n2'\n\
+ \n\
+ [nodes.n2]
+ ",
+ &Format::TOML,
+ )
+ .unwrap();
+ graph.modulate();
+
+ let query_result = graph.find_node("n1");
+ assert_eq!(query_result.node.unwrap().id, "n2");
+ assert!(query_result.redirect);
+ assert!(!query_result.exact);
+ }
+
+ #[test]
+ fn serial_error_display() {
+ let bad_input = SerialErrorCause::MalformedInput;
+ let bad_format = SerialErrorCause::UnsupportedFormat;
+
+ assert_eq!(format!("{bad_input}"), "Malformed Input");
+ assert_eq!(format!("{bad_format}"), "Unsupported Format");
+ }
+
+ #[test]
+ fn string_from_serial_error() {
+ let bad_input_error_message = "denSehpfhCjr05gUd7TgYLb8veJHAMZW";
+ let bad_input_cause = SerialErrorCause::MalformedInput;
+ let bad_input = SerialError {
+ cause: bad_input_cause.clone(),
+ message: bad_input_error_message.to_string(),
+ };
+
+ let bad_format_error_message = "4brcCkWOgLHBvhLk2OcgTOKQgpKrc1bB";
+ let bad_format_cause = SerialErrorCause::UnsupportedFormat;
+ let bad_format = SerialError {
+ cause: bad_format_cause.clone(),
+ message: bad_format_error_message.to_string(),
+ };
+
+ let s_bad_input = String::from(bad_input.clone());
+ let s_bad_format = String::from(bad_format.clone());
+
+ assert!(s_bad_input.contains(bad_input_error_message));
+ assert!(s_bad_input.contains(bad_input.message.as_str()));
+ assert!(s_bad_input.contains(format!("{bad_input_cause}").as_str()));
+
+ assert!(s_bad_format.contains(bad_format_error_message));
+ assert!(s_bad_format.contains(bad_format.message.as_str()));
+ assert!(s_bad_format.contains(format!("{bad_format_cause}").as_str()));
+ }
+
+ #[test]
+ fn format_from_str() {
+ let uppercase_toml = Format::from("TOML");
+ let lowercase_toml = Format::from("toml");
+ let mixed_case_toml = Format::from("tOmL");
+
+ assert!(matches!(uppercase_toml, Format::TOML));
+ assert!(matches!(lowercase_toml, Format::TOML));
+ assert!(matches!(mixed_case_toml, Format::TOML));
+
+ let uppercase_json = Format::from("JSON");
+ let lowercase_json = Format::from("json");
+ let mixed_case_json = Format::from("JsoN");
+
+ assert!(matches!(uppercase_json, Format::JSON));
+ assert!(matches!(lowercase_json, Format::JSON));
+ assert!(matches!(mixed_case_json, Format::JSON));
+
+ let unsupported = [
+ Format::from("j son"),
+ Format::from(""),
+ Format::from("strawberry"),
+ Format::from(" "),
+ Format::from("\n"),
+ ];
+
+ assert!(unsupported.iter().all(|f| matches!(f, Format::Unsupported)));
+ }
+
+ #[test]
+ fn format_display() {
+ let toml = format!("{}", Format::TOML);
+ let json = format!("{}", Format::JSON);
+ let unsupported = format!("{}", Format::Unsupported);
+
+ assert_eq!(toml, "TOML");
+ assert_eq!(json, "JSON");
+ assert_eq!(unsupported, "Unsupported format");
+ }
+
+ #[test]
+ fn query_result_display() {
+ let mut node = Node::default();
+ let node_id = "nv00qmO6PDrqJheUHOONlCVpuceefS30";
+ node.id = String::from(node_id);
+
+ let none_exact = QueryResult {
+ node: None,
+ exact: true,
+ redirect: false,
+ };
+
+ assert!(!format!("{none_exact}").contains(node_id));
+ assert!(format!("{none_exact}").contains("No Match"));
+ assert!(format!("{none_exact}").contains("exact"));
+ assert!(!format!("{none_exact}").contains("redirect"));
+
+ let some_exact = QueryResult {
+ node: Some(node.clone()),
+ exact: true,
+ redirect: false,
+ };
+
+ assert!(format!("{some_exact}").contains(node_id));
+ assert!(!format!("{some_exact}").contains("No Match"));
+ assert!(format!("{some_exact}").contains("exact"));
+ assert!(!format!("{some_exact}").contains("redirect"));
+
+ let none_redirect = QueryResult {
+ node: None,
+ exact: false,
+ redirect: true,
+ };
+
+ assert!(!format!("{none_redirect}").contains(node_id));
+ assert!(format!("{none_redirect}").contains("No Match"));
+ assert!(format!("{none_redirect}").contains("redirect"));
+ assert!(!format!("{none_redirect}").contains("exact"));
+
+ let some_redirect = QueryResult {
+ node: Some(node.clone()),
+ exact: false,
+ redirect: true,
+ };
+
+ assert!(format!("{some_redirect}").contains(node_id));
+ assert!(!format!("{some_redirect}").contains("No Match"));
+ assert!(format!("{some_redirect}").contains("redirect"));
+ assert!(!format!("{some_redirect}").contains("exact"));
+
+ let some_exact_redirect = QueryResult {
+ node: Some(node.clone()),
+ exact: true,
+ redirect: true,
+ };
+
+ assert!(format!("{some_exact_redirect}").contains(node_id));
+ assert!(!format!("{some_exact_redirect}").contains("No Match"));
+ assert!(format!("{some_exact_redirect}").contains("redirect"));
+ assert!(format!("{some_exact_redirect}").contains("exact"));
+
+ let none_exact_redirect = QueryResult {
+ node: None,
+ exact: true,
+ redirect: true,
+ };
+
+ assert!(!format!("{none_exact_redirect}").contains(node_id));
+ assert!(format!("{none_exact_redirect}").contains("No Match"));
+ assert!(format!("{none_exact_redirect}").contains("redirect"));
+ assert!(format!("{none_exact_redirect}").contains("exact"));
+
+ let none = QueryResult {
+ node: None,
+ exact: false,
+ redirect: false,
+ };
+
+ assert!(!format!("{none}").contains(node_id));
+ assert!(format!("{none}").contains("No Match"));
+ assert!(!format!("{none}").contains("redirect"));
+ assert!(!format!("{none}").contains("exact"));
+
+ let some = QueryResult {
+ node: Some(node),
+ exact: false,
+ redirect: false,
+ };
+
+ assert!(format!("{some}").contains(node_id));
+ assert!(!format!("{some}").contains("No Match"));
+ assert!(!format!("{some}").contains("redirect"));
+ assert!(!format!("{some}").contains("exact"));
+ }
}
#[cfg(test)]
+#[expect(clippy::panic_in_result_fn)]
mod serial_tests {
use super::*;
+ use crate::dev::test::{Directories, Error};
#[test]
- fn bad_graph_path() {
- let original_working_directory = std::env::current_dir().unwrap();
-
- assert!(
- std::env::set_current_dir(std::path::Path::new(
- "tests/mocks/no_graph"
- ))
- .is_ok()
- );
+ fn no_graph_fallback() -> Result<(), Error> {
+ let _dirs = Directories::setup("bad_graph_path")?;
let graph = Graph::load();
- let message = graph.meta.messages.first().unwrap();
- assert!(message.contains("Failed reading file at"));
+ assert_eq!(graph.nodes["GettingStarted"].title, "Getting Started");
- assert!(std::env::set_current_dir(original_working_directory).is_ok());
+ Ok(())
}
}
diff --git a/src/graph/edge.rs b/src/graph/edge.rs
index e95e45c..1c34bca 100644
--- a/src/graph/edge.rs
+++ b/src/graph/edge.rs
@@ -1,7 +1,8 @@
-use serde::{Serialize, Deserialize};
+use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
pub struct Edge {
+ #[serde(default)]
pub to: String,
#[serde(default)]
pub from: String,
diff --git a/src/graph/meta.rs b/src/graph/meta.rs
index bea1b2b..4d4f56e 100644
--- a/src/graph/meta.rs
+++ b/src/graph/meta.rs
@@ -1,10 +1,12 @@
-use serde::{Serialize, Deserialize};
+use serde::{Deserialize, Serialize};
+
+use crate::prelude::*;
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
pub struct Meta {
pub config: Config,
#[serde(default)]
- pub version: Option,
+ pub version: Version,
#[serde(default)]
pub messages: Vec,
#[serde(default)]
@@ -15,7 +17,7 @@ impl Default for Meta {
fn default() -> Meta {
Meta {
config: Config::default(),
- version: Version::from_env(),
+ version: Version::from_compilation().unwrap_or_default(),
messages: vec![],
malformed: false,
}
@@ -42,6 +44,8 @@ pub struct Config {
pub footer_credits: bool,
#[serde(default = "mktrue")]
pub footer_date: bool,
+ #[serde(default = "mktrue")]
+ pub footer_version: bool,
#[serde(default)]
pub footer_text: String,
#[serde(default = "mk8")]
@@ -62,6 +66,8 @@ pub struct Config {
pub raw_json: bool,
#[serde(default = "mktrue")]
pub raw_toml: bool,
+ #[serde(default = "mktrue")]
+ pub serve_fonts: bool,
#[serde(default)]
pub site_description: String,
#[serde(default)]
@@ -84,6 +90,7 @@ impl Default for Config {
footer: true,
footer_credits: true,
footer_date: true,
+ footer_version: true,
footer_text: String::default(),
index_node_count: 8,
index_node_list: true,
@@ -94,6 +101,7 @@ impl Default for Config {
raw: true,
raw_json: true,
raw_toml: true,
+ serve_fonts: true,
site_description: String::default(),
site_title: String::default(),
tree: true,
@@ -103,21 +111,234 @@ impl Default for Config {
}
// See: https://github.com/serde-rs/serde/issues/368
-fn mktrue() -> bool {
- true
+const fn mktrue() -> bool { true }
+const fn mkfalse() -> bool { false }
+const fn mk8() -> u16 { 8 }
+
+#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
+pub struct Version {
+ major: u8,
+ minor: u8,
+ patch: u8,
+ qualifier: Option,
}
-fn mkfalse() -> bool {
- false
+
+impl Default for Version {
+ fn default() -> Version {
+ match Version::from_compilation() {
+ Ok(v) => v,
+ Err(e) => {
+ log!(ERROR, "{e}");
+ Version {
+ major: 0,
+ minor: 0,
+ patch: 0,
+ qualifier: None,
+ }
+ },
+ }
+ }
}
-fn mk8() -> u16 {
- 8
+
+impl std::fmt::Display for Version {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ if let Some(qualifier) = &self.qualifier {
+ write!(
+ f,
+ "{}.{}.{}-{qualifier}",
+ self.major, self.minor, self.patch
+ )
+ } else {
+ write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
+ }
+ }
+}
+
+impl Version {
+ /// Parses the compile-time version into a Version struct.
+ ///
+ /// # Errors
+ /// This function is a thin wrapper around `Meta::from_text` and will
+ /// return its errors without change.
+ pub fn from_compilation() -> Result {
+ Version::from_text(env!("CARGO_PKG_VERSION"))
+ }
+
+ /// Parses a string into a Version struct.
+ ///
+ /// It is expected for the version string to contain exactly three
+ /// dot-separated numeric values with an optional leading `v` character.
+ ///
+ /// # Errors
+ /// Will error if the version string is malformed.
+ pub fn from_text(version: &str) -> Result {
+ use VersionErrorCause::*;
+
+ let triple: Vec =
+ version.split('.').map(str::to_string).collect();
+
+ let has_two_dots = version.matches('.').count() == 2;
+ let has_three_elements = triple.len() == 3;
+ let has_whitespace = version.contains(' ') || version.contains('\n');
+ let has_contiguous_dots = version.contains("..");
+ let ends_with_dot = version.ends_with('.');
+ let starts_with_dot = version.starts_with('.');
+
+ let major: u8 = if let Some(s) = triple.first()
+ && !s.is_empty()
+ {
+ match s.trim_start_matches('v').trim().parse() {
+ Ok(parsed) => parsed,
+ Err(e) => {
+ return Err(VersionError {
+ cause: FailedMajorParse,
+ message: Some(e.to_string()),
+ });
+ },
+ }
+ } else {
+ return Err(VersionError {
+ cause: MissingMajor,
+ message: None,
+ });
+ };
+
+ let minor: u8 = if triple.len() >= 2
+ && let Some(s) = triple.get(1)
+ {
+ match s.trim().parse() {
+ Ok(parsed) => parsed,
+ Err(e) => {
+ return Err(VersionError {
+ cause: FailedMinorParse,
+ message: Some(e.to_string()),
+ });
+ },
+ }
+ } else {
+ return Err(VersionError {
+ cause: MissingMinor,
+ message: None,
+ });
+ };
+
+ let patch: u8 = if triple.len() >= 3
+ && let Some(s) = triple.get(2)
+ {
+ let patch_number = if let Some(split) = s.split_once('-') {
+ split.0
+ } else {
+ s
+ };
+
+ match patch_number.trim().parse() {
+ Ok(parsed) => parsed,
+ Err(e) => {
+ return Err(VersionError {
+ cause: FailedPatchParse,
+ message: Some(e.to_string()),
+ });
+ },
+ }
+ } else {
+ return Err(VersionError {
+ cause: MissingPatch,
+ message: None,
+ });
+ };
+
+ let qualifier: Option = if let Some(tail) = triple.get(2) {
+ tail.split_once('-').map(|split| String::from(split.1))
+ } else {
+ None
+ };
+
+ let conditions = has_two_dots
+ && has_three_elements
+ && !has_whitespace
+ && !has_contiguous_dots
+ && !ends_with_dot
+ && !starts_with_dot;
+
+ if conditions {
+ Ok(Version {
+ major,
+ minor,
+ patch,
+ qualifier,
+ })
+ } else {
+ Err(VersionError {
+ cause: FailedValidation,
+ message: Some(format!(
+ "Evaluated rules (all must be true):\n\
+ Has exactly two dots: {has_two_dots},\n\
+ Splits to three elements: {has_three_elements}\n\
+ Has no whitespace: {}\n\
+ Has no contiguous dots: {}\n\
+ Does not end with a dot: {}\n\
+ Does not start with a dot: {}",
+ !has_whitespace,
+ !has_contiguous_dots,
+ !ends_with_dot,
+ !starts_with_dot,
+ )),
+ })
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct VersionError {
+ cause: VersionErrorCause,
+ message: Option,
+}
+
+#[derive(Debug)]
+enum VersionErrorCause {
+ MissingMajor,
+ FailedMajorParse,
+ MissingMinor,
+ FailedMinorParse,
+ MissingPatch,
+ FailedPatchParse,
+ FailedValidation,
+}
+
+impl std::fmt::Display for VersionError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ if let Some(message) = &self.message {
+ write!(f, "{}: {}", self.cause, message)
+ } else {
+ write!(f, "{}", self.cause)
+ }
+ }
+}
+
+impl std::fmt::Display for VersionErrorCause {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ use VersionErrorCause as V;
+
+ write!(
+ f,
+ "{}",
+ match self {
+ V::MissingMajor => "Major version couldn't be split",
+ V::FailedMajorParse => "Failed parse of major version",
+ V::MissingMinor => "Minor version couldn't be split",
+ V::FailedMinorParse => "Failed parse of minor version",
+ V::MissingPatch => "Patch version couldn't be split",
+ V::FailedPatchParse => "Failed parse of patch version",
+ V::FailedValidation => "Validation failed",
+ }
+ )
+ }
}
#[cfg(test)]
mod tests {
- use crate::graph::Graph;
-
use super::*;
+ use crate::graph::Graph;
#[test]
fn empty_footer_text() {
@@ -179,60 +400,208 @@ mod tests {
== 1
);
}
-}
-#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, Debug)]
-pub struct Version {
- major: u8,
- minor: u8,
- patch: u8,
-}
+ #[test]
+ fn modulated_graph_version_matches_compilation_version() {
+ let version = Graph::load().meta.version;
-impl Version {
- pub fn from_env() -> Option {
- Version::from(env!("CARGO_PKG_VERSION"))
+ assert_eq!(format!("{version}"), env!("CARGO_PKG_VERSION"));
}
- pub fn from(version: &str) -> Option {
- let triple: Vec =
- version.split('.').map(str::to_string).collect();
+ #[test]
+ fn from_compilation_matches_compilation_version() {
+ let version = Version::from_compilation().unwrap();
- let has_two_dots = version.matches('.').count() == 2;
- let has_three_elements = triple.len() == 3;
- let has_whitespace = version.contains(' ') || version.contains('\n');
- let has_contiguous_dots = version.contains("..");
- let ends_with_dot = version.ends_with('.');
- let starts_with_dot = version.starts_with('.');
+ assert_eq!(format!("{version}"), env!("CARGO_PKG_VERSION"));
+ }
- let major: u8 = if let Some(s) = triple.first() {
- s.trim_start_matches('v').trim().parse().ok()?
- } else {
- return None;
- };
+ #[test]
+ fn version_from_str() {
+ let payload = "3.9.74";
+ let version_result = Version::from_text(payload);
- let minor: u8 = if let Some(s) = triple.get(1) {
- s.trim().parse().ok()?
- } else {
- return None;
- };
+ println!("{version_result:#?}");
+ assert_eq!(format!("{}", version_result.unwrap()), payload);
+ }
- let patch: u8 = if let Some(s) = triple.get(2) {
- s.trim().parse().ok()?
- } else {
- return None;
- };
+ #[test]
+ fn missing_major() {
+ let error = Version::from_text("").unwrap_err();
+ println!("{error:#?}");
+ assert!(matches!(error.cause, VersionErrorCause::MissingMajor));
+ }
- let conditions = has_two_dots
- && has_three_elements
- && !has_whitespace
- && !has_contiguous_dots
- && !ends_with_dot
- && !starts_with_dot;
+ #[test]
+ fn missing_minor() {
+ let error = Version::from_text("3").unwrap_err();
+ println!("{error:#?}");
+ assert!(matches!(error.cause, VersionErrorCause::MissingMinor));
+ }
- conditions.then_some(Version {
- major,
- minor,
- patch,
- })
+ #[test]
+ fn missing_patch() {
+ let error = Version::from_text("3.6").unwrap_err();
+ assert!(matches!(error.cause, VersionErrorCause::MissingPatch));
+ }
+
+ #[test]
+ fn malformed_patch() {
+ let error = Version::from_text("3.6.x").unwrap_err();
+ assert!(matches!(error.cause, VersionErrorCause::FailedPatchParse));
+
+ let error_empty = Version::from_text("3.6.").unwrap_err();
+ assert!(matches!(
+ error_empty.cause,
+ VersionErrorCause::FailedPatchParse
+ ));
+ }
+
+ #[test]
+ fn malformed_minor() {
+ let error = Version::from_text("3.x.0").unwrap_err();
+ assert!(matches!(error.cause, VersionErrorCause::FailedMinorParse));
+
+ let error_bad_patch = Version::from_text("3.x.z").unwrap_err();
+ assert!(matches!(
+ error_bad_patch.cause,
+ VersionErrorCause::FailedMinorParse
+ ));
+
+ let error_empty_patch = Version::from_text("3.x.").unwrap_err();
+ assert!(matches!(
+ error_empty_patch.cause,
+ VersionErrorCause::FailedMinorParse
+ ));
+
+ let error_patchless = Version::from_text("3.x").unwrap_err();
+ assert!(matches!(
+ error_patchless.cause,
+ VersionErrorCause::FailedMinorParse
+ ));
+
+ let error_empty = Version::from_text("3.").unwrap_err();
+ assert!(matches!(
+ error_empty.cause,
+ VersionErrorCause::FailedMinorParse
+ ));
+ }
+
+ #[test]
+ fn malformed_major() {
+ let error = Version::from_text("x.6.0").unwrap_err();
+ assert!(matches!(error.cause, VersionErrorCause::FailedMajorParse));
+
+ let error_bad_patch = Version::from_text("x.y.z").unwrap_err();
+ assert!(matches!(
+ error_bad_patch.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_empty_patch = Version::from_text("x.6.").unwrap_err();
+ assert!(matches!(
+ error_empty_patch.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_patchless = Version::from_text("x.6").unwrap_err();
+ assert!(matches!(
+ error_patchless.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_bad_minor = Version::from_text("x.y").unwrap_err();
+ assert!(matches!(
+ error_bad_minor.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_empty_minor = Version::from_text("x.").unwrap_err();
+ assert!(matches!(
+ error_empty_minor.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_minorless = Version::from_text("x").unwrap_err();
+ assert!(matches!(
+ error_minorless.cause,
+ VersionErrorCause::FailedMajorParse
+ ));
+
+ let error_empty = Version::from_text("").unwrap_err();
+ assert!(matches!(error_empty.cause, VersionErrorCause::MissingMajor));
+ }
+
+ #[test]
+ fn version_validation() {
+ assert!(["3.1.4.", "3.1.4.1"].iter().all(|s| matches!(
+ Version::from_text(s).unwrap_err().cause,
+ VersionErrorCause::FailedValidation
+ )));
+ }
+
+ #[test]
+ fn leading_v() {
+ let version = Version::from_text("v3.1.4").unwrap();
+ assert_eq!(format!("{version}"), "3.1.4");
+ }
+
+ #[test]
+ fn display_version_error_cause() {
+ fn assert(version: &str, message: &str) {
+ let error = Version::from_text(version).unwrap_err();
+ assert_eq!(format!("{error}"), message);
+ }
+
+ assert("3.6", "Patch version couldn't be split");
+ assert(
+ "3.6.",
+ "Failed parse of patch version: \
+ cannot parse integer from empty string",
+ );
+ assert(
+ "3.6.x",
+ "Failed parse of patch version: \
+ invalid digit found in string",
+ );
+
+ assert("3", "Minor version couldn't be split");
+ assert(
+ "3.",
+ "Failed parse of minor version: \
+ cannot parse integer from empty string",
+ );
+ assert(
+ "3.x",
+ "Failed parse of minor version: \
+ invalid digit found in string",
+ );
+
+ assert("", "Major version couldn't be split");
+ assert(
+ "x",
+ "Failed parse of major version: \
+ invalid digit found in string",
+ );
+
+ let validation_error = Version::from_text("3.1.4.1..").unwrap_err();
+ println!("{validation_error}");
+
+ assert!(matches!(
+ validation_error.cause,
+ VersionErrorCause::FailedValidation
+ ));
+ assert!(
+ validation_error
+ .message
+ .clone()
+ .unwrap()
+ .contains("Has exactly two dots: false")
+ );
+ assert!(
+ validation_error
+ .message
+ .unwrap()
+ .contains("Splits to three elements: false")
+ );
}
}
diff --git a/src/graph/node.rs b/src/graph/node.rs
index 6d2071f..3472641 100644
--- a/src/graph/node.rs
+++ b/src/graph/node.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use serde::{Serialize, Deserialize};
+use serde::{Deserialize, Serialize};
use super::edge::Edge;
@@ -18,16 +18,19 @@ pub struct Node {
pub links: Vec,
#[serde(default)]
pub redirect: String,
- #[serde(default)]
- pub hidden: bool,
+ #[serde(default = "mktrue")]
+ pub listed: bool,
- #[serde(skip_serializing_if = "Option::is_none")]
- pub connections: Option>,
+ #[serde(default)]
+ pub connections: HashMap,
#[serde(default)]
pub stats: Stats,
}
+// See: https://github.com/serde-rs/serde/issues/368
+const fn mktrue() -> bool { true }
+
#[derive(Serialize, Deserialize, Clone, Default, Eq, PartialEq, Debug)]
pub struct Stats {
pub outgoing: u32,
@@ -35,7 +38,7 @@ pub struct Stats {
}
impl Node {
- pub fn new(message: Option) -> Node {
+ pub fn not_found(message: Option) -> Node {
Node {
id: "404".to_string(),
title: "Not Found".to_string(),
@@ -43,10 +46,10 @@ impl Node {
Some(s) => s,
None => "Node not found.".to_string(),
},
- connections: None,
+ connections: HashMap::default(),
links: vec![],
redirect: String::default(),
- hidden: false,
+ listed: true,
summary: String::default(),
stats: Stats::default(),
}
@@ -55,35 +58,36 @@ impl Node {
impl std::fmt::Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- let mut meta = String::default();
- if self.title.is_empty() {
- meta.push_str("title:none");
- } else {
- meta.push_str(&format!("title:'{}'", self.title));
+ let mut meta_elements: Vec = vec![];
+
+ if !self.title.is_empty() {
+ meta_elements.push(format!("title:'{}'", self.title));
}
- if self.text.is_empty() {
- meta.push_str(" text:none");
- } else {
- meta.push_str(&format!(" text:{}l", self.text.len()));
+
+ if !self.text.is_empty() {
+ meta_elements.push(format!("text:{}l", self.text.len()));
}
- if self.summary.is_empty() {
- meta.push_str(" summary:none");
- } else {
- meta.push_str(&format!(" summary:{}", self.summary.len()));
+
+ if !self.summary.is_empty() {
+ meta_elements.push(format!("summary:{}", self.summary.len()));
}
- if self.redirect.is_empty() {
- meta.push_str(" redirect:none");
- } else {
- meta.push_str(&format!(" redirect:{}", self.redirect));
+
+ if !self.redirect.is_empty() {
+ meta_elements.push(format!("redirect:{}", self.redirect));
}
+
let links = self.links.len();
if links > 0 {
- meta.push_str(&format!(" links:{links}"));
+ meta_elements.push(format!("links:{links}"));
}
- if self.hidden {
- meta.push_str(" hidden");
+
+ if !self.listed {
+ meta_elements.push(String::from("unlisted"));
}
- write!(f, "Node: ID '{}' {meta}", self.id)
+
+ let meta = meta_elements.join(" ");
+
+ write!(f, "Node {} [{meta}]", self.id)
}
}
@@ -93,7 +97,70 @@ mod tests {
#[test]
fn empty_node_message() {
- let node = Node::new(None);
+ let node = Node::not_found(None);
assert_eq!(node.text, "Node not found.");
}
+
+ #[test]
+ fn display() {
+ let mut node = Node::not_found(None);
+ assert_eq!(format!("{node}"), "Node 404 [title:'Not Found' text:15l]");
+
+ let summary = "X2hSwanDoLdqLZNnYJagcWKFJVAx5TGF";
+ node.summary = String::from(summary);
+ assert_eq!(
+ format!("{node}"),
+ format!(
+ "Node 404 [title:'Not Found' text:15l summary:{}]",
+ summary.len()
+ )
+ );
+
+ let redirect = "ukfF3kz130oUzT2ushBIvEHx8xoY8ke0";
+ node.redirect = String::from(redirect);
+ assert_eq!(
+ format!("{node}"),
+ format!(
+ "Node 404 [title:'Not Found' \
+ text:15l summary:{} \
+ redirect:{redirect}]",
+ summary.len(),
+ )
+ );
+
+ node.links.push(String::from("1"));
+ node.links.push(String::from("2"));
+ node.links.push(String::from("3"));
+
+ assert_eq!(
+ format!("{node}"),
+ format!(
+ "Node 404 [\
+ title:'Not Found' \
+ text:15l summary:{} \
+ redirect:{redirect} \
+ links:{}\
+ ]",
+ summary.len(),
+ node.links.len(),
+ )
+ );
+
+ node.listed = false;
+
+ assert_eq!(
+ format!("{node}"),
+ format!(
+ "Node 404 [\
+ title:'Not Found' \
+ text:15l summary:{} \
+ redirect:{redirect} \
+ links:{} \
+ unlisted\
+ ]",
+ summary.len(),
+ node.links.len(),
+ )
+ );
+ }
}
diff --git a/src/lib.rs b/src/lib.rs
index 2a71d03..6d9c62a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,16 +1,16 @@
use std::{sync, time};
pub mod prelude {
- pub use crate::log;
- pub use crate::tlog;
- pub use crate::log::Level::*;
- pub use crate::log::now;
+ pub use crate::{
+ dev::log::{Level::*, now},
+ log, tlog, write_log,
+ };
}
+pub mod dev;
pub mod graph;
pub mod router;
pub mod syntax;
-pub mod log;
pub static ONSET: sync::LazyLock =
sync::LazyLock::new(time::Instant::now);
diff --git a/src/log/level.rs b/src/log/level.rs
deleted file mode 100644
index c5054c1..0000000
--- a/src/log/level.rs
+++ /dev/null
@@ -1,105 +0,0 @@
-#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
-#[repr(u16)]
-pub enum Level {
- SILENT = 0,
- FATAL = 1,
- ERROR = 2,
- WARN = 3,
- INFO = 4,
- DEBUG = 5,
- VERBOSE = 6,
- TRACE = 7,
- META = 37,
-}
-
-pub const ENV_DEFAULT: Level = Level::WARN;
-pub const MESSAGE_DEFAULT: Level = Level::DEBUG;
-
-impl From for u16 {
- fn from(level: Level) -> u16 {
- match level {
- Level::SILENT => 0,
- Level::FATAL => 1,
- Level::ERROR => 2,
- Level::WARN => 3,
- Level::INFO => 4,
- Level::DEBUG => 5,
- Level::VERBOSE => 6,
- Level::TRACE => 7,
- Level::META => 37,
- }
- }
-}
-
-impl From for Level {
- fn from(numeric: u16) -> Level {
- if numeric == 0 {
- Level::SILENT
- } else if numeric == 1 {
- Level::FATAL
- } else if numeric == 2 {
- Level::ERROR
- } else if numeric == 3 {
- Level::WARN
- } else if numeric == 4 {
- Level::INFO
- } else if numeric == 5 {
- Level::DEBUG
- } else if numeric == 6 {
- Level::VERBOSE
- } else if numeric == 7 {
- Level::TRACE
- } else if numeric == 37 {
- Level::META
- } else {
- super::ENV_DEFAULT
- }
- }
-}
-
-impl From<&str> for Level {
- fn from(s: &str) -> Level {
- if s == "0" || s == "SILENT" || s == "silent" {
- Level::SILENT
- } else if s == "1" || s == "FATAL" || s == "fatal" {
- Level::FATAL
- } else if s == "2" || s == "ERROR" || s == "error" {
- Level::ERROR
- } else if s == "3"
- || s == "WARN"
- || s == "warn"
- || s == "WARNING"
- || s == "warning"
- {
- Level::WARN
- } else if s == "4" || s == "INFO" || s == "info" {
- Level::INFO
- } else if s == "5" || s == "DEBUG" || s == "debug" {
- Level::DEBUG
- } else if s == "6" || s == "VERBOSE" || s == "verbose" {
- Level::VERBOSE
- } else if s == "7" || s == "TRACE" || s == "trace" {
- Level::TRACE
- } else if s == "37" || s == "META" || s == "meta" {
- Level::META
- } else {
- super::ENV_DEFAULT
- }
- }
-}
-impl std::fmt::Display for Level {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- let s = match self {
- Level::SILENT => "SILENT",
- Level::FATAL => "FATAL",
- Level::ERROR => "ERROR",
- Level::WARN => "WARNING",
- Level::INFO => "INFO",
- Level::DEBUG => "DEBUG",
- Level::VERBOSE => "VERBOSE",
- Level::TRACE => "TRACE",
- Level::META => "META",
- };
- write!(f, "{s}")
- }
-}
diff --git a/src/main.rs b/src/main.rs
index b23dc2d..9382190 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,17 +1,12 @@
use std::{backtrace, io, panic};
-use en::{ONSET, graph::Graph, log, prelude::*, syntax};
+use en::{ONSET, dev::log, graph::Graph, prelude::*, syntax};
#[tokio::main]
-#[allow(clippy::print_stderr, clippy::print_stdout)]
+#[expect(clippy::print_stderr, clippy::print_stdout, clippy::use_debug)]
async fn main() -> io::Result<()> {
- log::print_state();
let mut instant = now();
- let args = syntax::command::Arguments::default().parse();
- let address = args.make_address();
- instant = tlog!(&instant, "Parsed CLI arguments");
-
panic::set_hook(Box::new(|info| {
let payload = info
.payload_as_str()
@@ -37,12 +32,23 @@ async fn main() -> io::Result<()> {
}));
instant = tlog!(&instant, "Set up panic hook");
+ let args = syntax::command::Arguments::default().parse();
+ instant = tlog!(&instant, "Parsed CLI arguments");
+
+ if args.flags.version {
+ println!(env!("CARGO_PKG_VERSION"));
+ return Ok(());
+ }
+
+ log::print_state();
+
let graph = Graph::load();
instant = tlog!(&instant, "Loaded graph");
let router = en::router::new(graph);
tlog!(&instant, "Initialized router");
+ let address = args.make_address();
let listener =
tokio::net::TcpListener::bind(&address).await.map_err(|e| {
log!(ERROR, "Failed to create listener at {address}: {e:#?}");
diff --git a/src/router.rs b/src/router.rs
index 4617e47..1df5b78 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -3,13 +3,13 @@ use axum::{Router, routing::get};
use crate::graph::Graph;
mod handlers {
- pub mod graph;
- pub mod template;
- pub mod raw;
- pub mod navigation;
- pub mod fixed;
pub mod error;
+ pub mod fixed;
+ pub mod graph;
pub mod mime;
+ pub mod navigation;
+ pub mod raw;
+ pub mod template;
}
#[derive(Clone)]
@@ -33,7 +33,8 @@ pub fn new(graph: Graph) -> Router {
.route("/graph/{format}", get(handlers::fixed::serial))
.route("/search", get(handlers::navigation::search))
.route("/redirect", get(handlers::navigation::redirect))
- .route("/static/{*path}", get(handlers::fixed::file));
+ .route("/static/{*path}", get(handlers::fixed::file))
+ .route("/legal", get(handlers::navigation::legal));
if state.graph.meta.config.tree {
router = router.route("/tree", get(handlers::navigation::tree));
@@ -49,11 +50,6 @@ pub fn new(graph: Graph) -> Router {
#[cfg(test)]
mod tests {
- use crate::{
- graph::{Graph, Config, Meta},
- };
-
- use super::*;
use axum::{
body::Body,
http::{Request, StatusCode},
@@ -61,6 +57,9 @@ mod tests {
};
use tower::ServiceExt as _;
+ use super::*;
+ use crate::graph::{Config, Graph, Meta};
+
async fn request(uri: &str, config: Option<&Config>) -> Response {
let default_graph = Graph::load();
let graph = Graph {
diff --git a/src/router/handlers/error.rs b/src/router/handlers/error.rs
index 5367f8b..7698a50 100644
--- a/src/router/handlers/error.rs
+++ b/src/router/handlers/error.rs
@@ -9,7 +9,7 @@ use crate::{
router::{GlobalState, handlers},
};
-pub(in crate::router::handlers) fn by_code(
+pub(in crate::router::handlers) fn make(
code: Option,
message: Option<&str>,
graph: &Graph,
@@ -47,19 +47,21 @@ fn make_body(
context.insert("message", out_message);
context.insert("status_code", &out_code.to_string());
- handlers::template::render(
+ match handlers::template::render(
"error",
&context,
Some(&format!(
"Failed to render template for Error {out_code}: {out_message}"
))
.cloned(),
- )
- .0
+ ) {
+ Ok(rendered) => rendered.html,
+ Err(error) => error.template.html,
+ }
}
pub async fn not_found(State(state): State) -> Response {
- by_code(
+ make(
Some(404),
Some("The page you tried to access could not be found."),
&state.graph,
@@ -68,10 +70,8 @@ pub async fn not_found(State(state): State) -> Response {
#[cfg(test)]
mod tests {
- use axum::{
- http::{StatusCode},
- extract::State,
- };
+ use axum::{extract::State, http::StatusCode};
+
use super::*;
#[tokio::test]
@@ -86,10 +86,10 @@ mod tests {
#[tokio::test]
async fn internal_error() {
let graph = Graph::load();
- assert!(by_code(Some(201), None, &graph).status() == 201);
- assert!(by_code(Some(304), None, &graph).status() == 304);
- assert!(by_code(Some(418), None, &graph).status() == 418);
- assert!(by_code(Some(505), None, &graph).status() == 505);
+ assert!(make(Some(201), None, &graph).status() == 201);
+ assert!(make(Some(304), None, &graph).status() == 304);
+ assert!(make(Some(418), None, &graph).status() == 418);
+ assert!(make(Some(505), None, &graph).status() == 505);
}
#[test]
diff --git a/src/router/handlers/fixed.rs b/src/router/handlers/fixed.rs
index 3d4d4be..bf905ed 100644
--- a/src/router/handlers/fixed.rs
+++ b/src/router/handlers/fixed.rs
@@ -1,66 +1,311 @@
+use std::{collections::HashMap, io::ErrorKind, string::FromUtf8Error};
+
use axum::{
- http::{HeaderValue, Response, StatusCode, header},
- {
- body::Body,
- extract::{Path, State},
+ body::Body,
+ extract::{Path, State},
+ http::{HeaderValue, Response, header},
+};
+use serde::Serialize;
+
+use crate::{
+ dev::log,
+ graph::{Format, Graph, SerialErrorCause},
+ prelude::*,
+ router::{
+ GlobalState,
+ handlers::{self, error, mime},
},
};
-use crate::prelude::*;
-use crate::{
- graph::{Format, Graph, SerialErrorCause},
- router::{GlobalState, handlers},
- router::handlers::mime::Mime,
-};
+/// Assembles an HTTP response given Asset.
+fn assemble(asset: Asset, graph: &Graph) -> Response {
+ let set_content_type = |response: &mut Response<_>, content_type: &str| {
+ if let Ok(header_value) =
+ HeaderValue::from_str(&String::from(content_type))
+ {
+ response
+ .headers_mut()
+ .append(header::CONTENT_TYPE, header_value);
+ } else {
+ // This should be unreachable considering the possible mimetypes
+ // and their string representations are internal to en
+ log!(
+ WARN,
+ "Failed to create content type header value from {content_type}"
+ );
+ }
+ };
+ match asset.mime.kind() {
+ mime::Kind::Text => {
+ if let Some(text) = asset.text {
+ let mut response = Response::new(Body::from(text));
+ set_content_type(
+ &mut response,
+ &String::from(asset.mime.clone()),
+ );
+ response
+ } else {
+ // This should be unreachable, considering the constructors
+ // will convert to text even if a blob is passed
+ let mut response = error::make(
+ Some(500),
+ Some(
+ "Asset mimetype indicates text content, \
+ but none was found",
+ ),
+ graph,
+ );
+ set_content_type(&mut response, "text/html");
+ response
+ }
+ },
+ mime::Kind::Font | mime::Kind::Blob | mime::Kind::Image => {
+ if let Some(blob) = asset.blob {
+ let mut response = Response::new(Body::from(blob));
+ set_content_type(
+ &mut response,
+ &String::from(asset.mime.clone()),
+ );
+ response
+ } else {
+ // This should be unreachable, considering the constructors
+ // will convert to blob even if a text is passed
+ let mut response = error::make(
+ Some(500),
+ Some(
+ "Asset mimetype indicates binary content, \
+ but none was found",
+ ),
+ graph,
+ );
+ set_content_type(&mut response, "text/html");
+ response
+ }
+ },
+ }
+}
+
+#[derive(Debug)]
+#[expect(clippy::upper_case_acronyms)]
+pub enum AssetErrorKind {
+ NotFound,
+ IO,
+ UTF8,
+ Unknown,
+}
+
+#[derive(Debug)]
+pub struct AssetError {
+ pub path: String,
+ pub kind: AssetErrorKind,
+ pub io_error: Option,
+ pub utf8_error: Option,
+}
+
+impl AssetError {
+ fn new(
+ path: &str,
+ kind: AssetErrorKind,
+ io_error: Option,
+ utf8_error: Option,
+ ) -> AssetError {
+ AssetError {
+ path: String::from(path),
+ kind,
+ io_error,
+ utf8_error,
+ }
+ }
+}
+
+impl From for AssetError {
+ fn from(error: FromUtf8Error) -> AssetError {
+ AssetError::new("", AssetErrorKind::UTF8, None, Some(error))
+ }
+}
+
+impl From for AssetError {
+ fn from(string: String) -> AssetError {
+ AssetError::new(&string, AssetErrorKind::Unknown, None, None)
+ }
+}
+
+impl std::fmt::Display for AssetError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let mut message = match self.kind {
+ AssetErrorKind::IO => {
+ format!(
+ "File {} was found, but it could not be loaded",
+ self.path
+ )
+ },
+ AssetErrorKind::NotFound => {
+ String::from("The file was not found in the searched path")
+ },
+ AssetErrorKind::UTF8 => String::from(
+ "UTF8 decoding error: is the file properly encoded?",
+ ),
+ AssetErrorKind::Unknown => {
+ String::from("An unknown error happened.")
+ },
+ };
+
+ if let Some(error) = &self.io_error {
+ message = format!(
+ "{message}\n\
+ The following I/O error has happened: \n{error:?}"
+ );
+ }
+
+ if let Some(error) = &self.utf8_error {
+ message = format!(
+ "{message}\n\
+ The following encoding error has happened: \n{error:?}"
+ );
+ }
+
+ write!(f, "{message}")
+ }
+}
+
+#[derive(Debug)]
+struct Asset {
+ blob: Option>,
+ text: Option,
+ mime: mime::Mime,
+}
+
+impl Asset {
+ fn new(blob: &[u8], mime: mime::Mime) -> Result {
+ match mime.kind() {
+ mime::Kind::Text => Ok(Asset {
+ text: Some(String::from_utf8(blob.to_vec())?),
+ blob: None,
+ mime,
+ }),
+ mime::Kind::Font | mime::Kind::Image | mime::Kind::Blob => {
+ Ok(Asset {
+ text: None,
+ blob: Some(blob.to_vec()),
+ mime,
+ })
+ },
+ }
+ }
+
+ fn from_str(str: &str, mime: mime::Mime) -> Asset {
+ match mime.kind() {
+ mime::Kind::Text => Asset {
+ text: Some(String::from(str)),
+ blob: None,
+ mime,
+ },
+ mime::Kind::Font | mime::Kind::Image | mime::Kind::Blob => Asset {
+ text: None,
+ blob: Some(String::from(str).into_bytes()),
+ mime,
+ },
+ }
+ }
+}
+
+/// Given a relative path, returns the file contents or a default fallback.
+///
+/// The `path` argument is relative to the `static/public` directory.
+///
+/// Defaults are found in the `fixed::DEFAULTS` map.
+///
+/// Returns a `FallbackError` if neither is found or an I/O error occurred.
+fn fallback(path: &str, graph: &Graph) -> Result {
+ let target = format!("static/public/assets/{path}");
+ let defaults: HashMap<&str, &str> = TEXTS.iter().copied().collect();
+ let fonts: HashMap<&str, &'static Font> = FONTS.iter().copied().collect();
+ let mime = mime::Mime::guess(path);
+
+ match std::fs::read(&target) {
+ // A matching file exists on disk and is accessible
+ Ok(content) => Ok(Asset {
+ blob: Some(content),
+ text: None,
+ mime,
+ }),
+ Err(io_error) => {
+ // A matching file does not exist on disk
+ if io_error.kind() == ErrorKind::NotFound {
+ if let Some(content) = defaults.get(path) {
+ Ok(Asset::from_str(content, mime))
+ } else {
+ let not_found_error = Err(AssetError::new(
+ path,
+ AssetErrorKind::NotFound,
+ Some(io_error),
+ None,
+ ));
+
+ if !graph.meta.config.serve_fonts {
+ return not_found_error
+ }
+
+ match fonts.get(path) {
+ // A matching font exists
+ Some(content) => Asset::new(content.blob, mime),
+ None => not_found_error,
+ }
+ }
+ // A matching file exists on disk and is not accessible
+ } else {
+ Err(AssetError::new(
+ path,
+ AssetErrorKind::IO,
+ Some(io_error),
+ None,
+ ))
+ }
+ },
+ }
+}
+
+/// Handles requests for static files.
+///
+/// This handler receives and extracts requests from `/static/{path}`.
pub async fn file(
Path(path): Path,
State(state): State,
) -> Response {
let instant = now();
- let target = format!("static/public/{path}");
- let content = match std::fs::read(&target) {
- Ok(s) => s,
- Err(e) => {
- let mut error_message = String::from(
- "The requested file does not exist, the server does not have \
- permission to access it or a filesystem error ocurred.",
+
+ match fallback(&path, &state.graph) {
+ Ok(asset) => {
+ let response = assemble(asset, &state.graph);
+ tlog!(
+ &instant,
+ "Assembled {} response for {path}",
+ response.status()
);
+ response
+ },
+ Err(asset_error) => {
+ let mut error_message =
+ if matches!(asset_error.kind, AssetErrorKind::NotFound) {
+ String::from("The requested file was not found.")
+ } else {
+ String::from(
+ "The requested file exists, but the server lacks \
+ permission to access it or another I/O error occurred.",
+ )
+ };
if log::env_level() >= DEBUG {
error_message = format!(
"{error_message}
\
- Targeted path: {target}
\
- Error message:
{e} "
+ Targeted path: {path}
\
+ Error:
{asset_error} "
);
}
log!(ERROR, "{error_message}");
- return super::error::by_code(
- Some(404),
- Some(&error_message),
- &state.graph,
- );
+ error::make(Some(404), Some(&error_message), &state.graph)
},
- };
-
- let mut response = Response::new(Body::from(content));
- *response.status_mut() = StatusCode::OK;
- let header = header::CONTENT_TYPE;
-
- let content_type = Mime::guess(&path);
-
- if let Ok(header_value) =
- HeaderValue::from_str(&String::from(content_type.clone()))
- {
- response.headers_mut().append(header, header_value);
- } else {
- log!(
- WARN,
- "Failed to create content type header value from {content_type:?}"
- );
}
-
- tlog!(&instant, "Assembled response for {content_type:?} {path}");
- response
}
pub async fn serial(
@@ -70,7 +315,7 @@ pub async fn serial(
let config = &state.graph.meta.config;
let make_error = |code: u16, message: &str| -> Response {
- handlers::error::by_code(
+ handlers::error::make(
Some(code),
Some(
format!(
@@ -128,9 +373,258 @@ pub async fn serial(
}
}
+static TEXTS: &[(&str, &str)] = &[
+ (
+ "assets/style.css",
+ include_str!("../../../static/public/assets/style.css"),
+ ),
+ (
+ "assets/fonts/fonts.css",
+ include_str!("../../../static/public/assets/fonts/fonts.css"),
+ ),
+ (
+ "assets/favicon.svg",
+ include_str!("../../../static/public/assets/favicon.svg"),
+ ),
+];
+
+pub static FONTS: &[(&str, &Font)] = &[
+ (
+ "assets/fonts/cormorant/cormorant-infant-latin-300-normal.woff2",
+ &Font {
+ name: "Cormorant Infant",
+ attribution: &Attribution {
+ project_name: "Cormorant",
+ author: "Christian Thalmann",
+ project_url: "https://github.com/CatharsisFonts/Cormorant",
+ author_url: "https://github.com/CatharsisFonts",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ cormorant/header.LICENSE"
+ ),
+ },
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ cormorant/cormorant-infant-latin-300-normal.woff2"
+ ),
+ license: &OFL,
+ },
+ ),
+ (
+ "assets/fonts/cormorant/cormorant-infant-latin-300-italic.woff2",
+ &Font {
+ name: "Cormorant Infant Italic",
+ attribution: &Attribution {
+ project_name: "Cormorant",
+ author: "Christian Thalmann",
+ project_url: "https://github.com/CatharsisFonts/Cormorant",
+ author_url: "https://github.com/CatharsisFonts",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ cormorant/header.LICENSE"
+ ),
+ },
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ cormorant/cormorant-infant-latin-300-italic.woff2"
+ ),
+ license: &OFL,
+ },
+ ),
+ (
+ "assets/fonts/maven/maven-pro-latin-400-normal.woff2",
+ &Font {
+ name: "Maven Pro",
+ attribution: &Attribution {
+ project_name: "Maven",
+ author: "Joe Prince and Project Authors",
+ author_url: "https://github.com/m4rc1e/mavenproFont/blob/\
+ main/AUTHORS.txt",
+ project_url: "https://github.com/m4rc1e/mavenproFont",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ maven/header.LICENSE"
+ ),
+ },
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ maven/maven-pro-latin-400-normal.woff2"
+ ),
+ license: &OFL,
+ },
+ ),
+ (
+ "assets/fonts/mononoki/mononoki-latin-400-normal.woff2",
+ &Font {
+ name: "Mononoki",
+ attribution: &Attribution {
+ project_name: "Mononoki",
+ author: "Matthias Tellen",
+ author_url: "https://github.com/madmalik",
+ project_url: "https://madmalik.github.io/mononoki/",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ mononoki/header.LICENSE"
+ ),
+ },
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ mononoki/mononoki-latin-400-normal.woff2"
+ ),
+ license: &OFL,
+ },
+ ),
+ (
+ "assets/fonts/rawengulk/RawengulkLight.woff2",
+ &Font {
+ name: "Rawengulk Light",
+ attribution: &Attribution {
+ project_name: "Rawengulk",
+ author: "gluk Fonts",
+ author_url: "https://www.glukfonts.pl",
+ project_url: "https://www.glukfonts.pl/font.php?font=Rawengulk",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ rawengulk/header.LICENSE"
+ ),
+ },
+ license: &OFL,
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ rawengulk/RawengulkLight.woff2"
+ ),
+ },
+ ),
+ (
+ "assets/fonts/reforma/Reforma1969-Blanca.woff2",
+ &Font {
+ name: "Reforma 1969 Blanca",
+ attribution: &REFORMA_ATTRIBUTION,
+ license: &CCND,
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ reforma/Reforma1969-Blanca.woff2"
+ ),
+ },
+ ),
+ (
+ "assets/fonts/reforma/Reforma1969-BlancaItalica.woff2",
+ &Font {
+ name: "Reforma 1969 Blanca Italica",
+ attribution: &REFORMA_ATTRIBUTION,
+ license: &CCND,
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ reforma/Reforma1969-BlancaItalica.woff2"
+ ),
+ },
+ ),
+ (
+ "assets/fonts/reforma/Reforma1969-Gris.woff2",
+ &Font {
+ name: "Reforma 1969 Blanca Gris",
+ attribution: &REFORMA_ATTRIBUTION,
+ license: &CCND,
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ reforma/Reforma1969-Gris.woff2"
+ ),
+ },
+ ),
+ (
+ "assets/fonts/reforma/Reforma1969-GrisItalica.woff2",
+ &Font {
+ name: "Reforma 1969 Blanca Gris Italica",
+ attribution: &REFORMA_ATTRIBUTION,
+ license: &CCND,
+ blob: include_bytes!(
+ "../../../static/public/assets/fonts/\
+ reforma/Reforma1969-GrisItalica.woff2"
+ ),
+ },
+ ),
+];
+
+static REFORMA_ATTRIBUTION: Attribution = Attribution {
+ project_name: "Reforma",
+ project_url: "https://pampatype.com/reforma",
+ author: "PampaType",
+ author_url: "https://pampatype.com",
+ license_header: include_str!(
+ "../../../static/public/assets/fonts/\
+ reforma/header.LICENSE"
+ ),
+};
+
+#[derive(Serialize)]
+pub struct Font<'f> {
+ name: &'f str,
+ attribution: &'f Attribution<'f>,
+ license: &'f License<'f>,
+ blob: &'f [u8],
+}
+
+#[derive(Serialize)]
+pub struct Attribution<'a> {
+ project_name: &'a str,
+ project_url: &'a str,
+ author: &'a str,
+ author_url: &'a str,
+ license_header: &'a str,
+}
+
+#[derive(Serialize)]
+pub struct License<'l> {
+ name: &'l str,
+ kind: &'l LicenseKind,
+ text: &'l str,
+ url: &'l str,
+}
+
+#[derive(Serialize)]
+#[expect(non_camel_case_types, clippy::upper_case_acronyms)]
+pub enum LicenseKind {
+ SIL_OFL_1_1,
+ CC_BY_ND_4_0_INTERNATIONAL,
+}
+
+impl std::fmt::Display for LicenseKind {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let s = match self {
+ LicenseKind::SIL_OFL_1_1 => "SIL Open Font License 1.1",
+ LicenseKind::CC_BY_ND_4_0_INTERNATIONAL => {
+ "Creative Commons Attribution-NoDerivatives 4.0 International"
+ },
+ };
+ write!(f, "{s}")
+ }
+}
+
+static OFL: License = License {
+ name: "SIL Open Font License 1.1",
+ kind: &LicenseKind::SIL_OFL_1_1,
+ url: "assets/licenses/SIL_OFL_1_1.txt",
+ text: include_str!(
+ "../../../static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE"
+ ),
+};
+
+static CCND: License = License {
+ name: "Creative Commons Attribution-NoDerivatives 4.0 International",
+ kind: &LicenseKind::CC_BY_ND_4_0_INTERNATIONAL,
+ url: "/assets/licenses/CC_BY_ND_4_0_INTERNATIONAL.txt",
+ text: include_str!(
+ "../../../static/public/assets/fonts/_canon/\
+ CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE"
+ ),
+};
+
#[cfg(test)]
mod tests {
+ use axum::http::status::StatusCode;
+
use super::*;
+ use crate::router::handlers::mime::Mime;
async fn wrap_serial(format: &str) -> Response {
let state = GlobalState {
@@ -168,4 +662,218 @@ mod tests {
== "application/json"
);
}
+
+ #[tokio::test]
+ async fn not_found() {
+ let state = GlobalState {
+ graph: Graph::default(),
+ };
+ let response = file(Path("/k/j/m".to_string()), State(state)).await;
+ assert!(response.status() == StatusCode::NOT_FOUND);
+ }
+
+ #[test]
+ fn error_from_utf8error() {
+ let bytes = vec![0, 159];
+ let utf8error = String::from_utf8(bytes.clone()).unwrap_err();
+ let error = AssetError::from(utf8error);
+ assert!(error.utf8_error.is_some());
+ assert_eq!(error.utf8_error.unwrap().into_bytes(), bytes);
+ }
+
+ #[test]
+ fn error_from_string() {
+ let payload = "r5MDnkEojW9HZDAG";
+ let asset_error = AssetError::from(payload.to_string());
+ println!("{asset_error}");
+ assert!(asset_error.path.contains(payload));
+ }
+
+ #[test]
+ fn new_text_asset() {
+ let asset = Asset::new(&[1, 0, 1], mime::Mime::Txt).unwrap();
+
+ assert!(asset.blob.is_none());
+ assert!(asset.text.is_some());
+ assert_eq!(asset.text.unwrap(), "\u{1}\0\u{1}");
+ }
+
+ #[test]
+ fn new_blob_asset() {
+ let asset = Asset::new(&[1, 0, 1], mime::Mime::Png).unwrap();
+
+ assert!(asset.blob.is_some());
+ assert!(asset.text.is_none());
+ assert_eq!(asset.blob.unwrap(), &[1, 0, 1]);
+ }
+
+ #[test]
+ fn asset_from_str() {
+ let payload = "\u{1}\0\u{6}";
+ let asset = Asset::from_str(payload, mime::Mime::Ico);
+ assert_eq!(asset.blob.unwrap(), &[1, 0, 6]);
+ }
+
+ #[test]
+ fn new_asset_utf8_error() {
+ let bad_bytes = [0xff, 0xc0, 0xf5, 0xc1, 0x80];
+
+ let error = Asset::new(&bad_bytes, mime::Mime::Txt).unwrap_err();
+
+ assert!(matches!(&error.kind, AssetErrorKind::UTF8));
+ assert!(format!("{error}").contains("UTF8 decoding error"));
+ }
+
+ #[test]
+ fn not_found_asset_error() {
+ let error = fallback("not_found.png", &Graph::default()).unwrap_err();
+
+ assert!(matches!(&error.kind, AssetErrorKind::NotFound));
+ assert!(
+ format!("{error}")
+ .contains("The file was not found in the searched path")
+ );
+ }
+
+ #[test]
+ fn assemble_from_blob() {
+ let asset = Asset::new(&[1, 0, 1], Mime::Pdf).unwrap();
+ let response = assemble(asset, &Graph::default());
+ let content_type =
+ response.headers().get(header::CONTENT_TYPE).unwrap();
+ assert_eq!(content_type, "application/pdf");
+ }
+}
+
+#[cfg(test)]
+#[cfg(unix)]
+#[expect(clippy::panic_in_result_fn, clippy::unwrap_in_result)]
+mod serial_tests {
+ use std::{fs, os::unix::fs::PermissionsExt as _, path::PathBuf};
+
+ use super::*;
+ use crate::{
+ dev::test::{Directories, Error},
+ router::handlers::mime::Mime,
+ };
+
+ #[test]
+ fn io_asset_error() -> Result<(), Error> {
+ let dirs = Directories::setup("io_asset_error")?;
+
+ let assets = dirs.assets.clone();
+ let file = assets.join("unreadable.png");
+
+ fs::write(&file, [1, 0, 1])?;
+ let mut permissions = fs::metadata(&file)?.permissions();
+ permissions.set_mode(0o200);
+ fs::set_permissions(&file, permissions)?;
+
+ let new_permissions = fs::metadata(&file)?.permissions();
+ assert_eq!(new_permissions.mode() & 0o777, 0o200);
+
+ let error = fallback("unreadable.png", &Graph::default()).unwrap_err();
+
+ assert!(matches!(&error.kind, AssetErrorKind::IO));
+ assert!(
+ format!("{error}")
+ .contains("was found, but it could not be loaded")
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn target_file_exists() -> Result<(), Error> {
+ let dirs = Directories::setup("target_file_exists")?;
+
+ let assets = dirs.assets.clone();
+ let file = assets.join("asset.woff2");
+
+ fs::write(&file, [1, 0, 1])?;
+ let asset = fallback("asset.woff2", &Graph::default()).unwrap();
+ assert!(asset.text.is_none());
+ assert!(asset.blob.is_some());
+ assert!(matches!(asset.mime, Mime::Woff2));
+
+ Ok(())
+ }
+
+ #[test]
+ fn default_font_found_if_serving_enabled() -> Result<(), Error> {
+ let dirs = Directories::setup("font_found_if_serving_enabled")?;
+
+ let assets = dirs.assets.clone();
+ let relative_font_path =
+ PathBuf::from(FONTS[0].0.replace("assets/", ""));
+ let font_path = assets.join(&relative_font_path);
+ let font_dir = font_path.parent().expect("failed getting font dir");
+
+ println!("{font_dir:?}");
+ fs::create_dir_all(font_dir)?;
+ fs::write(&font_path, [1, 0, 1])?;
+ let graph = Graph::from_serial(
+ "[meta.config]\nserve_fonts = true",
+ &Format::TOML,
+ )
+ .expect("failed instantiating graph");
+ println!("{font_path:?}");
+ let asset = fallback(relative_font_path.to_str().unwrap(), &graph)
+ .expect("fallback failed");
+
+ assert!(asset.text.is_none());
+ assert!(asset.blob.is_some());
+ assert!(matches!(asset.mime, Mime::Woff2));
+
+ Ok(())
+ }
+
+ #[test]
+ fn custom_font_found_if_serving_enabled() -> Result<(), Error> {
+ let dirs = Directories::setup("font_found_if_serving_enabled")?;
+
+ let assets = dirs.assets.clone();
+ let relative_font_path = "fonts/custom.ttf";
+ let font_path = assets.join(relative_font_path);
+ let font_dir = font_path.parent().unwrap();
+
+ fs::create_dir_all(font_dir)?;
+ fs::write(&font_path, [1, 0, 1])?;
+ let graph = Graph::from_serial(
+ "[meta.config]\nserve_fonts = true",
+ &Format::TOML,
+ )
+ .expect("failed instantiating graph");
+ let asset =
+ fallback(relative_font_path, &graph).expect("fallback failed");
+
+ assert!(asset.text.is_none());
+ assert!(asset.blob.is_some());
+ assert!(matches!(asset.mime, Mime::Ttf));
+
+ Ok(())
+ }
+
+ #[test]
+ fn font_not_found_if_serving_disabled() -> Result<(), Error> {
+ let dirs = Directories::setup("target_file_exists")?;
+
+ let assets = dirs.assets.clone();
+ let relative_font_path =
+ PathBuf::from(FONTS[0].0.replace("assets/", ""));
+ let font_path = assets.join(&relative_font_path);
+ let font_dir = font_path.parent().unwrap();
+
+ fs::create_dir_all(font_dir)?;
+ fs::write(&font_path, [1, 0, 1])?;
+ let graph = Graph::from_serial(
+ "[meta.config]\nserve_fonts = false",
+ &Format::TOML,
+ )
+ .unwrap();
+ let error = fallback(font_path.to_str().unwrap(), &graph).unwrap_err();
+ assert!(matches!(error.kind, AssetErrorKind::NotFound));
+
+ Ok(())
+ }
}
diff --git a/src/router/handlers/graph.rs b/src/router/handlers/graph.rs
index bdf3235..0ebc539 100644
--- a/src/router/handlers/graph.rs
+++ b/src/router/handlers/graph.rs
@@ -1,7 +1,8 @@
use axum::{
- extract::State,
- response::IntoResponse as _,
- {body::Body, extract::Path, http::Response, response::Redirect},
+ body::Body,
+ extract::{Path, State},
+ http::Response,
+ response::{IntoResponse as _, Redirect},
};
use crate::{
@@ -17,18 +18,11 @@ pub async fn node(
let instant = now();
let result = state.graph.find_node(&id);
let found = result.node.is_some();
- let node = result
- .node
- .unwrap_or(Node::new(Some(format!("Could not find node ID {id}."))));
+ let node = result.node.unwrap_or(Node::not_found(Some(format!(
+ "Could not find node ID {id}."
+ ))));
- if !node.redirect.is_empty() {
- return Redirect::permanent(
- format!("/node/{}", node.redirect).as_str(),
- )
- .into_response();
- }
-
- if found && !result.exact {
+ if found && (!result.exact || result.redirect) {
return Redirect::permanent(format!("/node/{}", node.id).as_str())
.into_response();
}
@@ -43,26 +37,20 @@ pub async fn node(
"node",
&context,
if found { 500 } else { 404 },
- Some(
- format!(
- "Failed to generate page for node {} (ID {}).",
- node.title, id
- )
- .to_owned(),
- ),
+ Some(format!(
+ "Failed to generate page for node {} (ID {}).",
+ node.title, id
+ )),
!found,
)
}
#[cfg(test)]
mod tests {
- use axum::{
- http::{HeaderName, StatusCode},
- };
-
- use crate::graph::Graph;
+ use axum::http::{HeaderName, StatusCode};
use super::*;
+ use crate::graph::{Format, Graph};
async fn wrap_node(query: &str) -> Response {
let state = GlobalState {
@@ -105,7 +93,24 @@ mod tests {
#[tokio::test]
async fn docs_redirect() {
- let response = wrap_node("docs").await;
+ let response = wrap_node("RedirectTest").await;
+ assert_eq!(response.status(), StatusCode::PERMANENT_REDIRECT);
+ }
+
+ #[tokio::test]
+ async fn standalone_graph_redirect() {
+ let toml = "\
+ [nodes.n1]\n\
+ redirect = 'n2'\n\
+ \n\
+ [nodes.n2]\n\
+ text = 'n2 text'\n\
+ ";
+ let graph = Graph::from_serial(toml, &Format::TOML).unwrap();
+ let state = GlobalState { graph };
+ let response =
+ node(Path("n1".to_string()), axum::extract::State(state)).await;
+
assert_eq!(response.status(), StatusCode::PERMANENT_REDIRECT);
}
}
diff --git a/src/router/handlers/mime.rs b/src/router/handlers/mime.rs
index 4b82089..9d108e5 100644
--- a/src/router/handlers/mime.rs
+++ b/src/router/handlers/mime.rs
@@ -83,7 +83,17 @@ impl From for String {
}
}
+pub enum Kind {
+ Text,
+ Font,
+ Image,
+ Blob,
+}
+
impl Mime {
+ /// Guesses the mimetype given the extension of a filename or path.
+ ///
+ /// Only considers the last dot-delimited fragment of `path`.
pub fn guess(path: &str) -> Mime {
if let Some(pair) = path.rsplit_once('.') {
Mime::from(pair.1)
@@ -91,4 +101,68 @@ impl Mime {
Mime::Unknown
}
}
+
+ /// Returns one of four kind of mimetypes among text, font, image and blob.
+ ///
+ /// This is mainly used when serving assets through the `fixed` module in
+ /// order to determine what `Asset` field to use when assemblimg a response
+ /// body.
+ pub const fn kind(&self) -> Kind {
+ use Mime::*;
+ match self {
+ Txt | Csv | Css | Toml | Xml | Json | Js | Svg => Kind::Text,
+ Ttf | Otf | Woff | Woff2 => Kind::Font,
+ Ico | Jpeg | Png | Apng | Gif | Webp | Avif => Kind::Image,
+ Pdf | Epub | Unknown => Kind::Blob,
+ }
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn smoke() {
+ let m = Mime::guess("/home/jane/top/inner/kitty.png");
+ assert_eq!(String::from(m), "image/png");
+ }
+
+ #[test]
+ fn all() {
+ let pairs = [
+ ("file.txt", "text/plain"),
+ ("file.csv", "text/csv"),
+ ("file.css", "text/css"),
+ ("file.ttf", "font/ttf"),
+ ("file.otf", "font/otf"),
+ ("file.woff", "font/woff"),
+ ("file.woff2", "font/woff2"),
+ ("file.svg", "image/svg+xml"),
+ ("file.ico", "image/x-icon"),
+ ("file.jpeg", "image/jpeg"),
+ ("file.png", "image/png"),
+ ("file.apng", "image/apng"),
+ ("caddy.gif", "image/gif"),
+ ("file.webp", "image/webp"),
+ ("file.avif", "image/avif"),
+ ("file.toml", "application/toml"),
+ ("file.xml", "application/xml"),
+ ("file.json", "application/json"),
+ ("file.js", "text/javascript"),
+ ("file.pdf", "application/pdf"),
+ ("book.epub", "application/epub+zip"),
+ ("weird.xzx", "application/octet-stream"),
+ ];
+
+ for (file, mime) in pairs {
+ assert_eq!(String::from(Mime::guess(file)), mime);
+ }
+ }
+
+ #[test]
+ fn unknown() {
+ let u = Mime::guess("x");
+ assert!(matches!(u, Mime::Unknown));
+ }
}
diff --git a/src/router/handlers/navigation.rs b/src/router/handlers/navigation.rs
index 12bd617..78da13c 100644
--- a/src/router/handlers/navigation.rs
+++ b/src/router/handlers/navigation.rs
@@ -1,4 +1,6 @@
-use axum::{Form, body::Body, extract::State, http::Response, response::Redirect};
+use axum::{
+ Form, body::Body, extract::State, http::Response, response::Redirect,
+};
use crate::{
prelude::*,
@@ -13,6 +15,14 @@ pub async fn about(State(state): State) -> Response {
handlers::template::with_graph("about", state).await
}
+pub async fn legal(State(state): State) -> Response {
+ let mut context = tera::Context::default();
+ context.insert("graph", &state.graph);
+ context.insert("fonts", &crate::router::handlers::fixed::FONTS);
+
+ handlers::template::with_context("legal", &context, 500, None, false)
+}
+
pub async fn tree(State(state): State) -> Response {
let instant = now();
@@ -31,7 +41,7 @@ pub async fn data(State(state): State) -> Response {
let mut detached_pairs: Vec<(String, u32)> =
state.graph.stats.detached.clone().into_iter().collect();
- detached_pairs.sort_by(|a, b| b.1.cmp(&a.1));
+ detached_pairs.sort_by_key(|b| std::cmp::Reverse(b.1));
let mut context = tera::Context::default();
context.insert("graph", &state.graph);
@@ -58,9 +68,9 @@ pub struct Query {
#[cfg(test)]
mod tests {
use axum::http::StatusCode;
- use crate::graph::Graph;
use super::*;
+ use crate::graph::Graph;
async fn wrap_page(path: &str) -> Response {
let state = GlobalState {
diff --git a/src/router/handlers/raw.rs b/src/router/handlers/raw.rs
index 789e4c2..a593cbe 100644
--- a/src/router/handlers/raw.rs
+++ b/src/router/handlers/raw.rs
@@ -1,6 +1,6 @@
use axum::{
body::Body,
- http::{header, HeaderValue, Response, StatusCode},
+ http::{HeaderValue, Response, StatusCode, header},
};
use crate::prelude::*;
diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs
index 5ccecc9..eab2675 100644
--- a/src/router/handlers/template.rs
+++ b/src/router/handlers/template.rs
@@ -1,14 +1,17 @@
+use std::{collections::HashMap, fs, io::ErrorKind, path::PathBuf};
+
use axum::{
body::Body,
- http::{header, Response, StatusCode},
+ http::{Response, StatusCode, header},
};
use crate::{
+ dev::log,
prelude::*,
router::{GlobalState, handlers::raw::make_response},
};
-/// Assembles a response containing the graph as its only context
+/// Assembles a response containing the graph as its only context.
///
/// The template name **must not** contain the extension.
#[expect(clippy::unused_async)]
@@ -31,50 +34,190 @@ pub(in crate::router::handlers) fn with_context(
error_message: Option,
is_error: bool,
) -> Response {
- let (body, render_status) = render(name, context, error_message);
-
- let status_code = if is_error { error_code } else { render_status };
-
- make_response(&body, status_code, &[(header::CONTENT_TYPE, "text/html")])
+ match render(name, context, error_message) {
+ Ok(rendered) => {
+ let status_code = if is_error { error_code } else { rendered.code };
+ make_response(
+ &rendered.html,
+ status_code,
+ &[(header::CONTENT_TYPE, "text/html")],
+ )
+ },
+ Err(error) => make_response(
+ &error.template.html,
+ error.template.code,
+ &[(header::CONTENT_TYPE, "text/html")],
+ ),
+ }
}
-/// Renderes a template into a String and error code
+#[derive(Debug)]
+pub struct Rendered {
+ pub html: String,
+ pub code: u16,
+}
+
+impl Rendered {
+ fn ok(html: &str) -> Rendered {
+ Rendered {
+ code: 200,
+ html: String::from(html),
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct RenderingError {
+ pub message: String,
+ pub template: Rendered,
+}
+
+impl RenderingError {
+ fn new(message: &str, code: u16, error: &tera::Error) -> RenderingError {
+ RenderingError {
+ message: String::from(message),
+ template: Rendered {
+ html: emergency_wrap(error, message),
+ code,
+ },
+ }
+ }
+
+ fn with_template(
+ message: &str,
+ code: u16,
+ template: &str,
+ ) -> RenderingError {
+ RenderingError {
+ message: String::from(message),
+ template: Rendered {
+ html: String::from(template),
+ code,
+ },
+ }
+ }
+}
+
+impl std::fmt::Display for RenderingError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(f, "Rendering Error: {}", self.message)
+ }
+}
+
+static DEFAULTS: &[(&str, &str)] = &[
+ ("base.html", include_str!("../../../templates/base.html")),
+ ("index.html", include_str!("../../../templates/index.html")),
+ ("about.html", include_str!("../../../templates/about.html")),
+ ("legal.html", include_str!("../../../templates/legal.html")),
+ ("data.html", include_str!("../../../templates/data.html")),
+ ("empty.html", include_str!("../../../templates/empty.html")),
+ ("error.html", include_str!("../../../templates/error.html")),
+ ("node.html", include_str!("../../../templates/node.html")),
+ ("tree.html", include_str!("../../../templates/tree.html")),
+];
+
+fn read_template(name: &str, path: PathBuf) -> Result {
+ let defaults: HashMap<&str, &str> = DEFAULTS.iter().copied().collect();
+
+ match fs::read_to_string(path) {
+ Ok(content) => Ok(content),
+ Err(error) if error.kind() == ErrorKind::NotFound => {
+ match defaults.get(name) {
+ Some(default) => Ok(default.to_string()),
+ None => Err(error),
+ }
+ },
+ Err(error) => Err(error),
+ }
+}
+
+fn load_templates() -> Result {
+ let mut tera = tera::Tera::default();
+
+ let root = PathBuf::from("templates");
+ let default_names: Vec<&str> = DEFAULTS.iter().map(|(n, _)| *n).collect();
+
+ match fs::read_dir(&root) {
+ Ok(dir) => {
+ log!(
+ DEBUG,
+ "Reading templates from root directory '{}', canonically {:?}",
+ root.display(),
+ root.canonicalize()
+ );
+ for file_opt in dir {
+ let file = file_opt?;
+ let path = file.path();
+ if path.is_file() {
+ if let Some(name) = path.clone().file_name() {
+ let Some(name_str) = name.to_str() else {
+ return Err(tera::Error::msg(format!(
+ "Template filename {} is not valid unicode",
+ name.display()
+ )))
+ };
+ if !default_names.contains(&name_str) {
+ tera.add_raw_template(
+ name_str,
+ &read_template(name_str, path)?,
+ )?;
+ }
+ }
+ }
+ }
+ },
+ Err(error) => {
+ log!(
+ VERBOSE,
+ "A 'templates' directory was not found or is not accessible: \
+ only built-in templates will be available"
+ );
+ if error.kind() != ErrorKind::NotFound {
+ return Err(tera::Error::msg(error.to_string()))
+ }
+ },
+ }
+
+ for tuple in DEFAULTS {
+ let path = root.join(tuple.0);
+ let name = tuple.0;
+ tera.add_raw_template(name, &read_template(name, path)?)?;
+ }
+
+ Ok(tera)
+}
+
+/// Renders a template into a String and error code.
///
/// The template name **must not** contain the extension (e.g. `.html`).
pub(in crate::router::handlers) fn render(
template: &str,
- // TODO take Option, skip context if None,
- // then template_handler can replace static_template_handler
context: &tera::Context,
error_message: Option,
-) -> (String, u16) {
+) -> Result {
let instant = now();
- // TODO just return an Option/String> here
- let tera = match tera::Tera::new("./templates/**/*") {
- Ok(t) => t,
- Err(e) => {
- return (emergency_wrap(&e), 500);
+ let tera = match load_templates() {
+ Ok(engine) => engine,
+ Err(error) => {
+ return Err(RenderingError::new(
+ "Failed instantiating template engine",
+ 500,
+ &error,
+ ))
},
};
match tera.render(format!("{template}.html").as_str(), context) {
- Ok(t) => {
+ Ok(html) => {
tlog!(&instant, "Rendered template {template}");
- (t, 200)
+ Ok(Rendered::ok(&html))
},
Err(e) => {
let mut error_context = tera::Context::default();
let mut out_error_message = match error_message {
- Some(s) => format!(
- "Template render failed.\n\
- User message: {s},
- Engine message:\n{e:#?} "
- ),
- None => format!(
- "Template render failed.\n\
- Engine message:\n{e:#?} "
- ),
+ Some(s) => emergency_wrap(&e, &s),
+ None => emergency_wrap(&e, "Template render failed."),
};
if log::env_level() >= VERBOSE {
@@ -91,53 +234,78 @@ pub(in crate::router::handlers) fn render(
&StatusCode::INTERNAL_SERVER_ERROR.to_string(),
);
- (
- tera.render("error.html", &error_context)
- .unwrap_or(out_error_message.clone()),
- 500,
- )
+ match tera.render("error.html", &error_context) {
+ Ok(rendered_error) => Err(RenderingError::with_template(
+ &out_error_message,
+ 500,
+ &rendered_error,
+ )),
+ Err(error_rendering_error) => Err(RenderingError::new(
+ &format!(
+ "Failed to render an error message template for \
+ \"{out_error_message}\""
+ ),
+ 500,
+ &error_rendering_error,
+ )),
+ }
},
}
}
-fn emergency_wrap(error: &tera::Error) -> String {
+fn emergency_wrap(error: &tera::Error, message: &str) -> String {
log!(ERROR, "{error:#?}");
+
+ let message_element = format!("{message}
");
+
format!(
- r#"
-
-
- Pre-Templating Error
-
-
-
-
-
- Early Pre-Templating Error
- This normally indicates a malformed template.
-
- {error:#?}
-
-
- If you haven't modified templates, plese consider
- reporting it .
-
-
-
- "#
+ "\n\
+ \n\
+ \n\
+ en Pre-Templating Error \n
+ \n\
+ \n\
+ \n\
+ \n\
+ \n\
+ en Early Pre-Templating Error \n\
+ {message_element}\n\
+ \n\
+ {error:#?}\n\
+ \n\
+ This error may indicate a malformed or missing template.
\n\
+ If you haven't modified templates, please consider \
+ \
+ reporting it , including:\
+
\n\
+ \n\
+ The error message above \n\
+ en version: {} \n\
+ If possible, your graph file's [meta.config] \
+ values and definition for this page. \n\
+ \n\
+ \n\
+ \n\
+ ",
+ env!("CARGO_PKG_VERSION")
)
}
#[cfg(test)]
mod tests {
- use crate::graph::Graph;
-
use super::*;
+ use crate::graph::Graph;
#[test]
fn by_filename_forced_error() {
@@ -176,43 +344,68 @@ mod tests {
fn render_with_context() {
let payload = "dBgIw8DnNHxJojiXzu445qUC4UpxwZCy";
let mut context = tera::Context::default();
- let node = crate::graph::Node::new(Some(payload.to_string()));
+ let node = crate::graph::Node::not_found(Some(payload.to_string()));
let graph = Graph::load();
context.insert("node", &node);
context.insert("graph", &graph);
context.insert("incoming", &graph.incoming.get(&node.id));
- let (body, status) = render("node", &context, None);
- assert_eq!(status, 200);
- assert!(body.matches(payload).count() == 1);
+ match render("node", &context, None) {
+ Ok(rendered) => {
+ assert_eq!(rendered.code, 200);
+ assert!(rendered.html.matches(payload).count() == 1);
+ },
+ Err(error) => {
+ panic!("Errored on template generation with {error:?}")
+ },
+ }
}
#[test]
fn render_custom_error_message() {
let payload = "dBgIw8DnNHxJojiXzu445qUC4UpxwZCy";
- let (body, status) = render(
+ match render(
"ObH9jYUl4wMhUNcXnuqwVVzHoqx4ufyN",
&tera::Context::default(),
Some(payload.to_string()),
- );
- assert_eq!(status, 500);
- assert!(body.matches(payload).count() == 1);
+ ) {
+ Ok(_) => panic!("Got Ok, expected Error"),
+ Err(error) => {
+ assert_eq!(error.template.code, 500);
+ assert!(error.template.html.matches(payload).count() == 1);
+ },
+ }
}
#[test]
fn render_empty() {
- let (body, status) = render(
+ match render(
"R8D1pxwHZDxcH5SMjR7rZEnIzmpkiHkH",
&tera::Context::default(),
None,
- );
- assert_eq!(status, 500);
- assert!(body.matches("Template render failed").count() == 1);
+ ) {
+ Ok(_) => panic!("Got Ok, expected Error"),
+ Err(error) => {
+ assert_eq!(error.template.code, 500);
+ assert!(
+ error
+ .template
+ .html
+ .matches("Template render failed")
+ .count()
+ == 1
+ );
+ },
+ }
}
#[test]
fn render_not_found() {
let payload = "OL6kb9qHe7Iwr7wFIRKUTeFhF34BRsQo";
- let (body, status) = render(payload, &tera::Context::default(), None);
+ let (body, status) =
+ match render(payload, &tera::Context::default(), None) {
+ Ok(_) => panic!("Got Ok, expected Error"),
+ Err(error) => (error.template.html, error.template.code),
+ };
assert!(body.matches("TemplateNotFound").count() > 0);
assert!(body.matches(payload).count() > 0);
@@ -221,7 +414,11 @@ mod tests {
#[test]
fn render_bad_context() {
- let (body, status) = render("node", &tera::Context::default(), None);
+ let (body, status) =
+ match render("node", &tera::Context::default(), None) {
+ Ok(_) => panic!("Got Ok, expected Error"),
+ Err(error) => (error.template.html, error.template.code),
+ };
assert!(body.matches("Template render failed.").count() > 0);
assert_eq!(status, 500);
}
@@ -230,7 +427,174 @@ mod tests {
fn emergency_wrap_custom_message() {
let payload = "JLaTtsnd2IFukIOvqFNymeuiaS6nMaUc";
let error = tera::Error::msg(payload);
- let html = emergency_wrap(&error);
+ let html = emergency_wrap(&error, "");
assert!(html.matches(payload).count() == 1);
}
+
+ #[test]
+ fn default_templates_exist_and_match() {
+ let templates_dir =
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("templates");
+
+ for (map_name, map_contents) in DEFAULTS {
+ let path = templates_dir.join(map_name);
+ assert!(path.exists());
+ assert!(path.is_file());
+ let contents = fs::read_to_string(&path).unwrap();
+ assert_eq!(&contents, map_contents);
+ }
+ }
+
+ #[test]
+ fn rendering_error_html_contains_inner_error() {
+ let outer_payload = "Gl0c7CyArjlG1Zgvj3D5BFmZT6zRz5Ky";
+ let inner_payload = "t53pvXCf0JqUzwiM5BZbYxAQadYSJ9XW";
+ let inner_error = tera::Error::msg(inner_payload);
+ let error = RenderingError::new(outer_payload, 501, &inner_error);
+ assert!(error.template.html.contains(inner_payload));
+ assert!(error.template.html.contains(outer_payload));
+ }
+
+ #[test]
+ fn rendering_error_display() {
+ let payload = "4LKNOSqfW0Ys3LALDAond8IIp5RgN7vK";
+ let error = RenderingError::new(payload, 501, &tera::Error::msg(""));
+ let display_string = format!("{error}");
+ assert!(display_string.contains(payload));
+ }
+
+ #[test]
+ fn empty_template_read_is_an_error() {
+ let result = read_template("", PathBuf::from(""));
+ assert!(result.is_err());
+ }
+
+ #[test]
+ fn template_read_without_permissions_is_an_error() {
+ let result = read_template("", PathBuf::from("/etc/shadow"));
+ assert!(result.is_err());
+ }
+
+ #[test]
+ fn template_read_without_a_default_is_an_error() {
+ let result = read_template(
+ "xkQwFZpqf5iz",
+ PathBuf::from("templates/Boy5CZQUk2oX"),
+ );
+ assert!(result.is_err());
+ }
+
+ #[test]
+ fn template_read_with_a_default_is_ok() {
+ let result =
+ read_template("base.html", PathBuf::from("templates/St1iFgeOrhCK"));
+ assert!(result.is_ok());
+ }
+
+ #[test]
+ fn template_read_with_a_file_is_ok() {
+ let result =
+ read_template("GpzjjAPhCTIr", PathBuf::from("templates/base.html"));
+ assert!(result.is_ok());
+ }
+}
+
+#[cfg(test)]
+#[expect(clippy::panic_in_result_fn)]
+mod serial_tests {
+ use std::{ffi::OsStr, os::unix::ffi::OsStrExt as _};
+
+ use super::*;
+ use crate::dev::test::{Directories, Error};
+
+ #[test]
+ #[cfg_attr(not(unix), ignore)]
+ fn invalid_utf8_template_filename() -> Result<(), Error> {
+ let dirs = Directories::setup("encoding")?;
+
+ let invalid_name = OsStr::from_bytes(&[0xff, 0xfe, 0x80]);
+ let file_path = dirs.templates.join(invalid_name);
+ fs::write(file_path, b"")?;
+
+ let template_load_result = load_templates();
+ let err = template_load_result.err().unwrap();
+
+ let error_message = err.to_string();
+ assert!(error_message.contains("not valid unicode"));
+
+ Ok(())
+ }
+
+ #[test]
+ fn custom_template() -> Result<(), Error> {
+ let dirs = Directories::setup("custom_template")?;
+
+ let file_name = "custom.html";
+ let file_path = dirs.templates.join(file_name);
+ fs::write(file_path, b"")?;
+
+ let engine = load_templates()?;
+ assert!(engine.get_template_names().any(|t| t == "custom.html"));
+
+ Ok(())
+ }
+
+ #[test]
+ fn custom_template_inheritance_error() -> Result<(), Error> {
+ let dirs = Directories::setup("custom_template")?;
+
+ let file_name = "custom.html";
+ let file_path = dirs.templates.join(file_name);
+ fs::write(file_path, br#"{% extends "nonexistent.html" %}"#)?;
+
+ let template_load_result = load_templates();
+ assert!(template_load_result.is_err());
+
+ Ok(())
+ }
+
+ #[test]
+ fn inner_template_no_op() -> Result<(), Error> {
+ let dirs = Directories::setup("inner_template")?;
+
+ let inner_dir = dirs.templates.join("inner");
+ fs::create_dir(&inner_dir)?;
+ let inner_template = inner_dir.join("inner.html");
+ fs::write(inner_template, br#"{% extends "nonexistent.html" %}"#)?;
+
+ let engine = load_templates()?;
+ let default_count = dirs.original.join("templates").read_dir()?.count();
+ let template_count = engine.get_template_names().count();
+ assert!(template_count == default_count);
+
+ Ok(())
+ }
+
+ #[test]
+ fn templates_dir_not_found_ok() -> Result<(), Error> {
+ let dirs = Directories::setup("not_found_error")?;
+
+ std::fs::remove_dir_all(&dirs.templates)?;
+ let template_load_result = load_templates();
+ template_load_result?;
+
+ Ok(())
+ }
+
+ #[test]
+ // Unexpected here means any error other than 'not found'
+ fn templates_dir_unexpected_error() -> Result<(), Error> {
+ let dirs = Directories::setup("unexpected_error")?;
+
+ log!(DEBUG, "Working directory is {:?}", std::env::current_dir());
+
+ std::fs::remove_dir_all(&dirs.templates)?;
+ let templates = dirs.test.join("templates");
+ fs::write(&templates, b"")?;
+
+ let template_load_result = load_templates();
+ assert!(template_load_result.is_err());
+
+ Ok(())
+ }
}
diff --git a/src/syntax/command.rs b/src/syntax/command.rs
index 948866f..04d1195 100644
--- a/src/syntax/command.rs
+++ b/src/syntax/command.rs
@@ -7,11 +7,17 @@ use crate::prelude::*;
static FIRST_PARSE: AtomicBool = AtomicBool::new(true);
-#[derive(Clone, Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Arguments {
pub hostname: String,
pub port: u16,
pub graph_path: PathBuf,
+ pub flags: Flags,
+}
+
+#[derive(Default, Clone, Debug, PartialEq, Eq)]
+pub struct Flags {
+ pub version: bool,
}
impl Arguments {
@@ -32,6 +38,7 @@ impl Default for Arguments {
hostname: String::from("0.0.0.0"),
port: 0,
graph_path: PathBuf::from("./static/graph.toml"),
+ flags: Flags::default(),
}
}
}
@@ -39,21 +46,33 @@ impl Default for Arguments {
fn parse(defaults: &Arguments, args: &[String]) -> Arguments {
let mut out_args = defaults.clone();
- let filtered_args = if let Some((head, tail)) = args.split_first() {
+ // The first argument is usually the command path, but this is not
+ // guaranteed on all platforms so we drop it if it is unrecognized.
+ // For now, this is done simply by checking if it starts with a dash
+ let commandless_args = if let Some((head, tail)) = args.split_first() {
if head.starts_with('-') { args } else { tail }
} else {
args
};
- for arg in filtered_args.chunks(2) {
+ let mut nonflag_args: Vec<&str> = vec![];
+ for arg in commandless_args {
+ if arg == "--version" || arg == "-v" {
+ out_args.flags.version = true;
+ } else {
+ nonflag_args.push(arg);
+ }
+ }
+
+ for arg in nonflag_args.chunks(2) {
if let Some(argument) = arg.first()
&& let Some(parameter) = arg.get(1)
{
- if argument.eq("-h") || argument.eq("--hostname") {
- out_args.hostname = String::from(parameter);
- } else if argument.eq("-p") || argument.eq("--port") {
+ if *argument == "-h" || *argument == "--hostname" {
+ out_args.hostname = String::from(*parameter);
+ } else if *argument == "-p" || *argument == "--port" {
out_args.port = parameter.parse().unwrap_or(out_args.port);
- } else if argument.eq("-g") || argument.eq("--graph") {
+ } else if *argument == "-g" || *argument == "--graph" {
out_args.graph_path = PathBuf::from(parameter);
} else {
if FIRST_PARSE.load(Ordering::SeqCst) {
@@ -78,6 +97,7 @@ mod tests {
hostname: String::from("localhost"),
port: 3007,
graph_path: PathBuf::default(),
+ flags: Flags::default(),
};
assert_eq!(args.make_address(), "localhost:3007");
diff --git a/src/syntax/content.rs b/src/syntax/content.rs
index f8ccefc..8537e34 100644
--- a/src/syntax/content.rs
+++ b/src/syntax/content.rs
@@ -1,4 +1,6 @@
-use parser::{Token, Lexeme};
+use std::mem::discriminant;
+
+use parser::{Lexeme, Token};
use crate::graph::Graph;
@@ -21,10 +23,48 @@ pub struct TokenOutput {
pub format_tokens: Vec,
}
-pub fn parse(text: &str, graph: &Graph) -> String {
- parser::read(text, graph)
+impl TokenOutput {
+ pub fn only(&self, kind: &Token) -> Vec {
+ let filter = |tokens: &[Token], k: &Token| -> Vec {
+ tokens
+ .iter()
+ .filter(|&t| discriminant(t) == discriminant(k))
+ .cloned()
+ .collect::>()
+ };
+
+ let filtered_tokens = filter(&self.tokens, kind);
+ let filtered_format_tokens = filter(&self.format_tokens, kind);
+
+ [filtered_tokens, filtered_format_tokens]
+ .into_iter()
+ .flatten()
+ .collect::>()
+ }
}
+pub fn parse(text: &str, graph: &Graph) -> String { parser::read(text, graph) }
+
pub fn rich_parse(text: &str, graph: &Graph) -> TokenOutput {
- parser::rich_read(text, graph)
+ parser::rich_read(
+ &text.replace("{{ en_version }}", env!("CARGO_PKG_VERSION")),
+ graph,
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::syntax::content::parser::token::{Bold, Oblique};
+
+ #[test]
+ fn only() {
+ let graph = Graph::default();
+ let output = rich_parse("*four* *bold* and _two_ italic", &graph);
+ let bold_tokens = output.only(&Token::Bold(Bold::new(true)));
+ let italic_tokens = output.only(&Token::Oblique(Oblique::new(true)));
+ println!("{bold_tokens:?}");
+ assert_eq!(bold_tokens.len(), 4);
+ assert_eq!(italic_tokens.len(), 2);
+ }
}
diff --git a/src/syntax/content/parser.rs b/src/syntax/content/parser.rs
index 0498582..42b2680 100644
--- a/src/syntax/content/parser.rs
+++ b/src/syntax/content/parser.rs
@@ -1,86 +1,21 @@
-use crate::{prelude::*, graph::Graph};
-use super::{TokenOutput, Parseable as _, LexMap};
-use token::{LineBreak, Literal};
use context::{Block, Inline};
-pub use {lexeme::Lexeme, token::Token, state::State};
+pub use lexeme::Lexeme;
+use lexer::{LEXMAP, lex};
+pub use state::State;
+pub use token::Token;
+
+use crate::{graph::Graph, prelude::*, syntax::content::TokenOutput};
-pub mod token;
-pub mod lexeme;
-pub mod segment;
pub mod context;
+pub mod lexeme;
+pub mod lexer;
pub mod point;
+pub mod segment;
pub mod state;
+pub mod token;
-const LEXMAP: LexMap = &[
- (LineBreak::probe, |lexeme| {
- Token::LineBreak(LineBreak::lex(lexeme))
- }),
- (Literal::probe, |lexeme| {
- Token::Literal(Literal::lex(lexeme))
- }),
-];
-
-fn lex(text: &str, map: LexMap, graph: &Graph, blocking: bool) -> TokenOutput {
- let mut tokens: Vec = Vec::default();
- let mut state = State::default();
-
- let segments = segment::segment(text);
- let lexemes = Lexeme::collect(&segments);
-
- log!(VERBOSE, "Segments: {segments:?}");
-
- let mut iterator = lexemes.iter().peekable();
- while let Some(lexeme) = iterator.next() {
- if lexeme.match_char('\\') {
- if let Some(next) = iterator.next() {
- tokens.push(Token::Literal(Literal::lex(next)));
- }
- continue;
- }
-
- if blocking {
- if context::block::parse(
- lexeme,
- &mut state,
- &mut tokens,
- &mut iterator,
- graph,
- ) {
- continue;
- }
- }
-
- if point::parse(lexeme, &mut state, &mut tokens, &mut iterator) {
- continue;
- }
-
- if context::inline::parse(
- lexeme,
- &mut state,
- &mut tokens,
- &mut iterator,
- graph,
- ) {
- continue;
- }
-
- for (probe, lex) in map {
- if probe(lexeme) {
- let token = lex(lexeme);
- log!(VERBOSE, "Lexmap lexed {lexeme} into {token}");
- tokens.push(token);
- break;
- }
- }
- }
-
- context::close(&state, &mut tokens);
-
- TokenOutput {
- tokens,
- format_tokens: state.format_tokens,
- text: None,
- }
+fn parse(tokens: &[Token]) -> String {
+ tokens.iter().map(Token::render).collect::()
}
pub(super) fn read(input: &str, graph: &Graph) -> String {
@@ -98,7 +33,7 @@ pub(super) fn rich_read(input: &str, graph: &Graph) -> TokenOutput {
}
/// Apply end-to-end point and inline parsing for nested formatting, such as
-/// inside the display text of anchors and list items
+/// inside the display text of anchors and list items.
pub fn format(input: &str, graph: &Graph) -> (String, Vec) {
let tokens = lex(input, LEXMAP, graph, false).tokens;
(parse(&tokens), tokens)
@@ -112,22 +47,12 @@ pub fn flatten(input: &str, graph: &Graph) -> String {
flat
}
-fn parse(tokens: &[Token]) -> String {
- tokens.iter().map(Token::render).collect::()
-}
-
#[cfg(test)]
mod tests {
- use crate::{
- graph::Graph,
- syntax::content::parser::{token::header::Level},
- };
-
use super::*;
+ use crate::{graph::Graph, syntax::content::parser::token::header::Level};
- fn read_noconfig(input: &str) -> String {
- read(input, &Graph::default())
- }
+ fn read_noconfig(input: &str) -> String { read(input, &Graph::default()) }
#[test]
fn empty_render_is_empty() {
@@ -137,7 +62,10 @@ mod tests {
#[test]
fn mixed_sample() {
let en = "`this |test|` tries ## to |brea|k|: things";
- let html = r#"this |test| tries ## to brea : things
"#;
+ let html = concat!(
+ r#"this |test| tries ## to brea : things
"#,
+ );
assert_eq!(read_noconfig(en), html);
}
diff --git a/src/syntax/content/parser/context.rs b/src/syntax/content/parser/context.rs
index e536bd2..e1379a5 100644
--- a/src/syntax/content/parser/context.rs
+++ b/src/syntax/content/parser/context.rs
@@ -1,58 +1,77 @@
use crate::syntax::content::parser::{
State, Token,
- token::{Header, Paragraph, PreFormat},
+ token::{Header, Paragraph, Verse},
};
+pub mod anchor;
pub mod block;
pub mod inline;
-pub mod anchor;
pub mod list;
+pub mod preformat;
+pub mod quote;
+pub mod table;
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub struct Context {
pub block: Block,
pub inline: Inline,
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub enum Block {
Paragraph,
Header(u8), // level
List,
PreFormat,
+ Quote,
+ Table,
+ Verse,
+ #[default]
None,
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub enum Inline {
Anchor,
Code,
+ #[default]
None,
}
/// # Panics
-/// Panics if there is an open header or list at end of input.
+/// Panics if there is an open token at end of input that can't be easily
+/// closed by simply adding a matching closing token. This normally is handled
+/// by context parsers and probably indicates an error in one of them.
pub fn close(state: &State, tokens: &mut Vec) {
match state.context.block {
- Block::PreFormat => {
- tokens.push(Token::PreFormat(PreFormat::new(false)));
- },
Block::Paragraph => {
tokens.push(Token::Paragraph(Paragraph::new(false)));
},
- Block::List => {
- panic!("End of input with open list")
- },
Block::Header(level) => {
tokens.push(Token::Header(Header::from_u8(level, false, None)));
},
+ Block::Verse => {
+ tokens.push(Token::Verse(Verse::new(false)));
+ },
+ Block::PreFormat => {
+ panic!("End of input with open preformat: {tokens:#?}")
+ },
+ Block::List => {
+ panic!("End of input with open list: {tokens:#?}")
+ },
+ Block::Quote => {
+ panic!("End of input with open quote: {tokens:#?}")
+ },
+ Block::Table => {
+ panic!("End of input with open table: {tokens:#?}")
+ },
Block::None => (),
}
}
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::{context::Block, State};
+ use crate::syntax::content::parser::{State, context::Block};
#[test]
#[should_panic(expected = "End of input with open list")]
@@ -61,4 +80,27 @@ mod tests {
state.context.block = Block::List;
super::close(&state, &mut vec![]);
}
+
+ #[test]
+ #[should_panic(expected = "End of input with open quote")]
+ fn open_quote_eoi() {
+ let mut state = State::default();
+ state.context.block = Block::Quote;
+ super::close(&state, &mut vec![]);
+ }
+
+ #[test]
+ #[should_panic(expected = "End of input with open table")]
+ fn open_table_eoi() {
+ let mut state = State::default();
+ state.context.block = Block::Table;
+ super::close(&state, &mut vec![]);
+ }
+
+ #[test]
+ fn open_verse_eoi() {
+ let mut state = State::default();
+ state.context.block = Block::Verse;
+ super::close(&state, &mut vec![]);
+ }
}
diff --git a/src/syntax/content/parser/context/anchor.rs b/src/syntax/content/parser/context/anchor.rs
index d9a861a..2aa172c 100644
--- a/src/syntax/content/parser/context/anchor.rs
+++ b/src/syntax/content/parser/context/anchor.rs
@@ -1,7 +1,7 @@
use crate::{
- prelude::*,
- syntax::content::parser::{context::Inline, Lexeme, State, Token},
graph::Graph,
+ prelude::*,
+ syntax::content::parser::{Lexeme, State, Token, context::Inline},
};
/// Handles open anchor contexts until an anchor token is fully parsed.
@@ -34,6 +34,9 @@ pub fn parse(
log!(VERBOSE, "End: Next lexeme is a pipe");
buffer.text.push_str(&lexeme.text());
candidate.set_text(&buffer.text.clone());
+ if buffer.text.starts_with('/') {
+ candidate.set_absolute(true);
+ }
} else {
log!(
VERBOSE,
@@ -61,7 +64,7 @@ pub fn parse(
&& !lexeme.match_next_char('|')
{
log!(VERBOSE, "End: Plural anchor");
- candidate.set_destination(Some(&candidate.text().clone()));
+ candidate.set_destination(Some(&candidate.text()));
candidate.text_push("s");
if lexeme.last() {
push(None, tokens, state, graph);
@@ -73,7 +76,7 @@ pub fn parse(
if candidate.text().contains(':') {
candidate.set_external(true);
}
- push(Some(&candidate.text().clone()), tokens, state, graph);
+ push(Some(&candidate.text()), tokens, state, graph);
} else {
push(Some(&buffer.destination.clone()), tokens, state, graph);
}
@@ -84,6 +87,13 @@ pub fn parse(
"State: Found a pipe, but no boundary: destination follows"
);
candidate.set_balanced(true);
+ if lexeme.match_next_first_char('/') {
+ log!(
+ VERBOSE,
+ "State: Destination starts with a dash, marking as absolute"
+ );
+ candidate.set_absolute(true);
+ }
return true;
} else if lexeme.match_char(':') {
log!(VERBOSE, "State: Found a colon, marking anchor as external");
@@ -162,11 +172,9 @@ fn push(
#[cfg(test)]
mod tests {
- use crate::{syntax::content::parser, graph::Graph};
+ use crate::{graph::Graph, syntax::content::parser};
- fn read(input: &str) -> String {
- parser::read(input, &Graph::default())
- }
+ fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn flanking() {
@@ -188,7 +196,10 @@ mod tests {
fn flanking_with_trailing_comma_and_space() {
assert_eq!(
read("|Node|, at"),
- r#"Node , at
"#
+ concat!(
+ r#"Node , at
"#,
+ )
);
}
@@ -204,7 +215,10 @@ mod tests {
fn needless_three_pipe_anchor() {
assert_eq!(
read("|Node|Destination|"),
- r#"Node
"#
+ concat!(
+ r#"Node
"#
+ )
);
}
@@ -212,7 +226,10 @@ mod tests {
fn nonleading_second_pipe() {
assert_eq!(
read("Go to Node|Destination|, here"),
- r#"Go to Node , here
"#,
+ concat!(
+ r#"Go to Node , here
"#
+ ),
);
}
@@ -220,7 +237,11 @@ mod tests {
fn anchor_to_node_s() {
assert_eq!(
read("The |letter s|s|'s node: |s|!"),
- r#"The letter s 's node: s !
"#
+ concat!(
+ r#"The letter s 's node: "#,
+ r#"s !
"#
+ )
);
}
@@ -228,7 +249,10 @@ mod tests {
fn nonleading_plural_anchor() {
assert_eq!(
read("The flower|s bloomed"),
- r#"The flowers bloomed
"#
+ concat!(
+ r#"The flowers bloomed
"#,
+ )
);
}
@@ -236,7 +260,11 @@ mod tests {
fn leading_plural_anchor() {
assert_eq!(
read("Interfaces are |element|s of |system|s."),
- r#"Interfaces are elements of systems .
"#
+ concat!(
+ r#"Interfaces are elements of systems .
"#
+ )
);
}
@@ -244,7 +272,11 @@ mod tests {
fn leading_multiword_anchor() {
assert_eq!(
read("interactions are |basic elements| of systems"),
- r#"interactions are basic elements of systems
"#
+ concat!(
+ r#"interactions are basic elements "#,
+ r#"of systems
"#,
+ ),
);
}
@@ -252,7 +284,11 @@ mod tests {
fn explicit_end_of_destination() {
assert_eq!(
read("interactions are |basic elements|BasicElements| of systems"),
- r#"interactions are basic elements of systems
"#
+ concat!(
+ r#"interactions are basic elements of "#,
+ r#"systems
"#
+ )
);
}
@@ -260,7 +296,11 @@ mod tests {
fn explicit_end_of_external_destination() {
assert_eq!(
read("this |anchor example|https://example.com| is external"),
- r#"this anchor example is external
"#
+ concat!(
+ r#"this anchor example is "#,
+ r#"external
"#
+ )
);
}
@@ -276,7 +316,10 @@ mod tests {
fn external_anchor_destination_at_eoi() {
assert_eq!(
read("a b|https://example.com"),
- r#"a b
"#
+ concat!(
+ r#"a b
"#,
+ )
);
}
@@ -284,7 +327,10 @@ mod tests {
fn nonleading_plural_anchor_at_eoi() {
assert_eq!(
read("element|s"),
- r#"elements
"#
+ concat!(
+ r#"elements
"#,
+ )
);
}
@@ -292,17 +338,37 @@ mod tests {
fn leading_plural_anchor_at_eoi() {
assert_eq!(
read("|element|s"),
- r#"elements
"#
+ concat!(
+ r#"elements
"#,
+ )
+ );
+ }
+
+ #[test]
+ fn absolute_anchor() {
+ let parse_result =
+ parser::rich_read("see the |raw endpoints|/data|.", &Graph::load());
+ println!("Parsed tokens: {:#?}", parse_result.tokens);
+ assert_eq!(
+ parse_result.text.unwrap(),
+ concat!(
+ r#"see the "#,
+ r#"raw endpoints .
"#,
+ ),
);
}
#[test]
fn http_external_anchor() {
assert_eq!(
- read(
- "a |false dichotomy|https://en.wikipedia.org/wiki/False_dilemma|."
+ read("a |false dichotomy|https://wikipedia.org/False_dilemma|."),
+ concat!(
+ r#"a "#,
+ r#"false dichotomy .
"#,
),
- r#"a false dichotomy .
"#
);
}
@@ -315,7 +381,8 @@ mod tests {
"at rustup.rs",
)),
concat!(
- r#"Rust toolchain "#,
+ r#"
Rust toolchain "#,
"\n",
"at rustup.rs
",
)
@@ -326,7 +393,11 @@ mod tests {
fn http_external_anchor_leading_no_third_then_space() {
assert_eq!(
read("|Rust toolchain|https://rustup.rs/ at rustup.rs"),
- r#"Rust toolchain at rustup.rs
"#
+ concat!(
+ r#"Rust toolchain "#,
+ r#"at rustup.rs
"#,
+ ),
);
}
@@ -334,7 +405,10 @@ mod tests {
fn http_external_anchor_leading_no_third_then_eoi() {
assert_eq!(
read("|Rust toolchain|https://rustup.rs/"),
- r#"Rust toolchain
"#
+ concat!(
+ r#"Rust toolchain
"#,
+ )
);
}
@@ -344,7 +418,10 @@ mod tests {
read("\n|SomeAnchor|\n"),
concat!(
"\n",
- r#"SomeAnchor
"#
+ concat!(
+ r#"SomeAnchor
"#,
+ )
),
);
}
@@ -354,9 +431,11 @@ mod tests {
assert_eq!(
read("|SomeAnchor|\n|SomeOtherAnchor|\n"),
concat!(
- r#"SomeAnchor "#,
+ r#"
SomeAnchor "#,
"\n",
- r#"SomeOtherAnchor
"#
+ r#"SomeOtherAnchor
"#,
)
);
}
@@ -366,10 +445,12 @@ mod tests {
assert_eq!(
read("|SomeAnchor|\n\n|SomeOtherAnchor|\n"),
concat!(
- r#"SomeAnchor
"#,
+ r#"SomeAnchor
"#,
"\n",
"\n",
- r#"SomeOtherAnchor
"#
+ r#"SomeOtherAnchor
"#,
),
);
}
@@ -378,7 +459,10 @@ mod tests {
fn trailing_anchor() {
assert_eq!(
read("see acks|acks"),
- r#"see acks
"#
+ concat!(
+ r#"see acks
"#,
+ )
);
}
@@ -388,8 +472,9 @@ mod tests {
read("\nsee acks|acks\n"),
concat!(
"\n",
- r#"see acks
"#
- )
+ r#"see acks
"#,
+ ),
);
}
@@ -417,7 +502,10 @@ mod tests {
fn anchor_with_trailing_single_quote() {
assert_eq!(
read("the |lion|'s mouth"),
- r#"the lion 's mouth
"#,
+ concat!(
+ r#"the lion 's mouth
"#,
+ )
);
}
@@ -425,7 +513,10 @@ mod tests {
fn anchor_with_trailing_double_quote() {
assert_eq!(
read(r#"the "|real|" motive"#),
- r#"the "real " motive
"#,
+ concat!(
+ r#"the "real " motive
"#,
+ )
);
}
@@ -433,7 +524,10 @@ mod tests {
fn anchor_with_trailing_parenthesis() {
assert_eq!(
read("this (though |true|) was questioned"),
- r#"this (though true ) was questioned
"#,
+ concat!(
+ r#"this (though true ) was questioned
"#,
+ )
);
}
@@ -441,7 +535,10 @@ mod tests {
fn anchor_with_leading_single_quote() {
assert_eq!(
read("the 'real|Reality' motive"),
- r#"the 'real ' motive
"#,
+ concat!(
+ r#"the 'real ' motive
"#,
+ )
);
}
@@ -449,7 +546,10 @@ mod tests {
fn anchor_with_leading_double_quote() {
assert_eq!(
read(r#"the "real|Reality" motive"#),
- r#"the "real " motive
"#,
+ concat!(
+ r#"the "real " motive
"#,
+ )
);
}
@@ -457,7 +557,10 @@ mod tests {
fn anchor_with_leading_parenthesis() {
assert_eq!(
read("her (last|Surname) name"),
- r#"her (last ) name
"#,
+ concat!(
+ r#"her (last ) name
"#,
+ )
);
}
@@ -465,7 +568,10 @@ mod tests {
fn anchor_with_internal_apostrophe() {
assert_eq!(
read("the |lion's mouth|album was released"),
- r#"the lion's mouth was released
"#
+ concat!(
+ r#"the lion's mouth was released
"#,
+ )
);
}
@@ -473,7 +579,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe() {
assert_eq!(
read("they decided to stay at Jane's|YellowHouse that night"),
- r#"they decided to stay at Jane's that night
"#
+ concat!(
+ r#"they decided to stay at Jane's that night
"#,
+ )
);
}
@@ -481,7 +590,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe_at_eoi() {
assert_eq!(
read("they decided to stay at Jane's|YellowHouse"),
- r#"they decided to stay at Jane's
"#
+ concat!(
+ r#"they decided to stay at Jane's
"#,
+ )
);
}
@@ -489,7 +601,10 @@ mod tests {
fn nonleading_anchor_with_internal_apostrophe_at_soi() {
assert_eq!(
read("Jane's|YellowHouse that night"),
- r#"Jane's that night
"#
+ concat!(
+ r#"Jane's that night
"#,
+ )
);
}
@@ -497,7 +612,10 @@ mod tests {
fn anchor_with_internal_double_quotes() {
assert_eq!(
read(r#"the |"real"|Truth motive"#),
- r#"the "real" motive
"#,
+ concat!(
+ r#"the "real" motive
"#,
+ )
);
}
@@ -505,7 +623,10 @@ mod tests {
fn anchor_with_internal_double_quotes_wrapping_spaced_words() {
assert_eq!(
read(r#"the |"bare reality"|Ideology they believed"#),
- r#"the "bare reality" they believed
"#,
+ concat!(
+ r#"the "bare reality" they believed
"#,
+ )
);
}
@@ -513,7 +634,10 @@ mod tests {
fn anchor_with_internal_parenthesis() {
assert_eq!(
read("her |last (name)|Surname was Amad"),
- r#"her last (name) was Amad
"#,
+ concat!(
+ r#"her last (name) was Amad
"#,
+ )
);
}
@@ -521,7 +645,11 @@ mod tests {
fn anchor_with_internal_parenthesis_wrapping_spaced_words() {
assert_eq!(
read("this |truth (though questionable) was fine|Absurd to them "),
- r#"this truth (though questionable) was fine to them
"#
+ concat!(
+ r#"this truth (though questionable) was "#,
+ r#"fine to them
"#,
+ )
);
}
}
diff --git a/src/syntax/content/parser/context/block.rs b/src/syntax/content/parser/context/block.rs
index cbf51b2..8048896 100644
--- a/src/syntax/content/parser/context/block.rs
+++ b/src/syntax/content/parser/context/block.rs
@@ -1,17 +1,22 @@
use std::{iter::Peekable, slice::Iter};
use crate::{
+ graph::Graph,
prelude::*,
syntax::content::{
Parseable as _,
parser::{
- Block, Token, Lexeme, State,
- token::{Header, List, Literal, Paragraph, PreFormat},
+ Block, Lexeme, State, Token, context,
+ token::{
+ Header, LineBreak, List, Paragraph, PreFormat, Quote, Table,
+ Verse,
+ },
},
},
- graph::Graph,
};
+/// A return of `true` will trigger a `continue` on the outer parser, causing
+/// no more subsequent parsing of the current lexeme.
pub fn parse(
lexeme: &Lexeme,
state: &mut State,
@@ -24,8 +29,7 @@ pub fn parse(
if PreFormat::probe(lexeme) {
log!(VERBOSE, "Block Context: None -> PreFormat on {lexeme}");
state.context.block = Block::PreFormat;
- tokens.push(Token::PreFormat(PreFormat::new(true)));
- return true;
+ return true
} else if Header::probe(lexeme) {
let mut header = Header::lex(lexeme);
header.dom_id = Some(Header::make_id(
@@ -41,9 +45,26 @@ pub fn parse(
log!(VERBOSE, "Block Context: None -> List on {lexeme}");
state.context.block = Block::List;
state.buffers.list.candidate.ordered = lexeme.match_char('+');
- return super::list::parse(
+ return context::list::parse(
lexeme, state, tokens, iterator, graph,
);
+ } else if Quote::probe(lexeme) {
+ log!(VERBOSE, "Block Context: None -> Quote on {lexeme}");
+ state.context.block = Block::Quote;
+ iterator.next();
+ return true;
+ } else if Verse::probe(lexeme) {
+ log!(VERBOSE, "Block Context: None -> Verse on {lexeme}");
+ state.context.block = Block::Verse;
+ tokens.push(Token::Verse(Verse::new(true)));
+ iterator.next();
+ iterator.next();
+ return true;
+ } else if Table::probe(lexeme) {
+ log!(VERBOSE, "Block Context: None -> Table on {lexeme}");
+ state.context.block = Block::Table;
+ iterator.next();
+ return true;
} else if Paragraph::probe(lexeme) {
log!(VERBOSE, "Block Context: None -> Paragraph on {lexeme}");
state.context.block = Block::Paragraph;
@@ -51,14 +72,7 @@ pub fn parse(
}
},
Block::PreFormat => {
- if PreFormat::probe(lexeme) {
- tokens.push(Token::PreFormat(PreFormat::new(false)));
- log!(VERBOSE, "Block Context: PreFormat -> None on {lexeme}");
- state.context.block = Block::None;
- } else {
- tokens.push(Token::Literal(Literal::lex(lexeme)));
- }
- return true;
+ return context::preformat::parse(lexeme, state, tokens, iterator);
},
Block::Paragraph => {
if Paragraph::probe_end(lexeme) {
@@ -75,7 +89,30 @@ pub fn parse(
}
},
Block::List => {
- return super::list::parse(lexeme, state, tokens, iterator, graph);
+ return context::list::parse(lexeme, state, tokens, iterator, graph);
+ },
+ Block::Quote => {
+ return context::quote::parse(
+ lexeme, state, tokens, iterator, graph,
+ );
+ },
+ Block::Table => {
+ return context::table::parse(
+ lexeme, state, tokens, iterator, graph,
+ );
+ },
+ Block::Verse => {
+ if Verse::probe_end(lexeme) {
+ tokens.push(Token::Verse(Verse::new(false)));
+ log!(VERBOSE, "Block Context: Verse -> None on {lexeme}");
+ state.context.block = Block::None;
+ iterator.next();
+ iterator.next();
+ return true;
+ } else if lexeme.match_char('\n') {
+ tokens.push(Token::LineBreak(LineBreak));
+ return true;
+ }
},
}
false
@@ -85,16 +122,14 @@ pub fn parse(
mod tests {
use crate::{
- syntax::content::parser::{
- self, Block, Token, context, State,
- token::{Header, header::Level, PreFormat},
- },
graph::Graph,
+ syntax::content::parser::{
+ self, Block, State, Token, context,
+ token::{Header, header::Level},
+ },
};
- fn read(input: &str) -> String {
- parser::read(input, &Graph::default())
- }
+ fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn pre() {
@@ -124,16 +159,6 @@ mod tests {
assert_eq!(vec, vec![Token::Header(Header::from_u8(1, false, None))]);
}
- #[test]
- fn end_with_open_preformat() {
- let mut state = State::default();
- state.context.block = Block::PreFormat;
-
- let mut vec: Vec = vec![];
- context::close(&state, &mut vec);
- assert_eq!(vec, vec![Token::PreFormat(PreFormat::new(false))]);
- }
-
#[test]
fn truncated_header_level() {
let u: usize = 999;
diff --git a/src/syntax/content/parser/context/inline.rs b/src/syntax/content/parser/context/inline.rs
index 27c4675..1f2d208 100644
--- a/src/syntax/content/parser/context/inline.rs
+++ b/src/syntax/content/parser/context/inline.rs
@@ -1,17 +1,16 @@
use std::{iter::Peekable, slice::Iter};
use crate::{
+ graph::Graph,
prelude::*,
syntax::content::{
Parseable as _,
parser::{
- Lexeme, State,
+ Inline, Lexeme, State, Token, context,
state::AnchorBuffer,
- Inline, context, Token,
token::{Anchor, Code, Literal},
},
},
- graph::Graph,
};
pub fn parse(
@@ -49,11 +48,10 @@ pub fn parse(
log!(VERBOSE, "Inline Context: Code -> None on {lexeme}");
state.context.inline = Inline::None;
tokens.push(Token::Code(Code::new(false)));
- return true;
} else {
tokens.push(Token::Literal(Literal::lex(lexeme)));
- return true;
}
+ return true;
},
Inline::Anchor => {
if context::anchor::parse(lexeme, state, tokens, graph) {
diff --git a/src/syntax/content/parser/context/list.rs b/src/syntax/content/parser/context/list.rs
index 415c0ea..ec53148 100644
--- a/src/syntax/content/parser/context/list.rs
+++ b/src/syntax/content/parser/context/list.rs
@@ -1,11 +1,11 @@
use std::{iter::Peekable, slice::Iter};
use crate::{
+ graph::Graph,
prelude::*,
syntax::content::parser::{
- context::Block, Token, Lexeme, State, state, token::Item, format,
+ Lexeme, State, Token, context::Block, format, state, token::Item,
},
- graph::Graph,
};
/// Handles open list contexts until a list is fully parsed.
@@ -13,6 +13,9 @@ use crate::{
/// A return of `true` will trigger a continue in the outer parser,
/// skipping any further parsing of the current lexeme.
///
+/// Performs checked arithmetic to the following effect:
+/// - The indent of list items will saturate at `u8::MAX` (255) spaces.
+///
/// # Panics
/// This parser can handle only the List context, and will panic if passed an
/// unrelated context since it has no knowledge on how to handle them.
@@ -27,6 +30,7 @@ pub fn parse(
let candidate = &mut buffer.candidate;
let item_candidate = &mut buffer.item_candidate;
+ #[expect(clippy::wildcard_enum_match_arm)]
match state.context.block {
Block::List => {
if lexeme.match_char(' ') && item_candidate.depth.is_none() {
@@ -74,10 +78,7 @@ pub fn parse(
item_candidate.text.push_str(&lexeme.text());
}
},
- Block::None
- | Block::Paragraph
- | Block::Header(_)
- | Block::PreFormat => {
+ _ => {
panic!("List context parser called to handle non-list context")
},
}
@@ -87,13 +88,11 @@ pub fn parse(
#[cfg(test)]
mod tests {
use crate::{
- syntax::content::parser::{self, context::list::parse, Lexeme, State},
graph::Graph,
+ syntax::content::parser::{self, Lexeme, State, context::list::parse},
};
- fn read(input: &str) -> String {
- parser::read(input, &Graph::default())
- }
+ fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn unordered_list() {
diff --git a/src/syntax/content/parser/context/preformat.rs b/src/syntax/content/parser/context/preformat.rs
new file mode 100644
index 0000000..ed6763f
--- /dev/null
+++ b/src/syntax/content/parser/context/preformat.rs
@@ -0,0 +1,61 @@
+use std::{iter::Peekable, slice::Iter};
+
+use crate::{
+ prelude::*,
+ syntax::content::{
+ Parseable as _,
+ parser::{Lexeme, State, Token, context::Block, token::PreFormat},
+ },
+};
+
+/// Handles open `PreFormat` contexts until a block is fully parsed.
+///
+/// A return of `true` will trigger a continue in the outer parser,
+/// skipping any further parsing of the current lexeme.
+///
+/// # Panics
+/// This parser can handle only the List context, and will panic if passed an
+/// unrelated context since it has no knowledge on how to handle them.
+pub fn parse(
+ lexeme: &Lexeme,
+ state: &mut State,
+ tokens: &mut Vec,
+ iterator: &mut Peekable>,
+) -> bool {
+ let buffer = &mut state.buffers.preformat;
+ let candidate = &mut buffer.candidate;
+
+ #[expect(clippy::wildcard_enum_match_arm)]
+ match state.context.block {
+ Block::PreFormat => {
+ if lexeme.match_first_char('<') {
+ candidate.text.push_str("<");
+ candidate.text.push_str(
+ lexeme.text().strip_prefix('<').unwrap_or(&lexeme.text()),
+ );
+ } else if lexeme.match_last_char('>') {
+ candidate.text.push_str(
+ lexeme.text().strip_suffix('>').unwrap_or(&lexeme.text()),
+ );
+ candidate.text.push_str(">");
+ } else if lexeme.match_char('\\') {
+ candidate.text.push_str(lexeme.next().as_str());
+ iterator.next();
+ return true;
+ } else if PreFormat::probe(lexeme) {
+ // found end of block, push it and reset state
+ log!(VERBOSE, "Accepting preformat candidate {candidate}");
+ tokens.push(Token::PreFormat(candidate.clone()));
+ state.context.block = Block::None;
+ *candidate = PreFormat::default();
+ } else {
+ // anything else is pushed into the candidate preformat's text
+ candidate.text.push_str(&lexeme.text());
+ }
+ },
+ _ => {
+ panic!("PreFormat context parser called for {:?}", state.context)
+ },
+ }
+ true
+}
diff --git a/src/syntax/content/parser/context/quote.rs b/src/syntax/content/parser/context/quote.rs
new file mode 100644
index 0000000..8b46c22
--- /dev/null
+++ b/src/syntax/content/parser/context/quote.rs
@@ -0,0 +1,92 @@
+use std::{iter::Peekable, slice::Iter};
+
+use crate::{
+ graph::Graph,
+ prelude::*,
+ syntax::content::parser::{
+ Lexeme, State, Token, context::Block, format, state, token::Quote,
+ },
+};
+
+/// Handles open quote contexts until a quote is fully parsed.
+///
+/// A return of `true` will trigger a continue in the outer parser,
+/// skipping any further parsing of the current lexeme.
+///
+/// # Panics
+/// This parser can handle only the Quote context, and will panic if passed an
+/// unrelated context since it has no knowledge on how to handle them.
+pub fn parse(
+ lexeme: &Lexeme,
+ state: &mut State,
+ tokens: &mut Vec,
+ iterator: &mut Peekable>,
+ graph: &Graph,
+) -> bool {
+ let buffer = &mut state.buffers.quote;
+ let candidate = &mut buffer.candidate;
+
+ #[expect(clippy::wildcard_enum_match_arm)]
+ match state.context.block {
+ Block::Quote => {
+ if Quote::probe_end(lexeme) {
+ log!(VERBOSE, "Probed end of quote on {lexeme}");
+ let (text, text_tokens) = format(&candidate.text, graph);
+ candidate.text = text;
+ state.format_tokens.extend_from_slice(&text_tokens);
+
+ if let Some(citation) = &candidate.citation {
+ let (formatted_citation, citation_tokens) =
+ format(citation, graph);
+ candidate.citation = Some(formatted_citation);
+ state.format_tokens.extend_from_slice(&citation_tokens);
+
+ if let Some(url) = citation_tokens.into_iter().find_map(
+ |token| match token {
+ Token::Anchor(a) if a.external() => a.destination(),
+ _ => None,
+ },
+ ) {
+ candidate.url = Some(url);
+ }
+ }
+
+ tokens.push(Token::Quote(candidate.clone()));
+ log!(VERBOSE, "Block Context: Quote -> None on {lexeme}");
+ state.context.block = Block::None;
+ *buffer = state::QuoteBuffer::default();
+ } else if !buffer.in_citation
+ && lexeme.match_char('\n')
+ && lexeme.next() == "--"
+ {
+ log!(VERBOSE, "Matched citation start on {lexeme}");
+ buffer.in_citation = true;
+ iterator.next();
+ iterator.next();
+ } else if lexeme.match_char_sequence('\n', '>') {
+ log!(VERBOSE, "Matched break-aware sequence on {lexeme}");
+ candidate.text.push_str(" <\n");
+ iterator.next();
+ } else {
+ log!(VERBOSE, "Entered quote else branch on {lexeme}");
+ if buffer.in_citation {
+ log!(VERBOSE, "Extending citation on {lexeme}");
+ candidate.extend_citation(&lexeme.text());
+ if lexeme.match_char('\n') && lexeme.next() == "--" {
+ candidate.text.push('\n');
+ iterator.next();
+ } else if lexeme.match_char('\n') {
+ buffer.in_citation = false;
+ }
+ } else {
+ log!(VERBOSE, "Extending quote on {lexeme}");
+ candidate.text.push_str(&lexeme.text());
+ }
+ }
+ },
+ _ => {
+ panic!("Quote context parser called to handle non-quote context")
+ },
+ }
+ true
+}
diff --git a/src/syntax/content/parser/context/table.rs b/src/syntax/content/parser/context/table.rs
new file mode 100644
index 0000000..40ca217
--- /dev/null
+++ b/src/syntax/content/parser/context/table.rs
@@ -0,0 +1,447 @@
+use std::{iter::Peekable, slice::Iter};
+
+use crate::{
+ graph::Graph,
+ prelude::*,
+ syntax::content::parser::{
+ Lexeme, State, Token, context::Block, format, state, token::Table,
+ },
+};
+
+/// Handles open table contexts until a table is fully parsed.
+///
+/// A return of `true` will trigger a continue in the outer parser,
+/// skipping any further parsing of the current lexeme.
+///
+/// # Panics
+/// This parser can handle only the Table context, and will panic if passed an
+/// unrelated context since it has no knowledge on how to handle them.
+pub fn parse(
+ lexeme: &Lexeme,
+ state: &mut State,
+ tokens: &mut Vec,
+ iterator: &mut Peekable>,
+ graph: &Graph,
+) -> bool {
+ let buffer = &mut state.buffers.table;
+ let candidate = &mut buffer.candidate;
+
+ let mut parse_text = |text: &str| {
+ let (parsed_text, text_tokens) = format(text, graph);
+ state.format_tokens.extend_from_slice(&text_tokens);
+ parsed_text
+ };
+
+ #[expect(clippy::wildcard_enum_match_arm)]
+ match state.context.block {
+ Block::Table => {
+ if Table::probe_end(lexeme) {
+ log!(VERBOSE, "Probed end of table on {lexeme}");
+
+ if buffer.in_header {
+ log!(VERBOSE, "Adding unterminated header: {lexeme}");
+ candidate.add_header(&parse_text(&buffer.cell));
+ } else {
+ let descriptor = if buffer.in_cell {
+ "unterminated"
+ } else {
+ "undelimited"
+ };
+ log!(VERBOSE, "Adding {descriptor} cell: {lexeme}");
+ candidate.add_cell(&parse_text(&buffer.cell));
+ }
+
+ tokens.push(Token::Table(candidate.clone()));
+ log!(VERBOSE, "Block Context: Table -> None on {lexeme}");
+ state.context.block = Block::None;
+ *buffer = state::TableBuffer::default();
+ iterator.next();
+ } else if lexeme.match_char('\n')
+ || lexeme.match_char_triple(' ', '!', '\n')
+ || lexeme.match_char_triple(' ', '|', '\n')
+ {
+ log!(VERBOSE, "Adding row: found newline on {lexeme}");
+
+ if !buffer.cell.is_empty() {
+ if buffer.in_header {
+ log!(VERBOSE, "Adding unterminated header: {lexeme}");
+ candidate.add_header(&parse_text(&buffer.cell));
+ } else {
+ let descriptor = if buffer.in_cell {
+ "unterminated"
+ } else {
+ "undelimited"
+ };
+ log!(VERBOSE, "Adding {descriptor} cell: {lexeme}");
+ candidate.add_cell(&parse_text(&buffer.cell));
+ }
+ buffer.cell.clear();
+ }
+
+ if lexeme.match_next_either_char('|', '!') {
+ iterator.next();
+ }
+
+ buffer.in_header = false;
+ buffer.in_cell = false;
+ candidate.add_row(vec![]);
+ } else if lexeme.match_char_triple(' ', '!', ' ') {
+ buffer.in_header = true;
+ if !buffer.cell.trim().is_empty() {
+ log!(VERBOSE, "Adding header: found spaced ! on {lexeme}");
+ candidate.add_header(&parse_text(&buffer.cell));
+ buffer.cell.clear();
+ }
+ iterator.next();
+ iterator.next();
+ } else if lexeme.match_char_triple(' ', '|', ' ') {
+ buffer.in_cell = true;
+ if !buffer.cell.trim().is_empty() {
+ log!(VERBOSE, "Adding cell: found spaced | on {lexeme}");
+ candidate.add_cell(&parse_text(&buffer.cell));
+ buffer.cell.clear();
+ }
+ iterator.next();
+ iterator.next();
+ } else {
+ log!(VERBOSE, "Extending cell text on {lexeme}");
+ buffer.cell.push_str(lexeme.text().as_str());
+ }
+ },
+ _ => {
+ panic!("Table context parser called to handle non-table context")
+ },
+ }
+ true
+}
+
+#[cfg(test)]
+mod tests {
+ use crate::{graph::Graph, syntax::content::parser};
+
+ fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
+
+ fn read_loaded(input: &str) -> String {
+ parser::read(input, &Graph::load())
+ }
+
+ #[test]
+ fn single_row() {
+ assert_eq!(
+ read(concat!("%", "\n", "a | b | c", "\n", "%", "\n")),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn two_rows() {
+ assert_eq!(
+ read(concat!(
+ "%", "\n",
+ "a | b | c", "\n",
+ "d | e | f", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn three_rows() {
+ assert_eq!(
+ read(concat!(
+ "%", "\n",
+ "a | b | c", "\n",
+ "d | e | f", "\n",
+ "g | h | i", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn with_header() {
+ assert_eq!(
+ read(concat!(
+ "%", "\n",
+ "hA ! hB ! hC", "\n",
+ "a | b | c", "\n",
+ "d | e | f", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " hA ", "\n",
+ " hB ", "\n",
+ " hC ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn with_anchor() {
+ assert_eq!(
+ read(concat!(
+ "%", "\n",
+ "a | |Node| | c", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ r#" Node "#, "\n",
+ " c ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn with_loaded_anchor() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ "a | |Node| | c", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ r#" Node "#, "\n",
+ " c ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn no_leading_delimiters() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ "a ! b ! c !", "\n",
+ "d | e | f |", "\n",
+ "g | h | i |", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn no_trailing_delimiters() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ " ! a ! b ! c", "\n",
+ " | d | e | f", "\n",
+ " | g | h | i", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn with_leading_and_trailing_delimiters() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ " ! a ! b ! c !", "\n",
+ " | d | e | f |", "\n",
+ " | g | h | i |", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn no_flanking_delimiters() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ "a ! b ! c", "\n",
+ "d | e | f", "\n",
+ "g | h | i", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+
+ #[test]
+ fn with_indent() {
+ assert_eq!(
+ read_loaded(concat!(
+ "%", "\n",
+ " ! a ! b ! c !", "\n",
+ " | d | e | f |", "\n",
+ " | g | h | i |", "\n",
+ "%", "\n",
+ )),
+ concat!(
+ "\n",
+ "", "\n",
+ " ", "\n",
+ " a ", "\n",
+ " b ", "\n",
+ " c ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " d ", "\n",
+ " e ", "\n",
+ " f ", "\n",
+ " ", "\n",
+ " ", "\n",
+ " g ", "\n",
+ " h ", "\n",
+ " i ", "\n",
+ " ", "\n",
+ "
", "\n",
+ )
+ );
+ }
+}
diff --git a/src/syntax/content/parser/lexeme.rs b/src/syntax/content/parser/lexeme.rs
index acaf378..94b28d5 100644
--- a/src/syntax/content/parser/lexeme.rs
+++ b/src/syntax/content/parser/lexeme.rs
@@ -1,6 +1,6 @@
use std::fmt;
-use crate::{syntax::content::parser::segment::delimiter::Delimiters};
+use crate::syntax::content::parser::segment::delimiter::Delimiters;
#[derive(Clone, Debug, Default)]
pub struct Lexeme {
@@ -22,26 +22,18 @@ impl Lexeme {
}
}
- pub fn text(&self) -> String {
- self.text.clone()
- }
+ pub fn text(&self) -> String { self.text.clone() }
- pub fn next(&self) -> String {
- self.next.clone()
- }
+ pub fn next(&self) -> String { self.next.clone() }
- pub fn last(&self) -> bool {
- self.last
- }
+ pub const fn last(&self) -> bool { self.last }
- pub fn first(&self) -> bool {
- self.first
- }
+ pub const fn first(&self) -> bool { self.first }
- pub fn mutate_text(&mut self, new: &str) {
- self.text = new.to_string();
- }
+ pub fn mutate_text(&mut self, new: &str) { self.text = new.to_string(); }
+ /// Returns an Option containing the character if the raw lexeme text
+ /// is composed of a single character, None if it has multiple characters.
pub fn as_char(&self) -> Option {
if self.text.chars().count() == 1 {
self.text.chars().nth(0)
@@ -66,6 +58,7 @@ impl Lexeme {
}
}
+ /// Returns true if the raw lexeme text is a single matching character.
pub fn match_char(&self, c: char) -> bool {
self.as_char().is_some_and(|as_char| as_char == c)
}
@@ -96,6 +89,8 @@ impl Lexeme {
&& self.match_third_char(c3)
}
+ /// Returns true if the lexeme raw text is composed of a single character
+ /// and this character is in the provided slice.
pub fn match_char_in(&self, slice: &[char]) -> bool {
self.as_char().is_some_and(|c| slice.contains(&c))
}
@@ -141,9 +136,7 @@ impl Lexeme {
.is_some_and(|c| delimiters.is_delimiter(c))
}
- pub fn next_first_char(&self) -> Option {
- self.next.chars().nth(0)
- }
+ pub fn next_first_char(&self) -> Option { self.next.chars().nth(0) }
pub fn match_first_char(&self, query: char) -> bool {
self.text.chars().nth(0).is_some_and(|c| c == query)
@@ -158,7 +151,7 @@ impl Lexeme {
}
/// # Panics
- /// Panics if number of chars for a single lexeme exceeds `i32::MAX`
+ /// Panics if number of chars for a single lexeme exceeds `i32::MAX`.
pub fn count_char(&self, c: char) -> i32 {
let count = self.text().chars().filter(|&n| n == c).count();
match i32::try_from(count) {
@@ -236,7 +229,7 @@ impl Lexeme {
impl fmt::Display for Lexeme {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- use crate::log::wrap;
+ use crate::dev::log::wrap;
let properties = if self.last && self.first {
"[S] "
@@ -298,7 +291,7 @@ mod tests {
fn first_segment() {
let payload = "nhNc fGev QnGW E4hj ExyZ";
let lexeme = Lexeme::new(payload, "", "");
- assert_eq!(lexeme.clone().first_segment(), Some(String::from("nhNc")));
+ assert_eq!(lexeme.first_segment(), Some(String::from("nhNc")));
}
#[test]
@@ -393,8 +386,8 @@ mod tests {
let lexemes = Lexeme::collect(&input);
let first = lexemes.first().unwrap();
- let second = lexemes.get(1).unwrap();
- let third = lexemes.get(2).unwrap();
+ let second = &lexemes[1];
+ let third = &lexemes[2];
let last = lexemes.last().unwrap();
assert_eq!(
diff --git a/src/syntax/content/parser/lexer.rs b/src/syntax/content/parser/lexer.rs
new file mode 100644
index 0000000..e8d3abc
--- /dev/null
+++ b/src/syntax/content/parser/lexer.rs
@@ -0,0 +1,93 @@
+use crate::{
+ graph::Graph,
+ prelude::*,
+ syntax::content::{
+ LexMap, Parseable as _, TokenOutput,
+ parser::{
+ context,
+ lexeme::Lexeme,
+ point, segment,
+ state::State,
+ token::{LineBreak, Literal, Token},
+ },
+ },
+};
+
+pub(super) const LEXMAP: LexMap = &[
+ (LineBreak::probe, |lexeme| {
+ Token::LineBreak(LineBreak::lex(lexeme))
+ }),
+ (Literal::probe, |lexeme| {
+ Token::Literal(Literal::lex(lexeme))
+ }),
+];
+
+pub(super) fn lex(
+ text: &str,
+ map: LexMap,
+ graph: &Graph,
+ blocking: bool,
+) -> TokenOutput {
+ let mut tokens: Vec = Vec::default();
+ let mut state = State::default();
+
+ let segments = segment::segment(text);
+ let lexemes = Lexeme::collect(&segments);
+
+ log!(VERBOSE, "Segments: {segments:?}");
+
+ let mut iterator = lexemes.iter().peekable();
+ while let Some(lexeme) = iterator.next() {
+ if lexeme.match_char('\\')
+ && !matches!(state.context.block, context::Block::PreFormat)
+ {
+ if let Some(next) = iterator.next() {
+ tokens.push(Token::Literal(Literal::lex(next)));
+ }
+ continue;
+ }
+
+ if blocking {
+ if context::block::parse(
+ lexeme,
+ &mut state,
+ &mut tokens,
+ &mut iterator,
+ graph,
+ ) {
+ continue;
+ }
+ }
+
+ if point::parse(lexeme, &mut state, &mut tokens, &mut iterator) {
+ continue;
+ }
+
+ if context::inline::parse(
+ lexeme,
+ &mut state,
+ &mut tokens,
+ &mut iterator,
+ graph,
+ ) {
+ continue;
+ }
+
+ for (probe, lex) in map {
+ if probe(lexeme) {
+ let token = lex(lexeme);
+ log!(VERBOSE, "Lexmap lexed {lexeme} into {token}");
+ tokens.push(token);
+ break;
+ }
+ }
+ }
+
+ context::close(&state, &mut tokens);
+
+ TokenOutput {
+ tokens,
+ format_tokens: state.format_tokens,
+ text: None,
+ }
+}
diff --git a/src/syntax/content/parser/point.rs b/src/syntax/content/parser/point.rs
index 38aaec0..6c0b832 100644
--- a/src/syntax/content/parser/point.rs
+++ b/src/syntax/content/parser/point.rs
@@ -17,9 +17,9 @@ pub fn parse(
tokens: &mut Vec,
iterator: &mut Peekable>,
) -> bool {
- if let super::context::Block::PreFormat = state.context.block {
- return false;
- } else if let super::context::Inline::Code = state.context.inline {
+ if matches!(state.context.block, super::context::Block::PreFormat)
+ || matches!(state.context.inline, super::context::Inline::Code)
+ {
return false;
}
@@ -58,17 +58,18 @@ pub fn parse(
#[cfg(test)]
mod tests {
- use crate::{syntax::content::parser, graph::Graph};
+ use crate::{graph::Graph, syntax::content::parser};
- fn read(input: &str) -> String {
- parser::read(input, &Graph::default())
- }
+ fn read(input: &str) -> String { parser::read(input, &Graph::default()) }
#[test]
fn oblique_anchor() {
assert_eq!(
read("w _|S|_ w"),
- r#"w S w
"#
+ concat!(
+ r#"w S w
"#,
+ )
);
}
@@ -76,7 +77,8 @@ mod tests {
fn oblique_anchor_with_trailing_comma() {
assert_eq!(
read("w _|S|_, w"),
- r#"w S , w
"#
+ concat!(r#"w S , w
"#)
);
}
@@ -84,9 +86,17 @@ mod tests {
fn oblique() {
assert_eq!(
read(
- "_|this anchor is oblique|o as are these literals_ but not these _just these_, not this _and these with an |anc80r| again_"
+ "_|this anchor is oblique|o as are these literals_ but not \
+ these _just these_, not this _and these with an |anc80r| \
+ again_"
),
- r#"this anchor is oblique as are these literals but not these just these , not this and these with an anc80r again
"#
+ concat!(
+ r#""#,
+ r#"this anchor is oblique as are these literals "#,
+ r#"but not these just these , not this and these "#,
+ r#"with an anc80r again
"#,
+ )
);
}
diff --git a/src/syntax/content/parser/segment.rs b/src/syntax/content/parser/segment.rs
index 8a8ea76..1ee853e 100644
--- a/src/syntax/content/parser/segment.rs
+++ b/src/syntax/content/parser/segment.rs
@@ -1,6 +1,4 @@
-pub fn segment(text: &str) -> Vec {
- delimiter::atomize(text)
-}
+pub fn segment(text: &str) -> Vec { delimiter::atomize(text) }
pub mod delimiter {
@@ -146,7 +144,8 @@ pub mod delimiter {
fn atomize_flankign_sentence() {
assert_eq!(
atomize(
- "about_colors: the colors _amber_, _orange_ and _yellow mustard_ to `jane_bishop@mail.com`."
+ "about_colors: the colors _amber_, _orange_ and \
+ _yellow mustard_ to `jane_bishop@mail.com`."
),
vec![
"about_colors",
@@ -188,7 +187,8 @@ pub mod delimiter {
#[test]
fn atomize_words() {
let actual = atomize(
- " justification for the actions of those who hold authority inevitably dwindles ",
+ " justification for the actions of those who hold \
+ authority inevitably dwindles ",
);
let expected = vec![
" ",
@@ -285,7 +285,8 @@ pub mod delimiter {
#[test]
fn atomize_pipes_and_ticks() {
let actual = atomize(
- "every other |time| as `it could or |perhaps somehow|then or now| it was` perceived",
+ "every other |time| as `it could or |perhaps somehow|then or \
+ now| it was` perceived",
);
let expected = vec![
"every",
diff --git a/src/syntax/content/parser/state.rs b/src/syntax/content/parser/state.rs
index 851b0e7..47498a3 100644
--- a/src/syntax/content/parser/state.rs
+++ b/src/syntax/content/parser/state.rs
@@ -2,11 +2,11 @@ use std::collections::HashMap;
use crate::syntax::content::parser::{
Token,
- context::{Block, Context, Inline},
- token::{Anchor, Item, List},
+ context::Context,
+ token::{Anchor, Item, List, PreFormat, Quote, Table},
};
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub struct State {
pub context: Context,
pub dom_ids: HashMap>,
@@ -15,7 +15,7 @@ pub struct State {
pub format_tokens: Vec,
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub struct Switches {
pub bold: bool,
pub oblique: bool,
@@ -23,10 +23,13 @@ pub struct Switches {
pub underline: bool,
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Default, Debug)]
pub struct Buffers {
pub anchor: AnchorBuffer,
pub list: ListBuffer,
+ pub quote: QuoteBuffer,
+ pub table: TableBuffer,
+ pub preformat: PreFormatBuffer,
}
#[derive(Default, Clone, Debug)]
@@ -43,6 +46,25 @@ pub struct AnchorBuffer {
pub destination: String,
}
+#[derive(Default, Clone, Debug)]
+pub struct QuoteBuffer {
+ pub candidate: Quote,
+ pub in_citation: bool,
+}
+
+#[derive(Default, Clone, Debug)]
+pub struct TableBuffer {
+ pub candidate: Table,
+ pub cell: String,
+ pub in_cell: bool,
+ pub in_header: bool,
+}
+
+#[derive(Default, Clone, Debug)]
+pub struct PreFormatBuffer {
+ pub candidate: PreFormat,
+}
+
impl std::fmt::Display for AnchorBuffer {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let display_text = if self.text.is_empty() {
@@ -67,37 +89,6 @@ impl std::fmt::Display for AnchorBuffer {
}
}
-impl Default for State {
- fn default() -> State {
- State {
- context: Context {
- inline: Inline::None,
- block: Block::None,
- },
- dom_ids: HashMap::default(),
- switches: Switches {
- bold: false,
- crossout: false,
- oblique: false,
- underline: false,
- },
- buffers: Buffers {
- anchor: AnchorBuffer {
- candidate: Anchor::default(),
- text: String::default(),
- destination: String::default(),
- },
- list: ListBuffer {
- candidate: List::default(),
- item_candidate: Item::default(),
- depth: 0,
- },
- },
- format_tokens: vec![],
- }
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -116,24 +107,24 @@ mod tests {
#[test]
fn anchor_buffer_display_with_text_set() {
let mut buffer = AnchorBuffer::default();
- buffer.text = String::from("mX8Z7yWmsK");
+ buffer.text = String::from("mX8Z7sK");
println!("{buffer:#?}");
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
- r#"AnchorBuffer [text: "mX8Z7yWmsK"] >> Anchor -> "#
+ r#"AnchorBuffer [text: "mX8Z7sK"] >> Anchor -> "#
);
}
#[test]
fn anchor_buffer_display_with_destination_set() {
let mut buffer = AnchorBuffer::default();
- buffer.destination = String::from("VP2aqGngAq");
+ buffer.destination = String::from("VP2gAq");
println!("{buffer:#?}");
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
- r#"AnchorBuffer [, dest: "VP2aqGngAq"] >> Anchor -> "#
+ r#"AnchorBuffer [, dest: "VP2gAq"] >> Anchor -> "#
);
}
@@ -146,7 +137,10 @@ mod tests {
println!("{buffer}");
assert_eq!(
format!("{buffer}"),
- r#"AnchorBuffer [text: "ECJrzgkBHg", dest: "9dy6gQ2g3E"] >> Anchor -> "#
+ concat!(
+ r#"AnchorBuffer [text: "ECJrzgkBHg", dest: "9dy6gQ2g3E"] "#,
+ r#">> Anchor -> "#,
+ )
);
}
}
diff --git a/src/syntax/content/parser/token.rs b/src/syntax/content/parser/token.rs
index 85ddee5..a1f9a70 100644
--- a/src/syntax/content/parser/token.rs
+++ b/src/syntax/content/parser/token.rs
@@ -12,15 +12,29 @@ pub mod literal;
pub mod oblique;
pub mod paragraph;
pub mod preformat;
+pub mod quote;
pub mod strike;
+pub mod table;
pub mod underline;
+pub mod verse;
-pub use {
- anchor::Anchor, bold::Bold, checkbox::CheckBox, code::Code, header::Header,
- item::Item, linebreak::LineBreak, list::List, literal::Literal,
- oblique::Oblique, paragraph::Paragraph, preformat::PreFormat,
- strike::Strike, underline::Underline,
-};
+pub use anchor::Anchor;
+pub use bold::Bold;
+pub use checkbox::CheckBox;
+pub use code::Code;
+pub use header::Header;
+pub use item::Item;
+pub use linebreak::LineBreak;
+pub use list::List;
+pub use literal::Literal;
+pub use oblique::Oblique;
+pub use paragraph::Paragraph;
+pub use preformat::PreFormat;
+pub use quote::Quote;
+pub use strike::Strike;
+pub use table::Table;
+pub use underline::Underline;
+pub use verse::Verse;
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum Token {
@@ -37,7 +51,10 @@ pub enum Token {
Oblique(Oblique),
Paragraph(Paragraph),
PreFormat(PreFormat),
+ Quote(Quote),
+ Table(Table),
Underline(Underline),
+ Verse(Verse),
}
impl Token {
@@ -56,7 +73,10 @@ impl Token {
Token::Oblique(d) => d.render(),
Token::Paragraph(d) => d.render(),
Token::PreFormat(d) => d.render(),
+ Token::Quote(d) => d.render(),
+ Token::Table(d) => d.render(),
Token::Underline(d) => d.render(),
+ Token::Verse(d) => d.render(),
}
}
@@ -75,7 +95,10 @@ impl Token {
Token::Oblique(d) => d.flatten(),
Token::Paragraph(d) => d.flatten(),
Token::PreFormat(d) => d.flatten(),
+ Token::Quote(d) => d.flatten(),
+ Token::Table(d) => d.flatten(),
Token::Underline(d) => d.flatten(),
+ Token::Verse(d) => d.flatten(),
}
}
}
@@ -96,7 +119,10 @@ impl std::fmt::Display for Token {
Token::Oblique(d) => format!("{d}"),
Token::Paragraph(d) => format!("{d}"),
Token::PreFormat(d) => format!("{d}"),
+ Token::Quote(d) => format!("{d}"),
+ Token::Table(d) => format!("{d}"),
Token::Underline(d) => format!("{d}"),
+ Token::Verse(d) => format!("{d}"),
};
write!(f, "Tk:{data}")
diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs
index 94aac28..556ac42 100644
--- a/src/syntax/content/parser/token/anchor.rs
+++ b/src/syntax/content/parser/token/anchor.rs
@@ -1,6 +1,6 @@
use crate::{
- syntax::content::{Parseable, parser::Lexeme},
graph::Node,
+ syntax::content::{Parseable, parser::Lexeme},
};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
@@ -11,85 +11,54 @@ pub struct Anchor {
node: Option,
leading: bool,
balanced: bool,
+ absolute: bool,
external: bool,
}
impl Anchor {
- pub fn new(
- text: &str,
- destination: &str,
- node: Option,
- node_id: Option,
- leading: bool,
- external: bool,
- balanced: bool,
- ) -> Anchor {
- let mut anchor = Anchor {
- text: text.to_owned(),
- destination: Some(String::from(destination)),
- node,
- node_id,
- leading,
- external,
- balanced,
- };
+ pub fn text(&self) -> String { self.text.clone() }
- anchor.route();
- anchor
- }
+ pub fn set_text(&mut self, text: &str) { self.text = String::from(text); }
- pub fn text(&self) -> String {
- self.text.clone()
- }
+ pub fn text_push(&mut self, text: &str) { self.text.push_str(text); }
- pub fn set_text(&mut self, text: &str) {
- self.text = String::from(text);
- }
-
- pub fn text_push(&mut self, text: &str) {
- self.text.push_str(text);
- }
-
- pub fn destination(&self) -> Option {
- self.destination.clone()
- }
+ pub fn destination(&self) -> Option { self.destination.clone() }
pub fn set_destination(&mut self, destination: Option<&str>) {
self.destination = destination.map(str::to_string);
self.route();
}
- pub fn balanced(&self) -> bool {
- self.balanced
- }
+ pub const fn balanced(&self) -> bool { self.balanced }
- pub fn set_balanced(&mut self, balanced: bool) {
+ pub const fn set_balanced(&mut self, balanced: bool) {
self.balanced = balanced;
}
- pub fn external(&self) -> bool {
- self.external
+ pub const fn absolute(&self) -> bool { self.absolute }
+
+ pub const fn set_absolute(&mut self, absolute: bool) {
+ self.absolute = absolute;
}
- pub fn set_external(&mut self, external: bool) {
+ pub const fn external(&self) -> bool { self.external }
+
+ pub const fn set_external(&mut self, external: bool) {
self.external = external;
+ self.absolute = true;
}
- pub fn set_leading(&mut self, leading: bool) {
+ pub const fn set_leading(&mut self, leading: bool) {
self.leading = leading;
}
- pub fn node(&self) -> Option {
- self.node.clone()
- }
+ pub fn node(&self) -> Option { self.node.clone() }
pub fn set_node(&mut self, node: &Node) {
self.node = Some(node.to_owned());
}
- pub fn node_id(&self) -> Option {
- self.node_id.clone()
- }
+ pub fn node_id(&self) -> Option { self.node_id.clone() }
pub fn set_node_id(&mut self, id: &str) {
self.node_id = Some(id.to_owned());
@@ -97,21 +66,28 @@ impl Anchor {
fn route(&mut self) {
self.destination = if let Some(destination) = self.destination.clone() {
- if destination.contains(":") || destination.contains("/") {
+ if destination.contains(':') || destination.starts_with('/') {
Some(destination)
} else if destination.is_empty() && self.text.is_empty() {
None
} else if destination.is_empty() {
- self.node_id = Some(self.text.clone());
+ self.node_id = Some(Self::strip_fragment(&self.text));
Some(format!("/node/{}", self.text))
} else {
- self.node_id = self.destination.clone();
+ self.node_id = self
+ .destination
+ .clone()
+ .map(|d| Anchor::strip_fragment(&d));
Some(format!("/node/{destination}"))
}
} else {
None
}
}
+
+ fn strip_fragment(target: &str) -> String {
+ target.split('#').next().unwrap_or(target).to_string()
+ }
}
impl Parseable for Anchor {
@@ -128,7 +104,8 @@ impl Parseable for Anchor {
fn render(&self) -> String {
let Some(destination) = &self.destination else {
panic!(
- "Attempt to render anchor {self:#?} without knowing its destination."
+ "Attempt to render anchor {self:#?} without knowing \
+ its destination."
)
};
@@ -138,30 +115,40 @@ impl Parseable for Anchor {
String::default()
};
- let classes = if self.node.is_some() {
- String::from(r#"class="attached""#)
- } else if !self.external {
- String::from(r#"class="detached""#)
- } else if self.external {
+ let classes = if self.external {
String::from(r#"class="external""#)
+ } else if self.absolute {
+ String::from(r#"class="absolute""#)
+ } else if self.node.is_some() {
+ String::from(r#"class="attached""#)
} else {
- String::default()
+ String::from(r#"class="detached""#)
+ };
+
+ let text = if destination.contains('#')
+ && !self.absolute
+ && destination == &format!("/node/{}", self.text)
+ {
+ self.text
+ .split('#')
+ .next()
+ .unwrap_or(&self.text)
+ .to_string()
+ } else {
+ self.text.clone()
};
format!(
- r#"{} "#,
- destination, self.text,
+ r#"{text} "#
)
}
- fn flatten(&self) -> String {
- self.text.clone()
- }
+ fn flatten(&self) -> String { self.text.clone() }
}
impl std::fmt::Display for Anchor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- use crate::log::wrap;
+ use crate::dev::log::wrap;
let wrapped_text = wrap(&self.text);
let display_text = if wrapped_text.is_empty() {
@@ -200,9 +187,8 @@ impl std::fmt::Display for Anchor {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render_anchor() {
@@ -211,7 +197,10 @@ mod tests {
anchor.set_destination(Some("AnchorDest"));
assert_eq!(
anchor.render(),
- r#"AnchorText "#
+ concat!(
+ r#"AnchorText "#,
+ )
);
}
@@ -219,9 +208,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an anchor directly from a lexeme"
)]
- fn lex() {
- Anchor::lex(&Lexeme::default());
- }
+ fn lex() { Anchor::lex(&Lexeme::default()); }
#[test]
#[should_panic(expected = "without knowing its destination")]
@@ -256,7 +243,7 @@ mod tests {
anchor.external = true;
assert_eq!(
- format!("{}", Token::Anchor(Box::new(anchor.clone()))),
+ format!("{}", Token::Anchor(Box::new(anchor))),
"Tk:Anchor 'wPVo1 0OmYm' -> \"M1UEp 1gbfr\" \
+Leading +Balanced +External",
);
@@ -287,4 +274,29 @@ mod tests {
anchor.route(); // set_destination also called this
assert!(anchor.destination().is_none());
}
+
+ #[test]
+ fn set_node_id() {
+ let payload = "kxBDJ0EoDVaygxpZ8NgNdQrUIBsGimTs";
+ let mut anchor = Anchor::default();
+ anchor.set_node_id(payload);
+ assert_eq!(anchor.node_id.unwrap(), payload);
+ }
+
+ #[test]
+ fn display_no_destination() {
+ let anchor = Anchor::default();
+ assert_eq!(format!("{anchor}"), "Anchor -> ");
+ }
+
+ #[test]
+ fn flatten() {
+ let payload = "tpBTViYnldoTqDsB";
+ let mut anchor = Anchor::default();
+ anchor.text = String::from(payload);
+ assert_eq!(anchor.flatten(), payload);
+
+ let token = Token::Anchor(Box::new(anchor));
+ assert_eq!(token.flatten(), payload);
+ }
}
diff --git a/src/syntax/content/parser/token/bold.rs b/src/syntax/content/parser/token/bold.rs
index e2a7efc..6ae041e 100644
--- a/src/syntax/content/parser/token/bold.rs
+++ b/src/syntax/content/parser/token/bold.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Bold {
@@ -8,15 +6,11 @@ pub struct Bold {
}
impl Bold {
- pub fn new(open: bool) -> Bold {
- Bold { open }
- }
+ pub const fn new(open: bool) -> Bold { Bold { open } }
}
impl Parseable for Bold {
- fn probe(lexeme: &Lexeme) -> bool {
- lexeme.text() == "*"
- }
+ fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "*" }
fn lex(_lexeme: &Lexeme) -> Bold {
panic!("Attempt to lex a bold tag directly from a lexeme")
@@ -30,9 +24,7 @@ impl Parseable for Bold {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Bold {
@@ -44,9 +36,8 @@ impl std::fmt::Display for Bold {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a bold tag directly from a lexeme"
)]
- fn lex() {
- Bold::lex(&Lexeme::default());
- }
+ fn lex() { Bold::lex(&Lexeme::default()); }
#[test]
fn token_display() {
@@ -71,9 +60,15 @@ mod tests {
assert_eq!(format!("{}", Token::Bold(bold.clone())), "Tk:Bold [open]");
bold.open = false;
- assert_eq!(
- format!("{}", Token::Bold(bold.clone())),
- "Tk:Bold [closed]"
- );
+ assert_eq!(format!("{}", Token::Bold(bold)), "Tk:Bold [closed]");
+ }
+
+ #[test]
+ fn flatten() {
+ let bold = Bold::new(false);
+ assert_eq!(bold.flatten(), "");
+
+ let token = Token::Bold(bold);
+ assert_eq!(token.flatten(), "");
}
}
diff --git a/src/syntax/content/parser/token/checkbox.rs b/src/syntax/content/parser/token/checkbox.rs
index 656f419..9230af6 100644
--- a/src/syntax/content/parser/token/checkbox.rs
+++ b/src/syntax/content/parser/token/checkbox.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CheckBox {
@@ -8,9 +6,7 @@ pub struct CheckBox {
}
impl CheckBox {
- pub fn new(checked: bool) -> CheckBox {
- CheckBox { checked }
- }
+ pub const fn new(checked: bool) -> CheckBox { CheckBox { checked } }
}
impl Parseable for CheckBox {
@@ -34,9 +30,7 @@ impl Parseable for CheckBox {
format!(r#" "#)
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for CheckBox {
@@ -48,9 +42,8 @@ impl std::fmt::Display for CheckBox {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -71,8 +64,17 @@ mod tests {
checkbox.checked = false;
assert_eq!(
- format!("{}", Token::CheckBox(checkbox.clone())),
+ format!("{}", Token::CheckBox(checkbox)),
"Tk:CheckBox [empty]"
);
}
+
+ #[test]
+ fn flatten() {
+ let checkbox = CheckBox::new(false);
+ assert_eq!(checkbox.flatten(), "");
+
+ let token = Token::CheckBox(checkbox);
+ assert_eq!(token.flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/code.rs b/src/syntax/content/parser/token/code.rs
index 4aef324..8f82eba 100644
--- a/src/syntax/content/parser/token/code.rs
+++ b/src/syntax/content/parser/token/code.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Code {
@@ -8,15 +6,11 @@ pub struct Code {
}
impl Code {
- pub fn new(open: bool) -> Code {
- Code { open }
- }
+ pub const fn new(open: bool) -> Code { Code { open } }
}
impl Parseable for Code {
- fn probe(lexeme: &Lexeme) -> bool {
- lexeme.text() == "`"
- }
+ fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "`" }
fn lex(_lexeme: &Lexeme) -> Code {
panic!("Attempt to lex a code tag directly from a lexeme")
@@ -30,9 +24,7 @@ impl Parseable for Code {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Code {
@@ -44,9 +36,8 @@ impl std::fmt::Display for Code {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a code tag directly from a lexeme"
)]
- fn lex() {
- Code::lex(&Lexeme::default());
- }
+ fn lex() { Code::lex(&Lexeme::default()); }
#[test]
fn token_display() {
@@ -71,9 +60,15 @@ mod tests {
assert_eq!(format!("{}", Token::Code(code.clone())), "Tk:Code [open]");
code.open = false;
- assert_eq!(
- format!("{}", Token::Code(code.clone())),
- "Tk:Code [closed]"
- );
+ assert_eq!(format!("{}", Token::Code(code)), "Tk:Code [closed]");
+ }
+
+ #[test]
+ fn flatten() {
+ let code = Code::new(true);
+ assert_eq!(code.flatten(), "");
+
+ let token = Token::Code(code);
+ assert_eq!(token.flatten(), "");
}
}
diff --git a/src/syntax/content/parser/token/header.rs b/src/syntax/content/parser/token/header.rs
index f238f73..9de3b5d 100644
--- a/src/syntax/content/parser/token/header.rs
+++ b/src/syntax/content/parser/token/header.rs
@@ -1,15 +1,14 @@
use std::{
collections::{HashMap, hash_map::Entry},
+ fmt::Display,
};
use crate::{
- prelude::*,
graph::Config,
- syntax::content::{Parseable, Lexeme},
+ prelude::*,
+ syntax::content::{Lexeme, Parseable},
};
-use std::fmt::Display;
-
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Header {
open: Option,
@@ -33,7 +32,7 @@ impl Header {
) -> String {
let base_id = if !config.ascii_dom_ids || next_lexeme.next().is_ascii()
{
- next_lexeme.next().clone()
+ next_lexeme.next()
} else {
String::from("h")
};
@@ -61,7 +60,7 @@ impl Header {
}
}
- pub fn level(&self) -> u8 {
+ pub const fn level(&self) -> u8 {
match self.level {
Level::One => 1,
Level::Two => 2,
@@ -113,9 +112,7 @@ impl Parseable for Header {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Header {
@@ -150,7 +147,7 @@ pub enum Level {
}
impl Level {
- fn from_u8(u: u8) -> Level {
+ const fn from_u8(u: u8) -> Level {
if u <= 1 {
Level::One
} else if u == 2 {
@@ -195,9 +192,8 @@ impl Display for Level {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn make_id() {
@@ -300,4 +296,39 @@ mod tests {
"Tk:Header [closed L2]"
);
}
+
+ #[test]
+ fn display_unknown_open_state() {
+ let header = Header {
+ open: None,
+ dom_id: None,
+ level: Level::One,
+ };
+
+ assert_eq!(format!("{header}"), "Header [unknown L1]");
+ }
+
+ #[test]
+ fn display_dom_id() {
+ let payload = "WIV0h1wCeY7Pp3FkjgIftJHX1I6YvnSc";
+ let header = Header {
+ open: None,
+ dom_id: Some(payload.to_string()),
+ level: Level::One,
+ };
+
+ assert_eq!(
+ format!("{header}"),
+ format!("Header [unknown L1 DOM ID {payload}]")
+ );
+ }
+
+ #[test]
+ fn flatten() {
+ let header = Header::new(Level::Two, true, Some("MNxqaFfIbCzw"));
+ assert_eq!(header.flatten(), "");
+
+ let token = Token::Header(header);
+ assert_eq!(token.flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/item.rs b/src/syntax/content/parser/token/item.rs
index 02b8431..0e36144 100644
--- a/src/syntax/content/parser/token/item.rs
+++ b/src/syntax/content/parser/token/item.rs
@@ -1,4 +1,4 @@
-use crate::syntax::content::{Parseable, Lexeme};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
pub struct Item {
@@ -7,9 +7,7 @@ pub struct Item {
}
impl Parseable for Item {
- fn probe(_: &Lexeme) -> bool {
- false
- }
+ fn probe(_: &Lexeme) -> bool { false }
fn lex(_: &Lexeme) -> Item {
panic!("Attempt to lex an item directly from a lexeme")
@@ -19,9 +17,7 @@ impl Parseable for Item {
panic!("Items should only be rendered by a list's render method")
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl Item {
@@ -50,17 +46,26 @@ impl std::fmt::Display for Item {
#[cfg(test)]
mod tests {
+ use super::*;
use crate::syntax::content::parser::Token;
- use super::*;
+ #[test]
+ #[should_panic(
+ expected = "Items should only be rendered by a list's render method"
+ )]
+ fn token_render() {
+ let item = Item::new("aCNuZwwzrt", None);
+ item.render();
+ }
#[test]
#[should_panic(
expected = "Items should only be rendered by a list's render method"
)]
fn render() {
- let item = Item::new("aCNuZwwzrt", None);
- item.render();
+ let item = Item::new("vuv3ipykTzuf", None);
+ let token = Token::Item(item);
+ token.render();
}
#[test]
@@ -85,8 +90,15 @@ mod tests {
);
item.depth = None;
assert_eq!(
- format!("{}", Token::Item(item.clone())),
+ format!("{}", Token::Item(item)),
"Tk:Item [] dRMy4"
);
}
+
+ #[test]
+ fn flatten() {
+ let item = Item::new("", None);
+ assert_eq!(item.flatten(), "");
+ assert_eq!(Token::Item(item).flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/linebreak.rs b/src/syntax/content/parser/token/linebreak.rs
index 9026b7c..65ccc73 100644
--- a/src/syntax/content/parser/token/linebreak.rs
+++ b/src/syntax/content/parser/token/linebreak.rs
@@ -1,26 +1,18 @@
-use crate::{
- syntax::content::{Parseable, parser::Lexeme},
-};
+use crate::syntax::content::{Parseable, parser::Lexeme};
#[derive(Default, Debug, Clone, Eq, PartialEq)]
-pub struct LineBreak {}
+pub struct LineBreak;
impl Parseable for LineBreak {
fn probe(lexeme: &Lexeme) -> bool {
- lexeme.text() == "\n" && !lexeme.last()
+ lexeme.match_char('<') && lexeme.match_next_char('\n')
}
- fn lex(_lexeme: &Lexeme) -> LineBreak {
- LineBreak {}
- }
+ fn lex(_lexeme: &Lexeme) -> LineBreak { LineBreak {} }
- fn render(&self) -> String {
- "\n".to_owned()
- }
+ fn render(&self) -> String { String::from(" ") }
- fn flatten(&self) -> String {
- String::from('\n')
- }
+ fn flatten(&self) -> String { String::from('\n') }
}
impl std::fmt::Display for LineBreak {
@@ -31,13 +23,17 @@ impl std::fmt::Display for LineBreak {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn token_display() {
- let linebreak = LineBreak::default();
- assert_eq!(format!("{}", Token::LineBreak(linebreak)), "Tk:LineBreak");
+ assert_eq!(format!("{}", Token::LineBreak(LineBreak)), "Tk:LineBreak");
+ }
+
+ #[test]
+ fn flatten() {
+ assert_eq!(LineBreak.flatten(), "\n");
+ assert_eq!(Token::LineBreak(LineBreak).flatten(), "\n");
}
}
diff --git a/src/syntax/content/parser/token/list.rs b/src/syntax/content/parser/token/list.rs
index 721d226..1120b9d 100644
--- a/src/syntax/content/parser/token/list.rs
+++ b/src/syntax/content/parser/token/list.rs
@@ -1,4 +1,5 @@
use crate::{
+ prelude::*,
syntax::content::{
Parseable,
parser::{Lexeme, token::Item},
@@ -20,6 +21,14 @@ impl Parseable for List {
panic!("Attempt to lex a List directly from a lexeme")
}
+ /// Renders the list to the equivalent HTML representation.
+ ///
+ /// Performs checked arithmetic to the following effects:
+ /// - Strict division is performed but related panics are unreachable given
+ /// the guarantees described in `List::scale_indent`
+ /// - Saturates subtractions from indent levels at zero. This is not
+ /// unreachable, but a difference of zero is a no-op considering it would
+ /// cause an iteration of zero times (over an empty range).
fn render(&self) -> String {
let tag = if self.ordered { "ol" } else { "ul" };
let mut output = String::new();
@@ -34,19 +43,19 @@ impl Parseable for List {
.unwrap_or(0)
.strict_div(scale);
- output.push_str(&format!("{}", item.text));
+ write_log!(output, " {}", item.text);
if next_level > level {
// open nested lists
for _ in 0..(next_level.saturating_sub(level)) {
- output.push_str(&format!("<{tag}>\n"));
+ write_log!(output, "<{tag}>\n");
}
} else {
// close current item
output.push_str(" ");
// close nested lists
for _ in 0..(level.saturating_sub(next_level)) {
- output.push_str(&format!("{tag}>"));
+ write_log!(output, "{tag}>");
}
output.push('\n');
}
@@ -61,13 +70,25 @@ impl Parseable for List {
}
impl List {
- pub fn new(ordered: bool) -> List {
+ pub const fn new(ordered: bool) -> List {
List {
ordered,
items: vec![],
}
}
+ /// Calculates the scale to normalize indents.
+ ///
+ /// For example, if two contiguous items have differing indents of 2 and 4,
+ /// the indent scale is 2 and they can be normalized as having indents of
+ /// 1 and 2 respectively.
+ ///
+ /// Performs checked arithmetic to the following effects:
+ /// - The subtraction of outer from inner saturates at 0 due to u8 being
+ /// unsigned, but such a case is unreachable given the outer condition
+ /// that guards this subtraction
+ /// - Will not return zero even if it is the calculated width, instead
+ /// logging the event and returning 1 instead
fn scale_indent(&self) -> u8 {
let width = self
.items
@@ -79,8 +100,12 @@ impl List {
})
.unwrap_or(1);
- assert!(width != 0, "Width of zero can't be a divisor");
- width
+ if width == 0 {
+ log!("Scale indent of 0 can't be a divisor: returning 1 instead");
+ 1
+ } else {
+ width
+ }
}
}
@@ -97,9 +122,8 @@ impl std::fmt::Display for List {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render_flat_list() {
@@ -178,7 +202,7 @@ mod tests {
fn token_display() {
let list = List::new(false);
assert_eq!(
- format!("{}", Token::List(list.clone())),
+ format!("{}", Token::List(list)),
"Tk:List [0 unordered items]"
);
}
@@ -189,4 +213,32 @@ mod tests {
let lexeme = Lexeme::new("SL6PX", "6xsNB", "oeAHa");
List::lex(&lexeme);
}
+
+ #[test]
+ fn ordered_list() {
+ let mut list = List::new(true);
+ list.items = vec![
+ Item::new("a", Some(0)),
+ Item::new("b", Some(0)),
+ Item::new("c", Some(0)),
+ ];
+
+ assert_eq!(
+ list.render(),
+ "\n\n\
+ a \n\
+ b \n\
+ c \n\
+ \n\n"
+ );
+ }
+
+ #[test]
+ fn flatten() {
+ let list = List::new(true);
+ assert_eq!(list.flatten(), "[List: 0 items]");
+
+ let token = Token::List(List::new(true));
+ assert_eq!(token.flatten(), "[List: 0 items]");
+ }
}
diff --git a/src/syntax/content/parser/token/literal.rs b/src/syntax/content/parser/token/literal.rs
index ca521ae..236ee41 100644
--- a/src/syntax/content/parser/token/literal.rs
+++ b/src/syntax/content/parser/token/literal.rs
@@ -16,26 +16,21 @@ impl Parseable for Literal {
}
}
- fn render(&self) -> String {
- self.text.clone()
- }
+ fn render(&self) -> String { self.text.clone() }
- fn flatten(&self) -> String {
- self.text.clone()
- }
+ fn flatten(&self) -> String { self.text.clone() }
}
impl std::fmt::Display for Literal {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "Literal {}", crate::log::wrap(&self.text))
+ write!(f, "Literal {}", crate::dev::log::wrap(&self.text))
}
}
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn token_display() {
@@ -48,9 +43,14 @@ mod tests {
);
literal.text = String::from("TjY02");
- assert_eq!(
- format!("{}", Token::Literal(literal.clone())),
- "Tk:Literal TjY02"
- );
+ assert_eq!(format!("{}", Token::Literal(literal)), "Tk:Literal TjY02");
+ }
+
+ #[test]
+ fn flatten() {
+ let payload = "vJtsvWD7ErYB";
+ let literal = Literal::lex(&Lexeme::new(payload, "", ""));
+ assert_eq!(literal.flatten(), payload);
+ assert_eq!(Token::Literal(literal).flatten(), payload);
}
}
diff --git a/src/syntax/content/parser/token/oblique.rs b/src/syntax/content/parser/token/oblique.rs
index 320626b..a156a19 100644
--- a/src/syntax/content/parser/token/oblique.rs
+++ b/src/syntax/content/parser/token/oblique.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Oblique {
@@ -8,15 +6,11 @@ pub struct Oblique {
}
impl Oblique {
- pub fn new(open: bool) -> Oblique {
- Oblique { open }
- }
+ pub const fn new(open: bool) -> Oblique { Oblique { open } }
}
impl Parseable for Oblique {
- fn probe(lexeme: &Lexeme) -> bool {
- lexeme.text() == "_"
- }
+ fn probe(lexeme: &Lexeme) -> bool { lexeme.text() == "_" }
fn lex(_lexeme: &Lexeme) -> Oblique {
panic!("Attempt to lex an oblique tag directly from a lexeme")
@@ -30,9 +24,7 @@ impl Parseable for Oblique {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Oblique {
@@ -44,9 +36,8 @@ impl std::fmt::Display for Oblique {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -61,9 +52,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an oblique tag directly from a lexeme"
)]
- fn lex() {
- Oblique::lex(&Lexeme::default());
- }
+ fn lex() { Oblique::lex(&Lexeme::default()); }
#[test]
fn token_display() {
@@ -75,8 +64,17 @@ mod tests {
oblique.open = false;
assert_eq!(
- format!("{}", Token::Oblique(oblique.clone())),
+ format!("{}", Token::Oblique(oblique)),
"Tk:Oblique [closed]"
);
}
+
+ #[test]
+ fn flatten() {
+ let oblique = Oblique::new(false);
+ assert_eq!(oblique.flatten(), "");
+
+ let token = Token::Oblique(oblique);
+ assert_eq!(token.flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/paragraph.rs b/src/syntax/content/parser/token/paragraph.rs
index 1c51d87..c0756af 100644
--- a/src/syntax/content/parser/token/paragraph.rs
+++ b/src/syntax/content/parser/token/paragraph.rs
@@ -6,9 +6,7 @@ pub struct Paragraph {
}
impl Paragraph {
- pub fn new(open: bool) -> Paragraph {
- Paragraph { open: Some(open) }
- }
+ pub const fn new(open: bool) -> Paragraph { Paragraph { open: Some(open) } }
pub fn probe_end(lexeme: &Lexeme) -> bool {
lexeme.match_char('\n') && lexeme.match_next_char('\n')
@@ -21,9 +19,7 @@ impl Parseable for Paragraph {
!lexeme.is_whitespace()
}
- fn lex(_lexeme: &Lexeme) -> Paragraph {
- Paragraph { open: None }
- }
+ fn lex(_lexeme: &Lexeme) -> Paragraph { Paragraph { open: None } }
fn render(&self) -> String {
if let Some(open) = self.open {
@@ -39,9 +35,7 @@ impl Parseable for Paragraph {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Paragraph {
@@ -62,9 +56,8 @@ impl std::fmt::Display for Paragraph {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn lex() {
@@ -73,9 +66,8 @@ mod tests {
}
#[test]
- #[should_panic(
- expected = "Attempt to render a paragraph tag while open state is unknown"
- )]
+ #[should_panic(expected = "Attempt to render a paragraph tag while \
+ open state is unknown")]
fn render_state_unknown() {
let p = Paragraph::lex(&Lexeme::default());
drop(p.render());
@@ -97,8 +89,19 @@ mod tests {
paragraph.open = None;
assert_eq!(
- format!("{}", Token::Paragraph(paragraph.clone())),
+ format!("{}", Token::Paragraph(paragraph)),
"Tk:Paragraph [unknown]"
);
}
+
+ #[test]
+ fn flatten() {
+ let open = Paragraph::new(true);
+ let closed = Paragraph::new(false);
+
+ assert_eq!(open.flatten(), "");
+ assert_eq!(closed.flatten(), "");
+ assert_eq!(Token::Paragraph(open).flatten(), "");
+ assert_eq!(Token::Paragraph(closed).flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/preformat.rs b/src/syntax/content/parser/token/preformat.rs
index a55995b..f24bbc4 100644
--- a/src/syntax/content/parser/token/preformat.rs
+++ b/src/syntax/content/parser/token/preformat.rs
@@ -1,102 +1,87 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
-#[derive(Debug, Clone, Eq, PartialEq)]
+#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct PreFormat {
- open: Option,
+ pub text: String,
}
impl PreFormat {
- pub fn new(open: bool) -> PreFormat {
- PreFormat { open: Some(open) }
+ pub fn new(text: &str) -> PreFormat {
+ PreFormat {
+ text: String::from(text),
+ }
}
}
impl std::fmt::Display for PreFormat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- let display_open_state = if let Some(open_state) = self.open {
- if open_state { "open" } else { "closed" }
+ let character_count = self.text.chars().count();
+ let is_whitespace = self.text.trim_ascii().is_empty();
+ let summary = if is_whitespace {
+ "empty"
} else {
- "unknown"
+ &format!("{character_count} chars")
};
- write!(f, "PreFormat [{display_open_state}]")
+ write!(f, "PreFormat [{summary}]")
}
}
impl Parseable for PreFormat {
fn probe(lexeme: &Lexeme) -> bool {
- lexeme.match_first_char('`') && (lexeme.next() == "\n" || lexeme.last())
+ lexeme.match_char('`') && (lexeme.next() == "\n" || lexeme.last())
}
fn lex(_lexeme: &Lexeme) -> PreFormat {
- PreFormat { open: None }
+ panic!("Attempt to lex a preformat directly from a lexeme")
}
- fn render(&self) -> String {
- if let Some(o) = self.open {
- if o {
- "".to_owned()
- } else {
- " ".to_owned()
- }
- } else {
- panic!(
- "Attempt to render a preformat tag while open state is unknown"
- )
- }
- }
+ fn render(&self) -> String { format!("{} ", self.text) }
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
-
- #[test]
- fn lex() {
- let from_empty_lexeme = PreFormat::lex(&Lexeme::default());
- assert!(from_empty_lexeme.open.is_none());
-
- let from_non_empty_lexeme = PreFormat::lex(&Lexeme::default());
- assert!(from_non_empty_lexeme.open.is_none());
- }
+ use crate::syntax::content::parser::Token;
#[test]
#[should_panic(
- expected = "Attempt to render a preformat tag while open state is unknown"
+ expected = "Attempt to lex a preformat directly from a lexeme"
)]
- fn render() {
- let from_empty_lexeme = PreFormat::lex(&Lexeme::default());
- from_empty_lexeme.render();
-
- let from_non_empty_lexeme = PreFormat::lex(&Lexeme::default());
- from_non_empty_lexeme.render();
+ fn lex() {
+ let lexeme = Lexeme::new("a", "b", "c");
+ PreFormat::lex(&lexeme);
}
#[test]
fn token_display() {
- let mut preformat = PreFormat::new(true);
+ let mut preformat = PreFormat::new("");
+
assert_eq!(
format!("{}", Token::PreFormat(preformat.clone())),
- "Tk:PreFormat [open]"
+ "Tk:PreFormat [empty]"
);
- preformat.open = Some(false);
+ preformat.text = "\n ".to_string();
assert_eq!(
format!("{}", Token::PreFormat(preformat.clone())),
- "Tk:PreFormat [closed]"
+ "Tk:PreFormat [empty]"
);
- preformat.open = None;
+ preformat.text = "text".to_string();
assert_eq!(
- format!("{}", Token::PreFormat(preformat.clone())),
- "Tk:PreFormat [unknown]"
+ format!("{}", Token::PreFormat(preformat)),
+ "Tk:PreFormat [4 chars]"
);
}
+
+ #[test]
+ fn flatten() {
+ let preformat = PreFormat::new("");
+ assert_eq!(preformat.flatten(), "");
+
+ let token = Token::PreFormat(preformat);
+ assert_eq!(token.flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/quote.rs b/src/syntax/content/parser/token/quote.rs
new file mode 100644
index 0000000..81d5544
--- /dev/null
+++ b/src/syntax/content/parser/token/quote.rs
@@ -0,0 +1,166 @@
+use crate::syntax::content::{Parseable, parser::Lexeme};
+
+#[derive(Debug, Default, Clone, Eq, PartialEq)]
+pub struct Quote {
+ pub text: String,
+ pub citation: Option,
+ pub url: Option,
+}
+
+impl Quote {
+ pub fn probe_end(lexeme: &Lexeme) -> bool {
+ lexeme.match_char_sequence('\n', '\n')
+ }
+
+ pub fn extend_citation(&mut self, s: &str) {
+ if let Some(current) = &self.citation {
+ self.citation = Some(format!("{current}{s}"));
+ } else {
+ self.citation = Some(String::from(s));
+ }
+ }
+}
+
+impl Parseable for Quote {
+ fn probe(lexeme: &Lexeme) -> bool {
+ lexeme.match_char('>') && lexeme.match_next_char(' ')
+ }
+
+ fn lex(_lexeme: &Lexeme) -> Quote {
+ panic!("Attempt to lex a quote directly from a lexeme")
+ }
+
+ fn render(&self) -> String {
+ let opening = if let Some(url) = &self.url {
+ format!(r#""#)
+ } else {
+ String::from("")
+ };
+
+ let content = if let Some(citation) = &self.citation {
+ format!(
+ r#"{}{citation} "#,
+ self.text
+ )
+ } else {
+ String::from(&self.text)
+ };
+
+ format!("\n{opening}\n{content}\n \n")
+ }
+
+ fn flatten(&self) -> String {
+ if let Some(citation) = &self.citation {
+ format!(r#""{}" -- {}"#, self.text, citation)
+ } else {
+ format!(r#""{}""#, self.text)
+ }
+ }
+}
+
+impl std::fmt::Display for Quote {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let mut meta = String::default();
+ if self.url.is_some() {
+ meta.push_str("+url ");
+ }
+ if self.citation.is_some() {
+ meta.push_str("+citation ");
+ }
+
+ write!(f, "Quote [{}]", meta.trim())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::syntax::content::parser::Token;
+
+ #[test]
+ fn display() {
+ let mut quote_slim = Quote::default();
+ quote_slim.text = "iXh0141J7B8P46Gv".to_string();
+
+ println!("{quote_slim}");
+ assert!(format!("{quote_slim}").contains("Quote"));
+ assert!(!format!("{quote_slim}").contains("+url"));
+ assert!(!format!("{quote_slim}").contains("+citation"));
+ assert_eq!(format!("{}", Token::Quote(quote_slim)), "Tk:Quote []");
+
+ let mut quote_cited = Quote::default();
+ quote_cited.text = "iXh0141J7B8P46Gv".to_string();
+ quote_cited.citation = Some("k8Fy7htmvi2NG7yh".to_string());
+
+ println!("{quote_cited}");
+ assert!(format!("{quote_cited}").contains("Quote"));
+ assert!(!format!("{quote_cited}").contains("+url"));
+ assert!(format!("{quote_cited}").contains("+citation"));
+ assert_eq!(
+ format!("{}", Token::Quote(quote_cited)),
+ "Tk:Quote [+citation]",
+ );
+
+ let mut quote_with_url = Quote::default();
+ quote_with_url.text = "iXh0141J7B8P46Gv".to_string();
+ quote_with_url.url = Some("CttVJU2IHDsjSjao".to_string());
+
+ println!("{quote_with_url}");
+ assert!(format!("{quote_with_url}").contains("Quote"));
+ assert!(format!("{quote_with_url}").contains("+url"));
+ assert!(!format!("{quote_with_url}").contains("+citation"));
+ assert_eq!(
+ format!("{}", Token::Quote(quote_with_url)),
+ "Tk:Quote [+url]",
+ );
+
+ let mut quote_full = Quote::default();
+ quote_full.text = "iXh0141J7B8P46Gv".to_string();
+ quote_full.citation = Some("k8Fy7htmvi2NG7yh".to_string());
+ quote_full.url = Some("CttVJU2IHDsjSjao".to_string());
+
+ println!("{quote_full}");
+ assert!(format!("{quote_full}").contains("Quote"));
+ assert!(format!("{quote_full}").contains("+url"));
+ assert!(format!("{quote_full}").contains("+citation"));
+ assert_eq!(
+ format!("{}", Token::Quote(quote_full)),
+ "Tk:Quote [+url +citation]",
+ );
+ }
+
+ #[test]
+ fn flatten() {
+ assert_eq!(Quote::default().flatten(), r#""""#);
+
+ let mut without_citation = Quote::default();
+ let text = "AphyFDQHVbkOeaNw";
+ without_citation.text = text.to_string();
+ assert_eq!(without_citation.flatten(), format!(r#""{text}""#));
+
+ let without_citation_token = Token::Quote(without_citation);
+ assert_eq!(without_citation_token.flatten(), format!(r#""{text}""#));
+
+ let mut with_citation = Quote::default();
+ let citation = "B35rcofYM0J7";
+ with_citation.text = text.to_string();
+ with_citation.citation = Some(citation.to_string());
+ assert_eq!(
+ with_citation.flatten(),
+ format!(r#""{text}" -- {citation}"#)
+ );
+
+ let with_citation_token = Token::Quote(with_citation);
+ assert_eq!(
+ with_citation_token.flatten(),
+ format!(r#""{text}" -- {citation}"#)
+ );
+ }
+
+ #[test]
+ #[should_panic(expected = "Attempt to lex a quote directly from a lexeme")]
+ fn lex() {
+ let lexeme = Lexeme::new("z2UI", "FiCd", "rtq4");
+ Quote::lex(&lexeme);
+ }
+}
diff --git a/src/syntax/content/parser/token/strike.rs b/src/syntax/content/parser/token/strike.rs
index c1a925a..14b1dc4 100644
--- a/src/syntax/content/parser/token/strike.rs
+++ b/src/syntax/content/parser/token/strike.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Strike {
@@ -8,9 +6,7 @@ pub struct Strike {
}
impl Strike {
- pub fn new(open: bool) -> Strike {
- Strike { open }
- }
+ pub const fn new(open: bool) -> Strike { Strike { open } }
}
impl Parseable for Strike {
@@ -27,9 +23,7 @@ impl Parseable for Strike {
String::from(tag)
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Strike {
@@ -41,9 +35,8 @@ impl std::fmt::Display for Strike {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -58,9 +51,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex a strike tag directly from a lexeme"
)]
- fn lex() {
- Strike::lex(&Lexeme::default());
- }
+ fn lex() { Strike::lex(&Lexeme::default()); }
#[test]
fn token_display() {
@@ -71,9 +62,15 @@ mod tests {
);
strike.open = false;
- assert_eq!(
- format!("{}", Token::Strike(strike.clone())),
- "Tk:Strike [closed]"
- );
+ assert_eq!(format!("{}", Token::Strike(strike)), "Tk:Strike [closed]");
+ }
+
+ #[test]
+ fn flatten() {
+ let strike = Strike::new(false);
+ assert_eq!(strike.flatten(), "");
+
+ let token = Token::Strike(strike);
+ assert_eq!(token.flatten(), "");
}
}
diff --git a/src/syntax/content/parser/token/table.rs b/src/syntax/content/parser/token/table.rs
new file mode 100644
index 0000000..ab2f715
--- /dev/null
+++ b/src/syntax/content/parser/token/table.rs
@@ -0,0 +1,169 @@
+use crate::syntax::content::{Parseable, parser::Lexeme};
+
+#[derive(Debug, Default, Clone, Eq, PartialEq)]
+pub struct Table {
+ pub headers: Vec,
+ pub contents: Vec>,
+}
+
+impl Table {
+ pub fn probe_end(lexeme: &Lexeme) -> bool {
+ lexeme.match_char_triple('\n', '%', '\n') || lexeme.last()
+ }
+
+ pub fn add_header(&mut self, header: &str) {
+ self.headers.push(header.trim().to_string());
+ }
+
+ pub fn add_row(&mut self, row: Vec) { self.contents.push(row); }
+
+ pub fn add_cell(&mut self, content: &str) {
+ if let Some(last) = self.contents.last_mut() {
+ last.push(content.trim().to_string());
+ } else {
+ self.contents.push(vec![content.trim().to_string()]);
+ }
+ }
+
+ /// Counts the number of cells in the last row.
+ pub fn last_row_count(&self) -> usize {
+ if let Some(last) = self.contents.last() {
+ last.len()
+ } else {
+ 0
+ }
+ }
+}
+
+impl Parseable for Table {
+ fn probe(lexeme: &Lexeme) -> bool { lexeme.match_char_sequence('%', '\n') }
+
+ fn lex(_lexeme: &Lexeme) -> Table {
+ panic!("Attempt to lex a table directly from a lexeme")
+ }
+
+ fn render(&self) -> String {
+ let mut xml = String::from("\n\n");
+ let tab = " ";
+
+ if !self.headers.is_empty() {
+ xml.push_str(format!("{tab}\n").as_str());
+ for header in &self.headers {
+ xml.push_str(format!("{tab}{tab}{header} \n").as_str());
+ }
+ xml.push_str(format!("{tab} \n").as_str());
+ }
+
+ for row in &self.contents {
+ if !row.is_empty() && row.iter().any(|cell| !cell.is_empty()) {
+ xml.push_str(format!("{tab}\n").as_str());
+ for cell in row {
+ xml.push_str(
+ format!("{tab}{tab}{cell} \n").as_str(),
+ );
+ }
+ xml.push_str(format!("{tab} \n").as_str());
+ }
+ }
+
+ xml.push_str("
\n");
+ xml
+ }
+
+ fn flatten(&self) -> String { String::from("[Table]") }
+}
+
+impl std::fmt::Display for Table {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let headers_width = self.headers.len();
+ let contents_height = self.contents.len();
+ let contents_width = self.last_row_count();
+
+ let mut extra = String::default();
+ if headers_width > 0 && contents_height > 0 {
+ extra = format!(
+ " [{contents_width}x{contents_height} +{headers_width} headers]"
+ );
+ } else if headers_width > 0 {
+ extra = format!(" [+{headers_width} headers]");
+ } else if contents_height > 0 {
+ extra = format!(" [{contents_width}x{contents_height}]");
+ }
+
+ write!(f, "Table{extra}")
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::syntax::content::parser::Token;
+
+ #[test]
+ #[should_panic(expected = "Attempt to lex a table directly from a lexeme")]
+ fn lex() {
+ let lexeme = Lexeme::new("tp0h", "rrFt", "Qouf");
+ Table::lex(&lexeme);
+ }
+
+ #[test]
+ fn flatten() {
+ assert_eq!(Table::default().flatten(), "[Table]");
+ assert_eq!(Token::Table(Table::default()).flatten(), "[Table]");
+ }
+
+ #[test]
+ fn display() {
+ use std::string::ToString;
+
+ let mut table = Table::default();
+ table.add_header("A");
+ table.add_header("B");
+ table.add_header("C");
+
+ let table_token = Token::Table(table.clone());
+ assert_eq!(format!("{table}"), "Table [+3 headers]");
+ assert_eq!(format!("{table_token}"), "Tk:Table [+3 headers]");
+
+ table.add_row(
+ ["1", "2", "3"]
+ .iter()
+ .map(ToString::to_string)
+ .collect::>(),
+ );
+ table.add_row(
+ ["4", "5", "6"]
+ .iter()
+ .map(ToString::to_string)
+ .collect::>(),
+ );
+ table.add_row(
+ ["7", "8", "9"]
+ .iter()
+ .map(ToString::to_string)
+ .collect::>(),
+ );
+
+ let table_token2 = Token::Table(table.clone());
+ assert_eq!(format!("{table}"), "Table [3x3 +3 headers]");
+ assert_eq!(format!("{table_token2}"), "Tk:Table [3x3 +3 headers]");
+
+ let mut table2 = Table::default();
+ table2.add_row(
+ ["1", "2", "3"]
+ .iter()
+ .map(ToString::to_string)
+ .collect::>(),
+ );
+ table2.add_row(
+ ["2", "4", "6"]
+ .iter()
+ .map(ToString::to_string)
+ .collect::>(),
+ );
+
+ let table2_token = Token::Table(table2.clone());
+ assert_eq!(format!("{table2}"), "Table [3x2]");
+ assert_eq!(format!("{table2_token}"), "Tk:Table [3x2]");
+ }
+}
diff --git a/src/syntax/content/parser/token/underline.rs b/src/syntax/content/parser/token/underline.rs
index a86e4b4..0cd565e 100644
--- a/src/syntax/content/parser/token/underline.rs
+++ b/src/syntax/content/parser/token/underline.rs
@@ -1,6 +1,4 @@
-use crate::{
- syntax::content::{Parseable, Lexeme},
-};
+use crate::syntax::content::{Lexeme, Parseable};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Underline {
@@ -8,9 +6,7 @@ pub struct Underline {
}
impl Underline {
- pub fn new(open: bool) -> Underline {
- Underline { open }
- }
+ pub const fn new(open: bool) -> Underline { Underline { open } }
}
impl Parseable for Underline {
@@ -30,9 +26,7 @@ impl Parseable for Underline {
}
}
- fn flatten(&self) -> String {
- String::default()
- }
+ fn flatten(&self) -> String { String::default() }
}
impl std::fmt::Display for Underline {
@@ -44,9 +38,8 @@ impl std::fmt::Display for Underline {
#[cfg(test)]
mod tests {
- use crate::syntax::content::parser::Token;
-
use super::*;
+ use crate::syntax::content::parser::Token;
#[test]
fn render() {
@@ -61,9 +54,7 @@ mod tests {
#[should_panic(
expected = "Attempt to lex an underline tag directly from a lexeme"
)]
- fn lex() {
- Underline::lex(&Lexeme::default());
- }
+ fn lex() { Underline::lex(&Lexeme::default()); }
#[test]
fn token_display() {
@@ -75,8 +66,17 @@ mod tests {
underline.open = false;
assert_eq!(
- format!("{}", Token::Underline(underline.clone())),
+ format!("{}", Token::Underline(underline)),
"Tk:Underline [closed]"
);
}
+
+ #[test]
+ fn flatten() {
+ let underline = Underline::new(false);
+ assert_eq!(underline.flatten(), "");
+
+ let token = Token::Underline(underline);
+ assert_eq!(token.flatten(), "");
+ }
}
diff --git a/src/syntax/content/parser/token/verse.rs b/src/syntax/content/parser/token/verse.rs
new file mode 100644
index 0000000..f3f7910
--- /dev/null
+++ b/src/syntax/content/parser/token/verse.rs
@@ -0,0 +1,101 @@
+use crate::syntax::content::{Parseable, parser::Lexeme};
+
+#[derive(Debug, Clone, Eq, PartialEq)]
+pub struct Verse {
+ open: Option,
+}
+
+impl Verse {
+ pub const fn new(open: bool) -> Verse { Verse { open: Some(open) } }
+
+ pub fn probe_end(lexeme: &Lexeme) -> bool {
+ lexeme.match_char_triple('\n', '&', '\n')
+ }
+}
+
+impl Parseable for Verse {
+ fn probe(lexeme: &Lexeme) -> bool {
+ lexeme.match_char_triple('\n', '&', '\n')
+ }
+
+ fn lex(_lexeme: &Lexeme) -> Verse { Verse { open: None } }
+
+ fn render(&self) -> String {
+ if let Some(open) = self.open {
+ if open {
+ concat!("\n", r#""#).to_string()
+ } else {
+ "\n
\n".to_owned()
+ }
+ } else {
+ panic!("Attempt to render a verse tag while open state is unknown")
+ }
+ }
+
+ fn flatten(&self) -> String { String::default() }
+}
+
+impl std::fmt::Display for Verse {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ let display_open_state = match self.open {
+ Some(open_state) => {
+ if open_state {
+ "open"
+ } else {
+ "closed"
+ }
+ },
+ None => "unknown",
+ };
+
+ write!(f, "Verse [{display_open_state}]")
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::syntax::content::parser::Token;
+
+ #[test]
+ fn lexed_verse_is_empty() {
+ let verse = Verse::lex(&Lexeme::default());
+ assert!(verse.open.is_none());
+ }
+
+ #[test]
+ fn flatten() {
+ let verse = Verse::new(true);
+ assert!(verse.flatten().is_empty());
+
+ let token = Token::Verse(verse);
+ assert_eq!(token.flatten(), "");
+ }
+
+ #[test]
+ #[should_panic(
+ expected = "Attempt to render a verse tag while open state is unknown"
+ )]
+ fn render_attempt_with_unknown_open_state() {
+ let verse = Verse::lex(&Lexeme::default());
+ verse.render();
+ }
+
+ #[test]
+ fn display() {
+ let open = Verse::new(true);
+ let open_token = Token::Verse(open.clone());
+ assert_eq!(format!("{open}"), "Verse [open]");
+ assert_eq!(format!("{open_token}"), "Tk:Verse [open]");
+
+ let closed = Verse::new(false);
+ let closed_token = Token::Verse(closed.clone());
+ assert_eq!(format!("{closed}"), "Verse [closed]");
+ assert_eq!(format!("{closed_token}"), "Tk:Verse [closed]");
+
+ let unknown = Verse::lex(&Lexeme::default());
+ let unknown_token = Token::Verse(unknown.clone());
+ assert_eq!(format!("{unknown}"), "Verse [unknown]");
+ assert_eq!(format!("{unknown_token}"), "Tk:Verse [unknown]");
+ }
+}
diff --git a/static/graph-schema.json b/static/graph-schema.json
new file mode 100644
index 0000000..95c177a
--- /dev/null
+++ b/static/graph-schema.json
@@ -0,0 +1,80 @@
+{
+ "$id": "https://git.jutty.dev/jutty/en/raw/branch/main/static/graph-schema.json",
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "title": "Graph",
+ "description": "An en graph file",
+ "type": "object",
+ "$defs": {
+ "node": {
+ "type": "object",
+ "title": "Node",
+ "description": "A node object.",
+ "example": "[nodes.Earth]\ntext = \"Earth is a planet of the solar system.\"",
+ "default": null,
+ "properties": {
+ "text": {
+ "type": "string",
+ "description": "The text content of this node."
+ },
+ "title": {
+ "type": "string",
+ "description": "The node display title, useful to make it distinct from the ID.",
+ "default": "The node's ID."
+ },
+ "listed": {
+ "type": "boolean",
+ "description": "Whether this node is shown in listing pages.",
+ "default": true
+ },
+ "redirect": {
+ "type": "string",
+ "description": "A node ID to where any requests for this node will be redirected.",
+ "default": null
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "properties": {
+ "root_node": {
+ "type": "string",
+ "title": "Root node ID",
+ "description": "The ID of node highlighted in the homepage as the graph root.",
+ "example": "MyNode",
+ "default": null
+ },
+ "nodes": {
+ "title": "Nodes",
+ "description": "The graph's nodes.",
+ "default": null,
+ "type": "object",
+ "additionalProperties": {
+ "$ref": "#/$defs/node"
+ },
+ "propertyNames": {
+ "pattern": "^[^-][^!@#$%^&*;:/~| \\]\\[()\\\\]*$"
+ }
+ },
+ "meta": {
+ "type": "object",
+ "properties": {
+ "config": {
+ "type": "object",
+ "properties": {
+ "content_language": { "type": "string" },
+ "footer_credits": { "type": "boolean" },
+ "error_poem": { "type": "boolean" },
+ "node_selector": { "type": "boolean" },
+ "navbar_search": { "type": "boolean" },
+ "about": { "type": "boolean" },
+ "footer_text": { "type": "string" },
+ "acknowledgments": { "type": "string" }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+ }
+ },
+ "additionalProperties": false
+}
diff --git a/static/graph.toml b/static/graph.toml
index 491d246..df35c11 100644
--- a/static/graph.toml
+++ b/static/graph.toml
@@ -1,28 +1,94 @@
-root_node = "Documentation"
+#:schema ./graph-schema.json
-[nodes.Documentation]
+root_node = "Introduction"
+
+[nodes.Introduction]
+text = """
+## What is en?
+
+en is a writing tool. It was designed for complex, conceptually heavy projects, where the relationships between terms matter and possibly have their own attributes. You can use it to write non-linear, connected textual works and have their references to which other mapped out as a |graph| of metadata-rich, interrelated information. This very website is running en.
+
+It works by ingesting plain text files written in |TOML|, a file format that focuses on being human-readable but that can also be directly interpreted by computer programs. These files contain your node definitions and allow en to construct a human-readable website that makes your graphs' nodes browsable, searchable and listed in relation to each other or as a shallow tree of nodes. It also serves this graph as raw data for integration with other tools that can further analyze and transform what you have written.
+
+## Motivation
+
+en was created out of the desire to write a book that did not follow a linear progression. But it can be used for note-taking, studying, documentation, encyclopedic content and any other format that benefits from a focus on the connections between pages. It aims to remove the constraints imposed by trying to mimic the linearity of typical nonfiction writing.
+
+It's described as a "writing instrument" because it's not so much about the presentation or even the web format. While that's the medium for this particular implementation, you can notice en serves its raw data in both TOML and JSON. It's first and foremost about mapping out and structuring written thoughts.
+
+Because your en graph is defined in simple plain-text files, you can add new pages easily from a few lines and start connecting them. Instead of having to create a dedicated file or resource for each new entry you find deserving of observation, with its own beginning and end, its own "I'm empty, fill me to completion" demeanor, you can stay in the flow of your sprawling thoughts. This is meant to fit the specific wiring of minds whose thoughts spread and fork quickly and often, whether to great depth or across wide expanses.
+
+## What's ahead
+
+en is in its infancy. Right now, most of the work is focused on making the markup syntax more robust. Some interesting features planned include:
+
+- Multi-file graphs, including single-file node definitions with TOML frontmatter
+- Richer node connection metadata, with builtin connection kinds and special rendering styles
+- More node metrics, sorting options and full-text search
+- New render formats: static website, single page and PDF/EPUB formats with paper-friendly metadata
+- JSON schema for language server integration
+- Separating the server from the source-to-source translator, allowing en's markup syntax to be used as a standalone compile-to-HTML language
+- Adding CLI options to make it more practical to manipulate a graph, such as adding new nodes or querying your graphagarn
+- Hypergraphs, enabling cross-graph references and letting the user choose which graph to render
+
+If you like what you see and are curious about en's future, take a look at the |roadmap| for a more comprehensive view of what else is to come.
+
+## Get started
+
+See the |Get Started|GetStarted| page to learn how to install and use en.
+"""
+
+[nodes.GetStarted]
+title = "Get Started"
text = """
## Installation
-For now, if you want to try en, you must build it yourself.
+### Pre-built binaries
-In an environment with a |Rust toolchain|https://rustup.rs/ and Git installed, run:
+The easiest way to get started is by downloading a pre-built binary.
+
+x64 Linux binaries are available from the |git.jutty.dev package registry|https://git.jutty.dev/jutty/-/packages/generic/en|:
+
+%
+ Platform ! Download
+ x64 Linux GNU | |en-x64-linux-gnu|https://git.jutty.dev/api/packages/jutty/generic/en/{{ en_version }}/en-x64-linux-gnu|
+ x64 Linux musl | |en-x64-linux-musl|https://git.jutty.dev/api/packages/jutty/generic/en/{{ en_version }}/en-x64-linux-musl |
+%
+
+If in doubt, it is likely your system uses the GNU libc. Regardless, the musl binary is statically compiled and should run on mostly any x64 Linux system.
+
+Other platforms may be supported in the future depending on CI resources.
+
+### Build from source
+
+If you are on another platform or simply prefer starting from source, you can also build en yourself.
+
+You will need:
+
+- For en itself, a |Rust compiler|https://rustup.rs/
+- For dependencies, a C compiler (e.g. `gcc`)
+
+Given the above is satisfied, you can build directly through Cargo:
`
-git clone https://codeberg.org/jutty/en
-cd en
-cargo build --release
+cargo install --git https://codeberg.org/jutty/en --tag v{{ en_version }}
`
-The en binary will be in `target/release/en`.
+And you should now have the `en` command available on your shell.
-You can start it and point it to an address, port and graph:
+The `cargo install` example shown above will build en from the last tagged release, which should be more stable. You can remove the `--tag v{{ en_version }}` part if you'd like to build the most recent development sources.
+
+For more details on building from source, see |SourceBuild|.
+
+## Usage
+
+Once you have installed en, run it and point it to your graph:
`
-en --host localhost --port 3003 --graph ./graph.toml
+en --graph my-graph.toml
`
-See |CLI| for defaults and details on the CLI options.
+See |CLI| for defaults and details on the available options.
## Graph Syntax
@@ -44,11 +110,13 @@ The main electronic component of a computer is its |motherboard|.
\"""
`
+In |the future|Roadmap, en should support both individual node files with TOML frontmatter and also multiple TOML files containing several nodes each. In the current implementation, all nodes live in a single `graph.toml` file.
+
Some special syntax is allowed inside the node text. See |Syntax| for supported features.
A node can have several other attributes. See |Node| for details on all of them.
-## Connections
+### Connections
Nodes can have connections between each other. Each node page lists its outgoing and incoming connections.
@@ -56,36 +124,105 @@ The simplest kind of connection is achieved by creating an anchor to another nod
`
[nodes.Quark]
-text = "Quarks are subatomic particles that form |hadron|s".
+text = "Quarks are subatomic particles that form |hadron|s."
`
Here, a connection is created from the node with ID `Quark` to the node with ID `Hadron`. See |AnchorSyntax| for the various ways you can link to other nodes from within the node text itself.
-Even if a node is not mentioned in the node text, you can still add connections to it. For simple connections without any associated properties, you can simply add links:
+There are several different ways to connect nodes, including ones where you can add metadata to the connection itself. See |Connections| for more details.
+
+## Where to go from here
+
+- Dive deeper into the |syntax| used to write your graph
+- Glimpse into en's future in the |roadmap|
+- Visit the |data endpoints|/data| for a raw view of the graph
+- See an index of all pages in the |tree|/tree|
+- Look under the hood in the |source code|https://codeberg.org/jutty/en repo
+"""
+
+[nodes.Connections]
+text = """
+A connection is a link from one node to another. As shown in |GetStarted|, the simplest way to create them is by adding an |anchor|Syntax#Anchors| in the node text itself. However, there are other ways to create connections between nodes.
+
+## Links
+
+Even if a node is not mentioned in the node text, you can still add connections to it.
+
+For simple connections without any associated properties, you can simply add links, which are lightweight connections without any metadata aside from the automatically determined source and destination:
`
[nodes.Quark]
text = "A subatomic particle that forms hadrons."
-links = [ "Particle", "Hadron" ]
-`
+links = [ "Particle", "Hadron" ] `
This will create two outgoing connections from Quark: to Particle and to Hadron.
-For metadata-rich connections, which allow you to add properties to the connection, you can use the full connection syntax:
+## Rich connections
+
+For richer connections that have their own properties, you can use the full connection syntax:
`
-[[nodes.Realism.connections]]
-to = "Surrealism"
-kind = "contrast"
+[nodes.Earth.connections.Moon]
+kind = "Satellite"
+
+[nodes.Earth.connections.MilkyWay]
+kind = "Galaxy"
`
-This will create a connection from the node with ID `Realism` to a node with ID `Surrealism` and add the "contrast" kind to the connection. See |Connections| for the existing kinds and how they affect your graph.
+This will create connections from the node with ID `Earth` to the nodes with ID `Moon` and `MilkyWay` and add the "Satellite" and "Galaxy" kinds to each connection, respectively. This will add a corresponding CSS class with the same name to the connection when it's rendered so you can style it in special ways and is also reflected in the |output formats|outputs.
"""
-[nodes.docs]
-redirect = "Documentation"
-hidden = true
+[nodes.Outputs]
+text = """
+en take as its input one or more graph files containing your node definitions. It then processes your graph, looks for connections and configuration values and produces one or more outputs depending on your settings:
+
+- A browsable, live-served website (such as this one)
+- A |TOML| representation of the graph that can be used as a basis to generate other, adapted graphs
+- A JSON representation of the graph that can be further analyzed and interpreted with third-party tools
+
+The output formats are not simply a translation of the input, but enrich them. Among other things, they translate en's |markup syntax|Syntax into HTML, add metrics about how nodes are connected and flag which missing nodes are most sought after by dangling connections.
+"""
+
+[nodes.SourceBuild]
+text = """
+An overview on building from source is available in the |Get Started|GetStarted#Build page. This page contains a more detailed and considered approach for those interested.
+
+en is developed on NixOS and builds are tested on both Debian and Alpine, meaning en should compile and run on both glibc and musl systems.
+
+## Dependencies
+
+A Rust toolchain is required to build en itself and can be installed through |rustup|https://rustup.rs/|.
+
+For compiling the en dependencies, you will also need a C toolchain: a compiler and a libc (e.g. `gcc` + `glibc` or `clang` + `musl`), which may already be installed on your system.
+
+For the two tested systems, all you need are the following packages:
+
+%
+ Distribution ! Needed packages
+ *Debian* | `gcc` `libc6-dev`
+ *Alpine* | `clang`
+%
+
+You may also need `curl`, `git` and `ca-certificates` depending on how you will fetch the source code.
+
+## Building from a Git clone
+
+Aside from the `cargo install` approach described in |GetStarted|GetStarted#Build, you can alternatively fetch the code yourself using Git, which allows you to inspect and change it before compiling:
+
+`
+git clone -b v{{ en_version }} --single-branch https://codeberg.org/jutty/en
+cd en
+cargo build --locked --release
+`
+
+In this case, the `en` binary will be in `target/release/en`.
+
+## Runnable examples
+
+You can find the exact commands used to test installation on both systems in the |containers|https://codeberg.org/jutty/en/src/branch/main/containers| directory of the en source repository.
+
+"""
[nodes.Node]
text = """
@@ -97,7 +234,7 @@ A node is defined in your graph file starting with a table header of the form:
Where `ID` is an identifier of your choice.
-While the |TOML| specification is quite flexible regarding what characters can make up this identifier, it's recommended that you keep it simple and use only letters and numbers. See |AnchorSyntax| for more details on why.
+While the |TOML| specification is quite flexible regarding what characters can make up this identifier, it's recommended that you keep it simple. Non-English characters are fine, but characters with special meaning in |en syntax|Syntax and URL parsing might lead to unexpected results. See |AnchorSyntax| for details.
## Fields
@@ -107,14 +244,14 @@ Nodes can have several optional fields that alter how en interprets and displays
- `text`: The textual content that is shown when the node is accessed
- `redirect`: Where to redirect any attempt to access the node
- `links`: An array of identifiers for other nodes to which this node is connected
-- `hidden`: Whether this node should be listed in the index and tree pages. This won't prevent the node from being found or linked to directly through its ID
+- `listed`: Whether this node should be listed in the index and tree pages. This won't prevent the node from being found or linked to directly through its ID
## Example
`
[nodes.Citrus]
title = "Citrus Trees"
-hidden = false
+listed = true
text = "Citrus is a |genus| of trees known mainly for its fruits."
redirect = "Citric"
links = [ "Orange", "Lemon", "Lime", "Grapefruit", ]
@@ -126,7 +263,7 @@ to = "Citric acid"
### Default values
-The example above has all fields in it for completeness, but all fields have default values and are therefore optional. This means that explicitly writing `hidden = false` is the same as not setting it at all.
+The example above has all fields in it for completeness, but all fields have default values and are therefore optional. This means that explicitly writing `listed = true` is the same as not setting it at all.
The default values for unset fields are:
@@ -134,7 +271,7 @@ The default values for unset fields are:
- `text`: An empty string (i.e. `text = ""`)
- `redirect`: An empty string
- `links`: An empty array (i.e. `links = []`)
-- `hidden`: `false`
+- `listed`: `true`
"""
[nodes.CLI]
@@ -142,32 +279,58 @@ title = "CLI Options"
text = """
You can set the hostname, port and graph file path using CLI options:
-For the hostname, use `-h` or `--hostname`:
-
`
-en -h localhost
-en --hostname 10.120.0.5
+en --hostname 10.0.1.2 -p 443 --graph ./graphs/my-graph.toml
`
-If unspecified, the default is `0.0.0.0`.
+## Options
-For the port, use `-p` or `--port`:
+### Graph
-`
-en -p 3003
-en --port 3000
-`
+The relative or absolute path to the graph definition |TOML| file.
-If unspecified, the default is to use a random available port assigned by the operating system.
+*Variants:* `--graph`, `-g`
-For the graph path, use `-g` or `--graph`:
+*Default:* `./static/graph.toml`
+
+*Examples:*
`
en -g graph.toml
en --g ./static/my-graph.toml
`
-If unspecified, the default is `./static/graph.toml`.
+### Hostname
+
+The IP address where the en server will be accessible.
+
+*Variants:* `--hostname`, `-h`
+
+*Default:* `0.0.0.0`
+
+*Examples:*
+
+`
+en -h localhost
+en --hostname 10.120.0.5
+`
+
+### Port
+
+The port where the en server will be accessible.
+
+*Variants:* `--port`, `-p`
+
+*Default:* A random available port assigned by the operating system
+
+*Examples:*
+
+`
+en -p 3003
+en --port 3000
+`
+
+## Using multiple options
You can combine these options as you wish:
@@ -188,7 +351,7 @@ If you are familiar with Markdown|https://en.wikipedia.org/wiki/Markdown|, you'l
## Anchors
-Anchors have the following basic syntax:
+Anchors are the most important and powerful syntactic element you will work with because they can create connections between nodes when you use them. They have the following basic syntax:
`
anchor|destination
@@ -197,11 +360,24 @@ anchor|destination
For example:
`
-DRC|DemocraticRepublicOfTheCongo
+particles|ParticlePhysics
+`
+
+This example will render as the word "particles" pointing to a node with ID `ParticlePhysics` because the destination is not an external URL.
+
+When both sides are the same, you can simply write:
+
+`
+|ParticlePhysics|
+`
+
+An external anchor looks like this:
+
+`
docs|https://en.jutty.dev/node/Documentation
`
-As shown above, anchors can point to external addresses. These are identified by the presence of either a `:` or a `/` character in the destination. Otherwise, the anchor will point to a node with an ID matching the destination. This means your anchors to external URLs, special handlers such as `mailto:user@domain.com` and destinations relative to the website root like `/about` will all work as intended without being interpreted as node IDs.
+External anchors are identified by the presence of either a `:` or a `/` character in the destination. This works for special handlers, such as `mailto:user@domain.com`, and destinations relative to the website root like `/about`.
If the left side contains spaces, you need a leading `|` character:
@@ -209,61 +385,25 @@ If the left side contains spaces, you need a leading `|` character:
|en docs|https://en.jutty.dev/node/Documentation
`
-To make a plain address clickable, wrap it in two `|` characters:
+To make a plain address an anchor, wrap it in two `|` characters:
`
|https://en.jutty.dev|
`
-### Trailing characters in anchors
-
-For internal anchors, most punctuation is automatically separated from the anchor destination so you can simply write:
-
-`
-This gem|PreciousStone, though green, was not an emerald.
-`
-
-However, for external anchors, you want to add a third `|` to explicitly set the end because external URLs can have all sorts of arbitrary characters.
-
### Node anchors
Because anchors between nodes are central to en, there is special syntax to make them as fluid as possible to create without cluttering the text too much.
-A node ID wrapped in two `|` characters will become an anchor to that node:
+en can resolve IDs case insensitively (with priority to case-sensitive matches), will ignore trailing punctuation and a single `s` character for plurals, and will also collapse spaces when trying to resolve an ID, so you can also write:
`
-|ParticlePhysics|
+check out the en |documentation|, or look at the |example|s.
`
-And two words separated by a single anchor allow you to set a display text and destination:
+If there is a node with id Documentation and another with id Example, they'd be linked to by the linked anchors.
-`
-particles|ParticlePhysics
-`
-
-This example will render as "particles|ParticlePhysics": the word particles pointing to a node with id `ParticlePhysics`.
-
-en can resolve IDs case insensitively (with priority to case-sensitive matches) and will also collapse spaces when trying to resolve an ID, so you can also write:
-
-`
-check out the |en documentation|
-`
-
-And if an anchor with the id `enDocumentation` or any other case-insensitive combination exists, it will land on it.
-
-In summary, all of the anchors below are valid and lead to the same page:
-
-`
-|syntax|Syntax
-Syntax|syntax
-Syntax|syn tax|
-
-|Syntax|
-|syntax|
-|syn tax|
-`
-
-While flexible, this can sometimes be ambiguous. See |AnchorSyntax| for some caveats regarding anchors.
+While flexible, this can sometimes be ambiguous. See |AnchorSyntax| for more details and caveats regarding anchors.
## Formatting
@@ -276,38 +416,6 @@ Supported formatting syntax includes:
To apply these, you can wrap a word in the formatting operators, so for instance `*this*` will be rendered as *this* and `~~this~~` as ~~this~~.
-## Paragraphs
-
-A block of lines not separated by an empty line is always joined together. This means if you write:
-
-`
-a
-b
-c
-`
-
-You still get "a b c" as a result.
-
-The exception to this are lists, which are explained below and must have their lines grouped together.
-
-## Lists
-
-A block of lines starting with a `-` character will be rendered as an unordered list:
-
-`
-- cyan
-- amber
-- crimson
-`
-
-Lines starting with a `+` character will create numbered lists instead:
-
-`
-+ ichi
-+ ni
-+ san
-`
-
## Checkboxes
You can use `[ ]` and `[x]` to render checkboxes:
@@ -317,31 +425,241 @@ You can use `[ ]` and `[x]` to render checkboxes:
- [x] done
`
-## Raw HTML
+- [ ] not done
+- [x] done
-If you need some more advanced feature that is not supported directly by en's markup snytax, you can always just write plain HTML and it will be passed along. For example, you could render a table:
+## Blocks
+
+A block is any group of lines separated by empty lines:
`
-<table>
- <tr>
- <td> Hi, </td>
- <td> *HTML*! </td>
- </tr>
-</table>
+block A
+still block A
+block A's last line
+
+block B starts here
+block B ends here
+
+this is block C
`
-Which will render to:
+By default, a block not starting with any special syntax is a paragraph, such as this very line you are reading.
-
+Some blocks will join the lines together, meaning even if you write:
-Notice that, as shown in this example, you can mix en syntax and HTML. You might want to add a space between your HTML tags and en special syntax so the boundary is clearer, but otherwise they don't tend to overlap since the symbols most used in HTML are not special in en.
+`
+a
+b
+c
+`
-If you want to avoid either one of these syntaxes from being interpreted specially, you should escape the relevant characters as explained in the next section.
+You still get "a b c" as a result. This is the case for paragraphs, but not for lists, verse blocks, tables and preformatted text. Blockquotes support both modes.
+
+This is useful when editing your text, allowing you to break some thoughts and special syntax without losing control over where your paragraph ends, particularly when handling huge paragraphs.
+
+If you want to force lines to break, you can use a `<` character at the end of a line:
+
+`
+a <
+b <
+c <
+`
+
+Which renders as:
+
+a <
+b <
+c <
+
+While useful to break a few lines on demand, if you have a large block of lines you want to break this can become cumbersome. That's where verse blocks are useful.
+
+### Verse
+
+Verse blocks are delimited by a `&` character at their first and last line and are useful to avoid precisely this line-joining behavior of paragraphs. They will break all lines without need for a trailing `<` character:
+
+`
+&
+ these lines
+ break just fine
+ once they are over
+&
+`
+
+&
+ these lines
+ break just fine
+ once they are over
+&
+
+### Quotes
+
+A block of lines starting with a `>` character will render as a quote:
+
+`
+> Who'll change old lamps for new ones?
+`
+
+> Who'll change old lamps for new ones?
+
+Quote blocks have two forms. If you prepend all blocks with a `>`, line breaks will be preserved, not collapsing the whole quote into a single line:
+
+`
+> When I was alive
+> I was dust which was,
+> But now I am dust in dust
+> I am dust which never was.
+`
+
+> When I was alive
+> I was dust which was,
+> But now I am dust in dust
+> I am dust which never was.
+
+If you would like the quote to be collapsed into a single line instead, you can leave just the first `>` and continue until the next empty line:
+
+`
+> And should I feel kindness towards my enemies?
+No: from that moment I declared everlasting war against the species,
+and more than all, against him who had formed me
+and sent me forth to this insupportable misery.
+`
+
+> And should I feel kindness towards my enemies?
+No: from that moment I declared everlasting war against the species,
+and more than all, against him who had formed me
+and sent me forth to this insupportable misery.
+
+You can still use `<` characters to force line breaks in this case.
+
+#### Citation
+
+To add a citation to your quote block, start a line with two `-` characters:
+
+`
+> i sat down next to her
+> with a large frosty _bandito_
+> she gazed at the ghost of me
+> asked _“amigo, como esta”_
+-- Assotto Saint, Lady & Me
+`
+
+> i sat down next to her
+> with a large frosty _bandito_
+> she gazed at the ghost of me
+> asked _“amigo, como esta”_
+-- Assotto Saint, Lady & Me
+
+If you have a more complex citation, you can use multiple lines starting with `--`. All such lines will be joined together in the citation. If you need to break lines, use the `<` character at the end of a line:
+
+`
+> Dois grandes mitos dominam a história oficial do Brasil:
+ o mito da índole pacífica do brasileiro e o da "democracia racial".
+-- Benedita da Silva,
+-- |Speech on the Federal Senate|https://www25.senado.leg.br/web/atividade/pronunciamentos/-/p/pronunciamento/165765|,
+-- March 3rd, 1995 <
+-- International Day for the Elimination of Racial Discrimination
+`
+
+> Dois grandes mitos dominam a história oficial do Brasil:
+ o mito da índole pacífica do brasileiro e o da "democracia racial".
+-- Benedita da Silva,
+-- |Speech on the Federal Senate|https://www25.senado.leg.br/web/atividade/pronunciamentos/-/p/pronunciamento/165765|,
+-- March 3rd, 1995 <
+-- International Day for the Elimination of Racial Discrimination
+
+The first URL found in your citation will be used as the blockquote element's `cite` value.
+
+### Lists
+
+A block of lines starting with a `-` character will be rendered as an unordered list:
+
+`
+- cyan
+- amber
+- crimson
+`
+
+- cyan
+- amber
+- crimson
+
+Lines starting with a `+` character will create numbered lists instead:
+
+`
++ ichi
++ ni
++ san
+`
+
++ ichi
++ ni
++ san
+
+In both kinds of lists, you can use an uniform amount of indentation to nest the items:
+
+`
+- purple
+ - red
+ - blue
+- orange
+ - red
+ - yellow
+ - red
+ - green
+`
+
+- purple
+ - red
+ - blue
+- orange
+ - red
+ - yellow
+ - red
+ - green
+
+### Tables
+
+Tables are blocks delimited by a sole `%` on its own line:
+
+`
+%
+ Country ! Capital
+ Colombia | Bogotá
+ Belgium | Brussels
+ Palestine | Jerusalem
+ Zambia | Lusaka
+%
+`
+
+%
+ Country ! Capital
+ Colombia | Bogotá
+ Belgium | Brussels
+ Palestine | Jerusalem
+ Zambia | Lusaka
+%
+
+Table cells are delimited by either a `!` for headers or `|` for common cells. These delimiters must be surrounded by at least one space to each side and are optional at the first and last position of each line.
+
+This means you can use any of the following formats:
+
+`
+%
+ middle | only
+ tail | only |
+ | lead | only
+ | fully | wrapped |
+%
+`
+
+%
+ middle | only
+ tail | only |
+ | lead | only
+ | fully | wrapped |
+%
+
+Because at least one space is required around each delimiter, you must indent the table inside the surrounding `%` markers by at least one space.
## Rendering unformatted text
@@ -351,6 +669,8 @@ The backtick character `\\`` can be used to render unformatted blocks and inline
The asterisk `*` is special in en markup syntax.
`
+> The asterisk `*` is special in en markup syntax.
+
Using the syntax above, the asterisk won't be interpreted as the start of bold formatting and instead will be shown like this: `*`.
This is useful for code but also for rendering characters with special meaning you wish to mention literally.
@@ -364,6 +684,32 @@ everything in here will be rendered without formatting
`
Finally, you can precede any character with a `\\\\` to fully _escape_ that character from being interpreted. Because |TOML| also treats backslashes specially, you'll likely need to use double slashes, as in `\\\\\\\\`, unless you wrap your TOML strings in single quotes. See |Escaping| for more details and examples.
+
+## Raw HTML
+
+If you need some more advanced feature that is not supported directly by en's markup syntax, you can always just write plain HTML and it will be passed along. For example, you could render a form:
+
+`
+<form style="text-align: center;">
+ <label for="name"> *__Name__* </label>
+ <input type="text" id="name"/>
+ <input type="submit"/>
+</form>
+`
+
+
+
+Notice that, as shown in this example, you can mix en syntax and HTML. You might want to add a space between your HTML tags and en special syntax so the boundary is clearer, but otherwise they don't tend to overlap since the symbols most used in HTML are not special in en with the exception of `<`, which is interpreted specially only at the end of lines.
+
+If you want to avoid either one of these syntaxes from being interpreted specially, you should escape the relevant characters as explained in the previous section.
+
+## Known issues
+
+- Nesting multiple different formatting symbols is currently supported only in a few cases. Better nesting is on the |roadmap|, but currently may not work as expected.
"""
[nodes.Escaping]
@@ -376,15 +722,15 @@ If you want to render a literal backslash, you can escape the backslash itself b
## Interactions with TOML escaping
-Notice that TOML itself also handles escape codes, so to pass a backslash you will need to escape it as a double backslash inside strings delimited by double quotes or triple double quotes. You can use a single backslash inside a string delimited by single quotes:
+Notice that |TOML| itself also handles escape codes, so to pass a backslash you will need to escape it as a double backslash inside strings delimited by double quotes or triple double quotes. You can use a single backslash inside a string delimited by single quotes:
`
[node.Double]
-text = "You need double slashes to escape an asterisk here: \\\\\\\\*"
+text = "You need double slashes here: \\\\\\\\*"
[node.TripleDouble]
text = \"""
-Just like here: \\\\\\\\*
+And here: \\\\\\\\*
\"""
[node.Single]
@@ -396,7 +742,7 @@ Here too: \\\\*
'''
`
-This has nothing to do with en's markup syntax per se, it's just a consequence of how backslashes are also special in |TOML| syntax. For more details, see the |TOML documentation on Strings|https://toml.io/en/v1.1.0#string|.
+This has nothing to do with en's markup syntax _per se_, it's just a consequence of how backslashes are also special in TOML syntax. For more details, see the |TOML documentation on Strings|https://toml.io/en/v1.1.0#string|.
## Interactions with HTML
@@ -404,7 +750,7 @@ en will happily accept HTML code and pass it along to the browser, so you can us
If you want to prevent a particular part of your text from being interpreted as HTML, you can escape it |as you normally would|https://developer.mozilla.org/en-US/docs/Glossary/Character_reference|.
-The fact you are using HTML does not exclude en syntax from being interpreted, although this may change in the future. Presently, you need to escape en markup syntax if you want it printed literally even inside HTML tags. This matters because en uses its syntax to create connections between your graph's nodes and makes several decisions based on these relations.
+The fact you are using HTML does not exclude en syntax from being interpreted, although this may change in the future. Presently, you need to escape en markup syntax if you want it printed literally even inside HTML tags. This matters because en |uses its syntax to create connections|AnchorSyntax| between your graph's nodes and makes several decisions based on these relations.
"""
[nodes.AnchorSyntax]
@@ -414,37 +760,32 @@ en's anchor syntax can be very flexible, but some situations lead to ambiguity.
In short, following these two rules should keep you out of trouble:
-- *Avoid special characters in your node IDs*: |TOML| allows you to use a wide range of characters in identifiers, but when writing your graph it's better keep your IDs simple
-- When needed, use full three-pipe `|text|destination|` syntax to make your anchors fully unambiguous
+- *Avoid characters with special meanings in your node IDs*: |TOML| allows you to use a wide range of characters in identifiers, but when writing your graph it's better keep your IDs free of some characters. Accents and ideograms are fine, but characters such as `#`, `&`, `:` and `/` are not because they are interpreted differently by en and URL parsers, which might lead to unexpected results
+- *Know you can be explicit to force proper evaluation*: When needed, use full three-pipe anchors, as in `|text|destination|`, to make your anchors fully unambiguous
-## Punctuation in destinations
+## Basic anchor
+See the |Anchors section in the Syntax page|Syntax#Anchors| for the basic anchor syntax. The following sections go into more detail on some edge cases.
-Consider this example:
+### Trailing characters in anchors
+
+For internal anchors, most punctuation is automatically separated from the anchor destination so you can simply write:
`
-|gem|PreciousStone
-|PreciousStone|,
+This gem|PreciousStone, though green, was not an emerald.
`
-Both point to the node with ID `PreciousStone`, as they indeed _seem_ to. But if we didn't treat punctuation differently, we'd have:
+> This gem|PreciousStone, though green, was not an emerald.
-`
-|a|b
-|a|b
-`
+This is one of the reasons to avoid punctuation in your node IDs.
-For this reason, some symbols are treated specially at the trailing boundary of anchors.
-
-Punctuation won't be considered as a possible destination, so you can write the previous example and have it behave as expected.
-
-This is one of the reasons special symbols in your node IDs can lead to trouble.
-
-These are the punctuation symbols that are treated specially:
+The punctuation symbols that are ignored at the trailing boundary of anchors are:
`
, . : ; ? ! ( ) ' " ` | _ * \\
`
+For external anchors, you often must add a third `|` to explicitly set the end because external URLs can have all sorts of arbitrary characters. This is not necessary for spaces, but it is for other characters.
+
## Plural node anchors
Something similar applies to the lowercase letter `s`:
@@ -456,10 +797,10 @@ We found three |boat|s at the marina.
This conveniently lets you write plural words as anchors to their singular form without having to write:
`
-We found three boats|boat at the marina.
+We found three boats|Boat at the marina.
`
-Which is annoyting to write and also makes the text a lot noisier.
+Which is annoying to write and makes the text a lot less fluid.
Unlike with punctuation, this doesn't mean you can't have a node with the ID `s`. You can, but you'll have to write your anchors to it always with a trailing pipe:
@@ -469,50 +810,94 @@ The |letter s|s| is important so we dedicated a whole page to it: |s|!
## Spaced node anchors
-Like punctuation, node IDs shouldn't have spaces. If you write a node anchor with spaces, it will be collapsed:
+If you write a node anchor with spaces, it will be collapsed:
`
-This |Node Anchor| will work as if it were |Node Anchor|NodeAnchor|.
+This |Node Anchor| will work as if it were |NodeAnchor|.
`
-As long as you don't have a page with the ID `NodeanchoR` and another with the ID `NodeAnchor`, this shouldn't be a problem.
+Accordingly, node IDs should not have spaces because, among other things, this feature makes it impossible to create an anchor to them.
-Because node ID resolution redirects to a lowercase match as a fallback to an exact match, you can write:
+## Case-insensitive fallbacks
+
+Because node ID resolution redirects to a lowercase match if it can't find an exact match, you can write:
`
The next |precious stone| was stolen in 1973.
`
-And the visible text will be preserved as "precious stone" but be able to point to an ID such as `PreciousStone`.
+And the visible text will still display as "precious stone" but point to an ID such as `PreciousStone`.
+
+This is not a problem if you want to refer to a specific ID that differs only in case because the case-sensitive match takes priority.
## URL detection
en must differentiate node anchors from outgoing URLs:
`
-|sample|Example|
-|sample|https://example.com|
-
-|Example|
-|https://example.com|
+|internal|Internal|
+|external|https://external.example.com|
`
-It does this by looking at the destination and checking if it contains a `:`. That's one more reason to avoid this character in your node IDs.
+It does this by looking at the destination and checking if it contains a `/` or `:`. That's one more reason to avoid these characters in your node IDs.
"""
-[nodes.en]
+[nodes.Customization]
text = """
-en is a tool to write non-linear, connected pieces of text and have their references mapped out as a |graph| of connected information.
+You can customize several aspects of en by overriding its default templates, styles and other assets.
-It works by ingesting a |TOML| file containing your node specification and serving it as a website that allows nodes to be browsed, searched and listed in relation to each other or as a shallow tree of nodes.
+## The `public` directory
-## Motivation
+The `static/public` directory is searched by en in the current working directory and can also be |passed as a command line option|CLI. All files placed inside this directory will be served by the en server as static files. You can create directories and organize files as you see fit, and then reference them through custom templates and includes.
-en was created out of the desire to write complex, long-form descriptions of a personal worldview without being constrained or getting stuck trying to mimic the linearity of a typical philosophy book.
+If you place a file in a default path, it will override the default. Namely:
-It's described as a "writing instrument" because it's not so much about the presentation or even the web format. While that's the medium for this particular implementation, you can notice en serves its raw data in both TOML and JSON. It's first and foremost about mapping out and structuring written thoughts.
+- `static/public/assets/favicon.svg`: Website icon as seen on tabs and other UI elements
+- `static/public/assets/style.css`: Main CSS stylesheet
+- `static/public/assets/fonts/fonts.css`: Fonts CSS index mapping the default families `sans`, `serifed`, `mono`, `prose` and `title`. The `prose` family is used for paragraphs such as in the node text content, while the `sans` family is used for UI elements such as the navigation bar and footer.
+
+The en server supports a variety of file types including plain text; data formats such as CSV, TOML and JSON; various font and image formats; and document formats such as PDF and EPUB. If you want to serve a file with a mimetype that is not included among the |builtin ones|https://codeberg.org/jutty/en/src/branch/main/src/router/handlers/mime.rs|, you can use the `mimes` |configuration option|Configuration#mimes|. If you don't, the file will be served with mimetype `application/octet-stream`, which may or may not work depending on what you are actually serving and how it's being consumed.
+
+## Styles
+
+You can override the default CSS and fonts using custom CSS files.
+
+To completely override the default style, you can place your replacement at the default path as explained in the previous section.
+
+If you just want to add small customizations, this can be better accomplished by adding a CSS file as part of a custom headers include, as explained in the next section.
+
+## Templates
+
+en uses the Tera|https://keats.github.io/tera templating engine, which provides several features for creating your own templates.
+
+When starting up, en will look for a `templates` directory in the current working directory. For each template, it looks up the corresponding filename inside this directory. If it can't find one, it will fallback to a default template.
+
+For a list of templates along with their names, see the |templates directory|https://codeberg.org/jutty/en/src/branch/main/templates| in the source code repository.
+
+See the |Tera documentation|https://keats.github.io/tera/docs for a more extensive description of the available features for writing templates.
+
+### Includes
+
+Overriding an entire template can be very verbose, considering the default templates attempt to handle various edge cases.
+
+To make it easier to override the most common use cases, the following templates are consumed as "includes" in specific parts of the main templates if placed inside the `templates` directory with the suffix `.include.html`:
+
+- `header`: Included at the end of the default templates' base header
+- `post-body`: Included after the body in the default base template
+- `favicon`: Replaces the default favicon code
+- `styles`: Replaces the default CSS links
+- `footer`: Replaces the footer
+- `navigation`: Replaces the navigation bar
+- `index-header`: Replaces the block showing the title and subtitle of the website in the index page
+- `index-list`: Replaces the block showing the list of nodes in the index page
+
+For example, to override the block in the header of all pages that globally sets the CSS stylesheets, you can drop a file at `templates/styles.include.html` containing something like:
+
+`
+
+
+`
-Because en is defined in simple configuration files, you can add new pages easily from a few lines and start connecting them. Instead of having to create a dedicated file or resource for each new entry you find deserving of observation, with its own beginning and end, its own "I'm empty, fill me to completion" demeanor, you can stay in the flow of your sprawling thoughts. This is meant to fit the specific wiring of minds whose thoughts spread and fork quickly and often, whether to great depth or across wide expanses.
"""
[nodes.Graph]
@@ -528,9 +913,13 @@ en uses this concept to create a writing tool, allowing you to map out complex t
text = """
TOML is a configuration format that can be easily read and understood by humans and machines alike.
+It was chosen as en's main input format for its obvious semantics, because it's more readable, has friendlier strings compared to alternatives such as JSON and less convoluted indentation compared to YAML.
+
+One of the most valued attributes in en's design is readability. TOML provides powerful multi-line strings that can trim whitespace and literal multiline string that avoid the need for escaping. This couples well with en's own |markup syntax|Syntax.
+
To learn more about TOML, you can visit its website at |https://toml.io|.
-To see the TOML declaration that translates into the rendered graph you are reading right now, visit the "TOML Graph" link on the top navigation bar.
+To see the TOML representation for the graph you are reading right now, visit the |data endpoints|/data|.
"""
[nodes.Acknowledgments]
@@ -565,111 +954,192 @@ en is only possible thanks to a number of projects and people:
## Software
-- Neovim|https://neovim.io/
-- foot|https://codeberg.org/dnkl/foot
-- tmux|https://github.com/tmux/tmux/
-- |Void Linux|https://voidlinux.org/ and its kernel|https://www.kernel.org/
-- LibreWolf|https://librewolf.net/
+- |NixOS|https://nixos.org/|, |Debian|https://debian.org|, |Alpine|https://alpinelinux.org and their kernel|https://www.kernel.org/
+- LibreWolf|https://librewolf.net/ and its upstream |Mozilla Firefox|https://www.firefox.com/
- InkScape|https://inkscape.org/
"""
+[nodes.RedirectTest]
+redirect = "Node"
+
[nodes.Roadmap]
text = """
-- [ ] Performance
- - [ ] Caching
- - [x] Move more logic from Serial to Graph submodules
- - [x] Further centralize state
- - [ ] Reduce O(n) calls in the formats module
-- [ ] Input syntax
- - [ ] Invert where redirects are set
- - [x] Formatting
- - [ ] Blockquotes
- - [x] Nested formatting
- - [x] Headers
- - [x] Preformatted blocks
- - [x] _Oblique_,
- - [x] __Underline__
- - [x] ~~Strikethrough~~
- - [x] *Bold*
- - [x] `Inline code`
- - [x] Lists
- - [x] Nested lists
- - [x] Checkboxes
- - [x] Move this roadmap to en
- - [ ] Special sections
- - [ ] Definition (implies metadata `has_definition`)
- - [ ] See also (implies a kind of connection, e.g. `related`)
- - [ ] Not to be confused with (implies a kind of connection)
- - [ ] Contrast with (implies a kind of connection)
- - [ ] Example (implies metadata `has_example`)
- - [ ] References/influences (implies metadata `has_references`)
-- [ ] Meta-awareness
- - [x] Detached edges
- - [ ] Most linked to nodes
- - [ ] Most linked from nodes
- - [ ] Most linked
-- [ ] Rendering
- - [ ] Sorting of tree, index list and drop-down navigation
- - [ ] Alphabetic
- - [ ] By most linked to
- - [ ] By most linked
- - [ ] Tree
- - [ ] Hide tree leaves from the top level
- - [ ] Branch deeper
- - Customization
- - [ ] Custom assets (favicon, CSS)
- - [x] Drop all hardcoded assets endpoints
- - [ ] Custom header include
- - [ ] Custom templates
- - [ ] Themes
-- [x] Anchors and connections
- - [x] Render detached anchors differently
- - [x] Count connection to a redirect as a connection to the target
- - [ ] Suffix-aware anchors
- - [x] Plural anchors (`|node|s` -> `node`)
- - [x] Ignore trailing punctuation
- - [ ] Conjugation anchors (`|will|ed` -> `will`)
- - [ ] Configurable suffixes
- - [x] Spaced node anchor (`|red fox|` -> `redfox` -> `RedFox`)
- - [x] Automatic connections from anchors
- - [ ] `#` syntax for header ID anchors
- - [ ] Connection kinds
- - [ ] Mutual
- - [ ] Category <-> Membership
- - [ ] Opposite <-> Equivalent
- - [ ] Contrast <-> Similar
- - [ ] Cognate <-> Unrelated
- - [ ] Specialization <-> Generalization
- - [ ] Custom connection kinds
- - [x] External anchors
-- [ ] I/O formats
- - [ ] Output
- - [ ] Add separate TOML endpoints for pre/postprocessed
- - [ ] Render to filesystem
- - [ ] Single-page rendering
- - [x] Make error output more clean when `DEBUG` is unset
- - [ ] Input
- - [ ] Frontmatter format
- - [ ] Multi-file graphs
- - [ ] Multi-graph
-- [ ] Templating
- - [ ] Simplify template code with includes, macros and custom functions
- - [ ] Move compiled templates to a static ref
- - See: |https://keats.github.io/tera/docs/#:~:text=only%20happen%20once|
- - [ ] Reduce whitespace
- - See: |https://keats.github.io/tera/docs/#whitespace-control|
+
+## Upcoming
+
+### v0.5.0-alpha
+- [ ] Docs for custom assets and templates
+- [ ] Custom kind for connections
+- [ ] Hide tree leaves from the top level
+- [x] Fix anchors containing `/` and `#` considered node IDs
+- [x] Fix `PreFormat` blocks rendering HTML tags
+
+### v0.6.0-alpha
+- [ ] Custom header include
+
+### v0.7.0-alpha
+- [ ] Frontmatter format
+- [ ] Multi-file graphs
+
+### v0.8.0-alpha
- [ ] Full-text search
-- [ ] Assess Option return types that should be Result
-## Done
+
-- [x] Redirects
+_See |Changelog|Roadmap#Changelog| for previously released versions._
+
+
+
+
+## Backlog
+These changes are planned, but have not been assigned to an upcoming release yet.
+
+### Syntax
+- [ ] Improve nested formatting
+- [ ] Invert where redirects are set
+- [ ] Special sections
+ - Top-bound
+ - [ ] Top-bound is not included in the summary (tooltip)
+ - Sections
+ - [ ] Definition (implies metadata `has_definition`)
+ - [ ] See also (implies a kind of connection, e.g. `related`)
+ - [ ] Not to be confused with (implies a kind of connection)
+ - [ ] Contrast with (implies a kind of connection)
+ - [ ] Example (implies metadata `has_example`)
+ - Bottom-bound
+ - [ ] References/influences (implies metadata `has_references`)
+ - [ ] Aggregated from the full text content
+
+### Metrics
+- [ ] Most linked to nodes
+- [ ] Most linked from nodes
+- [ ] Most linked
+
+### Rendering
+- [ ] Sorting of tree, index list and drop-down navigation
+ - [x] Alphabetic
+ - [ ] By most linked to
+ - [ ] By most linked
+- Tree
+ - [ ] Branch deeper
+- Customization
+ - [ ] Custom assets (favicon, CSS)
+ - [x] Drop all hardcoded assets endpoints
+ - [x] Custom templates
+ - [ ] user-supplied loading order (e.g. through filenames)
+ - [ ] Themes
+- [ ] Table of contents
+
+### Connections
+- [ ] `#` syntax for header ID anchors
+- Connection kinds
+ - [ ] Mutual
+ - [ ] Category <-> Membership
+ - [ ] Opposite <-> Equivalent
+ - [ ] Contrast <-> Similar
+ - [ ] Cognate <-> Unrelated
+ - [ ] Specialization <-> Generalization
+ - [ ] Custom connection kinds
+ - [x] External anchors
+- [ ] Suffix-aware anchors
+ - [x] Plural anchors (`|node|s` -> `node`)
+ - [x] Ignore trailing punctuation
+ - [ ] Conjugation anchors (`|will|ed` -> `will`)
+ - [ ] Configurable suffixes
+
+### I/O formats
+
+#### Input
+- [ ] Multi-graph
+
+#### Output
+- [ ] Add separate TOML endpoints for pre/postprocessed
+- [ ] Render to filesystem
+- [ ] Single-page rendering
+- [ ] Consider printing parsing errors to console by default
+
+### Templating
+- [ ] Simplify template code with includes, macros and custom functions
+- [ ] Move compiled templates to a static ref
+ - See: |https://keats.github.io/tera/docs/#:~:text=only%20happen%20once|
+- [ ] Reduce whitespace
+ - See: |https://keats.github.io/tera/docs/#whitespace-control|
+
+### Documentation
+- [ ] Generate `meta.config` docs from JSON schema
+
+#### Validation
+- [ ] Finalize JSON schema
+- [ ] Add CI step with `taplo lint`
+
+### Code
+- [ ] Assess `Option` return types that should be `Result`
+
+### Performance
+- [ ] Caching
+- [ ] Reduce O(n) calls in the formats module
+
+### Done
+
+Toggle to expand
+
+#### Syntax
+- Formatting
+ - [x] Blockquotes
+ - [x] Tables
+ - [x] Nested formatting
+ - [x] Headers
+ - [x] Preformatted blocks
+ - [x] _Oblique_,
+ - [x] __Underline__
+ - [x] ~~Strikethrough~~
+ - [x] *Bold*
+ - [x] `Inline code`
+ - [x] Lists
+ - [x] Nested lists
+ - [x] Checkboxes
+ - [x] Move this roadmap to en
+
+#### Connections
+- [x] Count connection to a redirect as a connection to the target
+- [x] Spaced node anchor (`|red fox|` -> `redfox` -> `RedFox`)
+- [x] Automatic connections from anchors
+
+#### I/O formats
+##### Input
+- [x] Array syntax for lightweight connections
+
+##### Output
+- [x] Make error output more clean when `DEBUG` is unset
+
+##### Metrics
+- [x] Detached edges
+
+#### Rendering
+- [x] Render detached anchors differently
- [x] Strip/render some syntax in Tree text preview
- [x] Drop-down navigation
-- [x] Array syntax for lightweight connections
+
+#### Server
+- [x] Redirects
- [x] Automatic IDs
- [x] Automatic titles
- [x] Mismatch between TOML ID and provided ID
+
+#### Performance
+- [x] Move more logic from Serial to Graph submodules
+- [x] Further centralize state
+
+
+
+
+
+## Changelog
+
+### |v0.4.0-alpha|https://codeberg.org/jutty/en/releases/tag/v0.4.0-alpha|
+
+- Embed assets and welcome graph into the binary
+- Source custom templates and assets from `./templates` and `./static/public`
"""
[meta.config]
@@ -678,6 +1148,7 @@ footer_credits = false
error_poem = true
node_selector = true
navbar_search = true
+about = true
footer_text = """
-acknowledgments|Acknowledgments • |source code|https://codeberg.org/jutty/en
+acknowledgments|Acknowledgments • |source code|https://codeberg.org/jutty/en
"""
diff --git a/static/public/assets/fonts/.gitignore b/static/public/assets/fonts/.gitignore
new file mode 100644
index 0000000..309503b
--- /dev/null
+++ b/static/public/assets/fonts/.gitignore
@@ -0,0 +1,2 @@
+**/*.compact.LICENSE
+**/compact.LICENSE
diff --git a/static/public/assets/fonts/LICENSES.sha256sum b/static/public/assets/fonts/LICENSES.sha256sum
new file mode 100644
index 0000000..b2023fc
--- /dev/null
+++ b/static/public/assets/fonts/LICENSES.sha256sum
@@ -0,0 +1,21 @@
+9cc97638cf0185884ac800144b6246c7772f94ff2cc70686afa9574aaea4fa2b ./_canon/CC_BY_ND_4_0_INTERNATIONAL.LICENSE
+00b6b2ffad0a8a99a0497b6474d16296adb91a9d9d83dd745d3148176aa16b7e ./_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE
+5f1cc99e4d0fe6ed3495b8f7fb57bdd07623b99a9f0b2bde6076ef3719f162f9 ./_canon/CC_BY_ND_4_0_INTERNATIONAL.compact.LICENSE
+1d361a8f8e8ce6e68457dcd93fb56e162e6baa3bbb7e7573a290d44399f6b57e ./_canon/SIL_OFL_1_1.LICENSE
+6863ff4dc820f24756b6acfb38a2c6bc19d5b8d71b17030330a6f16eb4cee348 ./_canon/SIL_OFL_1_1.body.LICENSE
+2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./_canon/SIL_OFL_1_1.compact.LICENSE
+3f70f82d58c8f58b91cf8d718621ac1537234eb6f37ee9a83469a321ef46e4db ./cormorant/LICENSE
+2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./cormorant/compact.LICENSE
+c110f34253aced57d6d4f02edce58b171dca3340591a1119e02ea084a4b78f93 ./cormorant/header.LICENSE
+7d5da66dc426b59bbba125049b7016f2011f93724ddf7b7f97ce1911f958b963 ./maven/LICENSE
+2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./maven/compact.LICENSE
+c63dd928ccd5c2c80491b84d1874227536dfced1f1f82cbd900ddc86c59b738b ./maven/header.LICENSE
+1d2892790cc9522de02d3f01ba48d12742862b1a69d04d69752938591efabecd ./mononoki/LICENSE
+2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./mononoki/compact.LICENSE
+20601bbaafe0fe8d6a39527785fc501f242ebae18d1aaa4d5d15a8ac4ff4fff3 ./mononoki/header.LICENSE
+3e57bc17e8ece63050a2ac5aa99a80f87183289b18303d46311199875b4808b7 ./rawengulk/LICENSE
+2533bdb563fb91d70cb719edca0a0cdc8f5cc347d567561b4a87e7509e02073d ./rawengulk/compact.LICENSE
+4d8b5ec962dfeb2813bdeb0762e3b714e68e19f9fbcdb3481d12f018b125308b ./rawengulk/header.LICENSE
+18837f5b671bd48dc6b595a475d8c45ab3e6ae33adb65d9bbeac59c58f77bc24 ./reforma/LICENSE
+2edceb2f872692052b281629777bc5af5386601dd4c437f297f84846f9fa75cf ./reforma/compact.LICENSE
+a3d29ef378426d0b1d9f17364a3d7532ad623a51c8c19a3badc74c23e5e93ef6 ./reforma/header.LICENSE
diff --git a/static/public/assets/fonts/README.md b/static/public/assets/fonts/README.md
new file mode 100644
index 0000000..db3412d
--- /dev/null
+++ b/static/public/assets/fonts/README.md
@@ -0,0 +1,9 @@
+## Known issues
+
+As documented by the source files and hashes in this directory, significant effort was made to preserve the original license files, determine that equally-licensed files have identical licenses and that the vendored license files match the upstream well-known official versions.
+
+In particular, the vendored file for the Reforma font is in Markdown format and as such hard to match against the license file supplied by Creative Commons without substantial reductions in punctuation, spacing and external URLs.
+
+However, because only this font uses such license, it is still a single copy that must end up embedded in the binary. As such, despite a missing matching hash, the vendored version is embedded as-is.
+
+Due to this issue, it was decided that any future font that is a candidate for addition to the project MUST be licensed under some version of the SIL Open Font License.
diff --git a/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.LICENSE b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.LICENSE
new file mode 100644
index 0000000..10fbcae
--- /dev/null
+++ b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.LICENSE
@@ -0,0 +1,393 @@
+Attribution-NoDerivatives 4.0 International
+
+=======================================================================
+
+Creative Commons Corporation ("Creative Commons") is not a law firm and
+does not provide legal services or legal advice. Distribution of
+Creative Commons public licenses does not create a lawyer-client or
+other relationship. Creative Commons makes its licenses and related
+information available on an "as-is" basis. Creative Commons gives no
+warranties regarding its licenses, any material licensed under their
+terms and conditions, or any related information. Creative Commons
+disclaims all liability for damages resulting from their use to the
+fullest extent possible.
+
+Using Creative Commons Public Licenses
+
+Creative Commons public licenses provide a standard set of terms and
+conditions that creators and other rights holders may use to share
+original works of authorship and other material subject to copyright
+and certain other rights specified in the public license below. The
+following considerations are for informational purposes only, are not
+exhaustive, and do not form part of our licenses.
+
+ Considerations for licensors: Our public licenses are
+ intended for use by those authorized to give the public
+ permission to use material in ways otherwise restricted by
+ copyright and certain other rights. Our licenses are
+ irrevocable. Licensors should read and understand the terms
+ and conditions of the license they choose before applying it.
+ Licensors should also secure all rights necessary before
+ applying our licenses so that the public can reuse the
+ material as expected. Licensors should clearly mark any
+ material not subject to the license. This includes other CC-
+ licensed material, or material used under an exception or
+ limitation to copyright. More considerations for licensors:
+ wiki.creativecommons.org/Considerations_for_licensors
+
+ Considerations for the public: By using one of our public
+ licenses, a licensor grants the public permission to use the
+ licensed material under specified terms and conditions. If
+ the licensor's permission is not necessary for any reason--for
+ example, because of any applicable exception or limitation to
+ copyright--then that use is not regulated by the license. Our
+ licenses grant only permissions under copyright and certain
+ other rights that a licensor has authority to grant. Use of
+ the licensed material may still be restricted for other
+ reasons, including because others have copyright or other
+ rights in the material. A licensor may make special requests,
+ such as asking that all changes be marked or described.
+ Although not required by our licenses, you are encouraged to
+ respect those requests where reasonable. More considerations
+ for the public:
+ wiki.creativecommons.org/Considerations_for_licensees
+
+
+=======================================================================
+
+Creative Commons Attribution-NoDerivatives 4.0 International Public
+License
+
+By exercising the Licensed Rights (defined below), You accept and agree
+to be bound by the terms and conditions of this Creative Commons
+Attribution-NoDerivatives 4.0 International Public License ("Public
+License"). To the extent this Public License may be interpreted as a
+contract, You are granted the Licensed Rights in consideration of Your
+acceptance of these terms and conditions, and the Licensor grants You
+such rights in consideration of benefits the Licensor receives from
+making the Licensed Material available under these terms and
+conditions.
+
+
+Section 1 -- Definitions.
+
+ a. Adapted Material means material subject to Copyright and Similar
+ Rights that is derived from or based upon the Licensed Material
+ and in which the Licensed Material is translated, altered,
+ arranged, transformed, or otherwise modified in a manner requiring
+ permission under the Copyright and Similar Rights held by the
+ Licensor. For purposes of this Public License, where the Licensed
+ Material is a musical work, performance, or sound recording,
+ Adapted Material is always produced where the Licensed Material is
+ synched in timed relation with a moving image.
+
+ b. Copyright and Similar Rights means copyright and/or similar rights
+ closely related to copyright including, without limitation,
+ performance, broadcast, sound recording, and Sui Generis Database
+ Rights, without regard to how the rights are labeled or
+ categorized. For purposes of this Public License, the rights
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
+ Rights.
+
+ c. Effective Technological Measures means those measures that, in the
+ absence of proper authority, may not be circumvented under laws
+ fulfilling obligations under Article 11 of the WIPO Copyright
+ Treaty adopted on December 20, 1996, and/or similar international
+ agreements.
+
+ d. Exceptions and Limitations means fair use, fair dealing, and/or
+ any other exception or limitation to Copyright and Similar Rights
+ that applies to Your use of the Licensed Material.
+
+ e. Licensed Material means the artistic or literary work, database,
+ or other material to which the Licensor applied this Public
+ License.
+
+ f. Licensed Rights means the rights granted to You subject to the
+ terms and conditions of this Public License, which are limited to
+ all Copyright and Similar Rights that apply to Your use of the
+ Licensed Material and that the Licensor has authority to license.
+
+ g. Licensor means the individual(s) or entity(ies) granting rights
+ under this Public License.
+
+ h. Share means to provide material to the public by any means or
+ process that requires permission under the Licensed Rights, such
+ as reproduction, public display, public performance, distribution,
+ dissemination, communication, or importation, and to make material
+ available to the public including in ways that members of the
+ public may access the material from a place and at a time
+ individually chosen by them.
+
+ i. Sui Generis Database Rights means rights other than copyright
+ resulting from Directive 96/9/EC of the European Parliament and of
+ the Council of 11 March 1996 on the legal protection of databases,
+ as amended and/or succeeded, as well as other essentially
+ equivalent rights anywhere in the world.
+
+ j. You means the individual or entity exercising the Licensed Rights
+ under this Public License. Your has a corresponding meaning.
+
+
+Section 2 -- Scope.
+
+ a. License grant.
+
+ 1. Subject to the terms and conditions of this Public License,
+ the Licensor hereby grants You a worldwide, royalty-free,
+ non-sublicensable, non-exclusive, irrevocable license to
+ exercise the Licensed Rights in the Licensed Material to:
+
+ a. reproduce and Share the Licensed Material, in whole or
+ in part; and
+
+ b. produce and reproduce, but not Share, Adapted Material.
+
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
+ Exceptions and Limitations apply to Your use, this Public
+ License does not apply, and You do not need to comply with
+ its terms and conditions.
+
+ 3. Term. The term of this Public License is specified in Section
+ 6(a).
+
+ 4. Media and formats; technical modifications allowed. The
+ Licensor authorizes You to exercise the Licensed Rights in
+ all media and formats whether now known or hereafter created,
+ and to make technical modifications necessary to do so. The
+ Licensor waives and/or agrees not to assert any right or
+ authority to forbid You from making technical modifications
+ necessary to exercise the Licensed Rights, including
+ technical modifications necessary to circumvent Effective
+ Technological Measures. For purposes of this Public License,
+ simply making modifications authorized by this Section 2(a)
+ (4) never produces Adapted Material.
+
+ 5. Downstream recipients.
+
+ a. Offer from the Licensor -- Licensed Material. Every
+ recipient of the Licensed Material automatically
+ receives an offer from the Licensor to exercise the
+ Licensed Rights under the terms and conditions of this
+ Public License.
+
+ b. No downstream restrictions. You may not offer or impose
+ any additional or different terms or conditions on, or
+ apply any Effective Technological Measures to, the
+ Licensed Material if doing so restricts exercise of the
+ Licensed Rights by any recipient of the Licensed
+ Material.
+
+ 6. No endorsement. Nothing in this Public License constitutes or
+ may be construed as permission to assert or imply that You
+ are, or that Your use of the Licensed Material is, connected
+ with, or sponsored, endorsed, or granted official status by,
+ the Licensor or others designated to receive attribution as
+ provided in Section 3(a)(1)(A)(i).
+
+ b. Other rights.
+
+ 1. Moral rights, such as the right of integrity, are not
+ licensed under this Public License, nor are publicity,
+ privacy, and/or other similar personality rights; however, to
+ the extent possible, the Licensor waives and/or agrees not to
+ assert any such rights held by the Licensor to the limited
+ extent necessary to allow You to exercise the Licensed
+ Rights, but not otherwise.
+
+ 2. Patent and trademark rights are not licensed under this
+ Public License.
+
+ 3. To the extent possible, the Licensor waives any right to
+ collect royalties from You for the exercise of the Licensed
+ Rights, whether directly or through a collecting society
+ under any voluntary or waivable statutory or compulsory
+ licensing scheme. In all other cases the Licensor expressly
+ reserves any right to collect such royalties.
+
+
+Section 3 -- License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the
+following conditions.
+
+ a. Attribution.
+
+ 1. If You Share the Licensed Material, You must:
+
+ a. retain the following if it is supplied by the Licensor
+ with the Licensed Material:
+
+ i. identification of the creator(s) of the Licensed
+ Material and any others designated to receive
+ attribution, in any reasonable manner requested by
+ the Licensor (including by pseudonym if
+ designated);
+
+ ii. a copyright notice;
+
+ iii. a notice that refers to this Public License;
+
+ iv. a notice that refers to the disclaimer of
+ warranties;
+
+ v. a URI or hyperlink to the Licensed Material to the
+ extent reasonably practicable;
+
+ b. indicate if You modified the Licensed Material and
+ retain an indication of any previous modifications; and
+
+ c. indicate the Licensed Material is licensed under this
+ Public License, and include the text of, or the URI or
+ hyperlink to, this Public License.
+
+ For the avoidance of doubt, You do not have permission under
+ this Public License to Share Adapted Material.
+
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
+ reasonable manner based on the medium, means, and context in
+ which You Share the Licensed Material. For example, it may be
+ reasonable to satisfy the conditions by providing a URI or
+ hyperlink to a resource that includes the required
+ information.
+
+ 3. If requested by the Licensor, You must remove any of the
+ information required by Section 3(a)(1)(A) to the extent
+ reasonably practicable.
+
+
+Section 4 -- Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that
+apply to Your use of the Licensed Material:
+
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+ to extract, reuse, reproduce, and Share all or a substantial
+ portion of the contents of the database, provided You do not Share
+ Adapted Material;
+
+ b. if You include all or a substantial portion of the database
+ contents in a database in which You have Sui Generis Database
+ Rights, then the database in which You have Sui Generis Database
+ Rights (but not its individual contents) is Adapted Material; and
+
+ c. You must comply with the conditions in Section 3(a) if You Share
+ all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not
+replace Your obligations under this Public License where the Licensed
+Rights include other Copyright and Similar Rights.
+
+
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
+
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
+
+ c. The disclaimer of warranties and limitation of liability provided
+ above shall be interpreted in a manner that, to the extent
+ possible, most closely approximates an absolute disclaimer and
+ waiver of all liability.
+
+
+Section 6 -- Term and Termination.
+
+ a. This Public License applies for the term of the Copyright and
+ Similar Rights licensed here. However, if You fail to comply with
+ this Public License, then Your rights under this Public License
+ terminate automatically.
+
+ b. Where Your right to use the Licensed Material has terminated under
+ Section 6(a), it reinstates:
+
+ 1. automatically as of the date the violation is cured, provided
+ it is cured within 30 days of Your discovery of the
+ violation; or
+
+ 2. upon express reinstatement by the Licensor.
+
+ For the avoidance of doubt, this Section 6(b) does not affect any
+ right the Licensor may have to seek remedies for Your violations
+ of this Public License.
+
+ c. For the avoidance of doubt, the Licensor may also offer the
+ Licensed Material under separate terms or conditions or stop
+ distributing the Licensed Material at any time; however, doing so
+ will not terminate this Public License.
+
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+ License.
+
+
+Section 7 -- Other Terms and Conditions.
+
+ a. The Licensor shall not be bound by any additional or different
+ terms or conditions communicated by You unless expressly agreed.
+
+ b. Any arrangements, understandings, or agreements regarding the
+ Licensed Material not stated herein are separate from and
+ independent of the terms and conditions of this Public License.
+
+
+Section 8 -- Interpretation.
+
+ a. For the avoidance of doubt, this Public License does not, and
+ shall not be interpreted to, reduce, limit, restrict, or impose
+ conditions on any use of the Licensed Material that could lawfully
+ be made without permission under this Public License.
+
+ b. To the extent possible, if any provision of this Public License is
+ deemed unenforceable, it shall be automatically reformed to the
+ minimum extent necessary to make it enforceable. If the provision
+ cannot be reformed, it shall be severed from this Public License
+ without affecting the enforceability of the remaining terms and
+ conditions.
+
+ c. No term or condition of this Public License will be waived and no
+ failure to comply consented to unless expressly agreed to by the
+ Licensor.
+
+ d. Nothing in this Public License constitutes or may be interpreted
+ as a limitation upon, or waiver of, any privileges and immunities
+ that apply to the Licensor or You, including from the legal
+ processes of any jurisdiction or authority.
+
+=======================================================================
+
+Creative Commons is not a party to its public
+licenses. Notwithstanding, Creative Commons may elect to apply one of
+its public licenses to material it publishes and in those instances
+will be considered the “Licensor.” The text of the Creative Commons
+public licenses is dedicated to the public domain under the CC0 Public
+Domain Dedication. Except for the limited purpose of indicating that
+material is shared under a Creative Commons public license or as
+otherwise permitted by the Creative Commons policies published at
+creativecommons.org/policies, Creative Commons does not authorize the
+use of the trademark "Creative Commons" or any other trademark or logo
+of Creative Commons without its prior written consent including,
+without limitation, in connection with any unauthorized modifications
+to any of its public licenses or any other arrangements,
+understandings, or agreements concerning use of licensed material. For
+the avoidance of doubt, this paragraph does not form part of the
+public licenses.
+
+Creative Commons may be contacted at creativecommons.org.
+
diff --git a/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE
new file mode 100644
index 0000000..6c5a1fe
--- /dev/null
+++ b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.body.LICENSE
@@ -0,0 +1,392 @@
+Attribution-NoDerivatives 4.0 International
+
+=======================================================================
+
+Creative Commons Corporation ("Creative Commons") is not a law firm and
+does not provide legal services or legal advice. Distribution of
+Creative Commons public licenses does not create a lawyer-client or
+other relationship. Creative Commons makes its licenses and related
+information available on an "as-is" basis. Creative Commons gives no
+warranties regarding its licenses, any material licensed under their
+terms and conditions, or any related information. Creative Commons
+disclaims all liability for damages resulting from their use to the
+fullest extent possible.
+
+Using Creative Commons Public Licenses
+
+Creative Commons public licenses provide a standard set of terms and
+conditions that creators and other rights holders may use to share
+original works of authorship and other material subject to copyright
+and certain other rights specified in the public license below. The
+following considerations are for informational purposes only, are not
+exhaustive, and do not form part of our licenses.
+
+ Considerations for licensors: Our public licenses are
+ intended for use by those authorized to give the public
+ permission to use material in ways otherwise restricted by
+ copyright and certain other rights. Our licenses are
+ irrevocable. Licensors should read and understand the terms
+ and conditions of the license they choose before applying it.
+ Licensors should also secure all rights necessary before
+ applying our licenses so that the public can reuse the
+ material as expected. Licensors should clearly mark any
+ material not subject to the license. This includes other CC-
+ licensed material, or material used under an exception or
+ limitation to copyright. More considerations for licensors:
+ wiki.creativecommons.org/Considerations_for_licensors
+
+ Considerations for the public: By using one of our public
+ licenses, a licensor grants the public permission to use the
+ licensed material under specified terms and conditions. If
+ the licensor's permission is not necessary for any reason--for
+ example, because of any applicable exception or limitation to
+ copyright--then that use is not regulated by the license. Our
+ licenses grant only permissions under copyright and certain
+ other rights that a licensor has authority to grant. Use of
+ the licensed material may still be restricted for other
+ reasons, including because others have copyright or other
+ rights in the material. A licensor may make special requests,
+ such as asking that all changes be marked or described.
+ Although not required by our licenses, you are encouraged to
+ respect those requests where reasonable. More considerations
+ for the public:
+ wiki.creativecommons.org/Considerations_for_licensees
+
+
+=======================================================================
+
+Creative Commons Attribution-NoDerivatives 4.0 International Public
+License
+
+By exercising the Licensed Rights (defined below), You accept and agree
+to be bound by the terms and conditions of this Creative Commons
+Attribution-NoDerivatives 4.0 International Public License ("Public
+License"). To the extent this Public License may be interpreted as a
+contract, You are granted the Licensed Rights in consideration of Your
+acceptance of these terms and conditions, and the Licensor grants You
+such rights in consideration of benefits the Licensor receives from
+making the Licensed Material available under these terms and
+conditions.
+
+
+Section 1 -- Definitions.
+
+ a. Adapted Material means material subject to Copyright and Similar
+ Rights that is derived from or based upon the Licensed Material
+ and in which the Licensed Material is translated, altered,
+ arranged, transformed, or otherwise modified in a manner requiring
+ permission under the Copyright and Similar Rights held by the
+ Licensor. For purposes of this Public License, where the Licensed
+ Material is a musical work, performance, or sound recording,
+ Adapted Material is always produced where the Licensed Material is
+ synched in timed relation with a moving image.
+
+ b. Copyright and Similar Rights means copyright and/or similar rights
+ closely related to copyright including, without limitation,
+ performance, broadcast, sound recording, and Sui Generis Database
+ Rights, without regard to how the rights are labeled or
+ categorized. For purposes of this Public License, the rights
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
+ Rights.
+
+ c. Effective Technological Measures means those measures that, in the
+ absence of proper authority, may not be circumvented under laws
+ fulfilling obligations under Article 11 of the WIPO Copyright
+ Treaty adopted on December 20, 1996, and/or similar international
+ agreements.
+
+ d. Exceptions and Limitations means fair use, fair dealing, and/or
+ any other exception or limitation to Copyright and Similar Rights
+ that applies to Your use of the Licensed Material.
+
+ e. Licensed Material means the artistic or literary work, database,
+ or other material to which the Licensor applied this Public
+ License.
+
+ f. Licensed Rights means the rights granted to You subject to the
+ terms and conditions of this Public License, which are limited to
+ all Copyright and Similar Rights that apply to Your use of the
+ Licensed Material and that the Licensor has authority to license.
+
+ g. Licensor means the individual(s) or entity(ies) granting rights
+ under this Public License.
+
+ h. Share means to provide material to the public by any means or
+ process that requires permission under the Licensed Rights, such
+ as reproduction, public display, public performance, distribution,
+ dissemination, communication, or importation, and to make material
+ available to the public including in ways that members of the
+ public may access the material from a place and at a time
+ individually chosen by them.
+
+ i. Sui Generis Database Rights means rights other than copyright
+ resulting from Directive 96/9/EC of the European Parliament and of
+ the Council of 11 March 1996 on the legal protection of databases,
+ as amended and/or succeeded, as well as other essentially
+ equivalent rights anywhere in the world.
+
+ j. You means the individual or entity exercising the Licensed Rights
+ under this Public License. Your has a corresponding meaning.
+
+
+Section 2 -- Scope.
+
+ a. License grant.
+
+ 1. Subject to the terms and conditions of this Public License,
+ the Licensor hereby grants You a worldwide, royalty-free,
+ non-sublicensable, non-exclusive, irrevocable license to
+ exercise the Licensed Rights in the Licensed Material to:
+
+ a. reproduce and Share the Licensed Material, in whole or
+ in part; and
+
+ b. produce and reproduce, but not Share, Adapted Material.
+
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
+ Exceptions and Limitations apply to Your use, this Public
+ License does not apply, and You do not need to comply with
+ its terms and conditions.
+
+ 3. Term. The term of this Public License is specified in Section
+ 6(a).
+
+ 4. Media and formats; technical modifications allowed. The
+ Licensor authorizes You to exercise the Licensed Rights in
+ all media and formats whether now known or hereafter created,
+ and to make technical modifications necessary to do so. The
+ Licensor waives and/or agrees not to assert any right or
+ authority to forbid You from making technical modifications
+ necessary to exercise the Licensed Rights, including
+ technical modifications necessary to circumvent Effective
+ Technological Measures. For purposes of this Public License,
+ simply making modifications authorized by this Section 2(a)
+ (4) never produces Adapted Material.
+
+ 5. Downstream recipients.
+
+ a. Offer from the Licensor -- Licensed Material. Every
+ recipient of the Licensed Material automatically
+ receives an offer from the Licensor to exercise the
+ Licensed Rights under the terms and conditions of this
+ Public License.
+
+ b. No downstream restrictions. You may not offer or impose
+ any additional or different terms or conditions on, or
+ apply any Effective Technological Measures to, the
+ Licensed Material if doing so restricts exercise of the
+ Licensed Rights by any recipient of the Licensed
+ Material.
+
+ 6. No endorsement. Nothing in this Public License constitutes or
+ may be construed as permission to assert or imply that You
+ are, or that Your use of the Licensed Material is, connected
+ with, or sponsored, endorsed, or granted official status by,
+ the Licensor or others designated to receive attribution as
+ provided in Section 3(a)(1)(A)(i).
+
+ b. Other rights.
+
+ 1. Moral rights, such as the right of integrity, are not
+ licensed under this Public License, nor are publicity,
+ privacy, and/or other similar personality rights; however, to
+ the extent possible, the Licensor waives and/or agrees not to
+ assert any such rights held by the Licensor to the limited
+ extent necessary to allow You to exercise the Licensed
+ Rights, but not otherwise.
+
+ 2. Patent and trademark rights are not licensed under this
+ Public License.
+
+ 3. To the extent possible, the Licensor waives any right to
+ collect royalties from You for the exercise of the Licensed
+ Rights, whether directly or through a collecting society
+ under any voluntary or waivable statutory or compulsory
+ licensing scheme. In all other cases the Licensor expressly
+ reserves any right to collect such royalties.
+
+
+Section 3 -- License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the
+following conditions.
+
+ a. Attribution.
+
+ 1. If You Share the Licensed Material, You must:
+
+ a. retain the following if it is supplied by the Licensor
+ with the Licensed Material:
+
+ i. identification of the creator(s) of the Licensed
+ Material and any others designated to receive
+ attribution, in any reasonable manner requested by
+ the Licensor (including by pseudonym if
+ designated);
+
+ ii. a copyright notice;
+
+ iii. a notice that refers to this Public License;
+
+ iv. a notice that refers to the disclaimer of
+ warranties;
+
+ v. a URI or hyperlink to the Licensed Material to the
+ extent reasonably practicable;
+
+ b. indicate if You modified the Licensed Material and
+ retain an indication of any previous modifications; and
+
+ c. indicate the Licensed Material is licensed under this
+ Public License, and include the text of, or the URI or
+ hyperlink to, this Public License.
+
+ For the avoidance of doubt, You do not have permission under
+ this Public License to Share Adapted Material.
+
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
+ reasonable manner based on the medium, means, and context in
+ which You Share the Licensed Material. For example, it may be
+ reasonable to satisfy the conditions by providing a URI or
+ hyperlink to a resource that includes the required
+ information.
+
+ 3. If requested by the Licensor, You must remove any of the
+ information required by Section 3(a)(1)(A) to the extent
+ reasonably practicable.
+
+
+Section 4 -- Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that
+apply to Your use of the Licensed Material:
+
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
+ to extract, reuse, reproduce, and Share all or a substantial
+ portion of the contents of the database, provided You do not Share
+ Adapted Material;
+
+ b. if You include all or a substantial portion of the database
+ contents in a database in which You have Sui Generis Database
+ Rights, then the database in which You have Sui Generis Database
+ Rights (but not its individual contents) is Adapted Material; and
+
+ c. You must comply with the conditions in Section 3(a) if You Share
+ all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not
+replace Your obligations under this Public License where the Licensed
+Rights include other Copyright and Similar Rights.
+
+
+Section 5 -- Disclaimer of Warranties and Limitation of Liability.
+
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
+
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
+
+ c. The disclaimer of warranties and limitation of liability provided
+ above shall be interpreted in a manner that, to the extent
+ possible, most closely approximates an absolute disclaimer and
+ waiver of all liability.
+
+
+Section 6 -- Term and Termination.
+
+ a. This Public License applies for the term of the Copyright and
+ Similar Rights licensed here. However, if You fail to comply with
+ this Public License, then Your rights under this Public License
+ terminate automatically.
+
+ b. Where Your right to use the Licensed Material has terminated under
+ Section 6(a), it reinstates:
+
+ 1. automatically as of the date the violation is cured, provided
+ it is cured within 30 days of Your discovery of the
+ violation; or
+
+ 2. upon express reinstatement by the Licensor.
+
+ For the avoidance of doubt, this Section 6(b) does not affect any
+ right the Licensor may have to seek remedies for Your violations
+ of this Public License.
+
+ c. For the avoidance of doubt, the Licensor may also offer the
+ Licensed Material under separate terms or conditions or stop
+ distributing the Licensed Material at any time; however, doing so
+ will not terminate this Public License.
+
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
+ License.
+
+
+Section 7 -- Other Terms and Conditions.
+
+ a. The Licensor shall not be bound by any additional or different
+ terms or conditions communicated by You unless expressly agreed.
+
+ b. Any arrangements, understandings, or agreements regarding the
+ Licensed Material not stated herein are separate from and
+ independent of the terms and conditions of this Public License.
+
+
+Section 8 -- Interpretation.
+
+ a. For the avoidance of doubt, this Public License does not, and
+ shall not be interpreted to, reduce, limit, restrict, or impose
+ conditions on any use of the Licensed Material that could lawfully
+ be made without permission under this Public License.
+
+ b. To the extent possible, if any provision of this Public License is
+ deemed unenforceable, it shall be automatically reformed to the
+ minimum extent necessary to make it enforceable. If the provision
+ cannot be reformed, it shall be severed from this Public License
+ without affecting the enforceability of the remaining terms and
+ conditions.
+
+ c. No term or condition of this Public License will be waived and no
+ failure to comply consented to unless expressly agreed to by the
+ Licensor.
+
+ d. Nothing in this Public License constitutes or may be interpreted
+ as a limitation upon, or waiver of, any privileges and immunities
+ that apply to the Licensor or You, including from the legal
+ processes of any jurisdiction or authority.
+
+=======================================================================
+
+Creative Commons is not a party to its public
+licenses. Notwithstanding, Creative Commons may elect to apply one of
+its public licenses to material it publishes and in those instances
+will be considered the “Licensor.” The text of the Creative Commons
+public licenses is dedicated to the public domain under the CC0 Public
+Domain Dedication. Except for the limited purpose of indicating that
+material is shared under a Creative Commons public license or as
+otherwise permitted by the Creative Commons policies published at
+creativecommons.org/policies, Creative Commons does not authorize the
+use of the trademark "Creative Commons" or any other trademark or logo
+of Creative Commons without its prior written consent including,
+without limitation, in connection with any unauthorized modifications
+to any of its public licenses or any other arrangements,
+understandings, or agreements concerning use of licensed material. For
+the avoidance of doubt, this paragraph does not form part of the
+public licenses.
+
+Creative Commons may be contacted at creativecommons.org.
diff --git a/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.url b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.url
new file mode 100644
index 0000000..a4612ec
--- /dev/null
+++ b/static/public/assets/fonts/_canon/CC_BY_ND_4_0_INTERNATIONAL.url
@@ -0,0 +1 @@
+https://creativecommons.org/licenses/by-nd/4.0/legalcode.txt
diff --git a/static/public/assets/fonts/_canon/SIL_OFL_1_1.LICENSE b/static/public/assets/fonts/_canon/SIL_OFL_1_1.LICENSE
new file mode 100644
index 0000000..40bd8a6
--- /dev/null
+++ b/static/public/assets/fonts/_canon/SIL_OFL_1_1.LICENSE
@@ -0,0 +1,97 @@
+Copyright (c) , (),
+with Reserved Font Name .
+Copyright (c) , (),
+with Reserved Font Name .
+Copyright (c) , ().
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+https://openfontlicense.org
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE b/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE
new file mode 100644
index 0000000..6e85af4
--- /dev/null
+++ b/static/public/assets/fonts/_canon/SIL_OFL_1_1.body.LICENSE
@@ -0,0 +1,85 @@
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/static/public/assets/fonts/_canon/SIL_OFL_1_1.url b/static/public/assets/fonts/_canon/SIL_OFL_1_1.url
new file mode 100644
index 0000000..78fe3ba
--- /dev/null
+++ b/static/public/assets/fonts/_canon/SIL_OFL_1_1.url
@@ -0,0 +1 @@
+https://openfontlicense.org/documents/OFL.txt
diff --git a/static/public/assets/fonts/cormorant/header.LICENSE b/static/public/assets/fonts/cormorant/header.LICENSE
new file mode 100644
index 0000000..4ff2f0d
--- /dev/null
+++ b/static/public/assets/fonts/cormorant/header.LICENSE
@@ -0,0 +1,8 @@
+Copyright 2015 The Cormorant Project Authors (github.com/CatharsisFonts/Cormorant) CormorantInfant-Italic[wght].ttf: Copyright 2015 The Cormorant Project Authors (github.com/CatharsisFonts/Cormorant)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+
diff --git a/static/public/assets/fonts/fonts.css b/static/public/assets/fonts/fonts.css
index 65bfaea..442c12d 100644
--- a/static/public/assets/fonts/fonts.css
+++ b/static/public/assets/fonts/fonts.css
@@ -45,14 +45,15 @@
src: url("reforma/Reforma1969-Gris.woff2") format("woff2");
font-family: "prose";
font-weight: bold;
+ size-adjust: 120%;
display: swap;
}
@font-face {
src: url("reforma/Reforma1969-BlancaItalica.woff2") format("woff2");
- src: url("prose-italic");
font-family: "prose";
font-style: italic;
+ size-adjust: 120%;
display: swap;
}
@@ -61,5 +62,6 @@
font-family: "prose";
font-weight: bold;
font-style: italic;
+ size-adjust: 120%;
display: swap;
}
diff --git a/static/public/assets/fonts/maven/header.LICENSE b/static/public/assets/fonts/maven/header.LICENSE
new file mode 100644
index 0000000..9dc80a2
--- /dev/null
+++ b/static/public/assets/fonts/maven/header.LICENSE
@@ -0,0 +1,8 @@
+Copyright 2011 The Maven Pro Project Authors (https://github.com/m4rc1e/mavenproFont), with Reserved Font Name "Maven Pro".
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+
diff --git a/static/public/assets/fonts/mononoki/LICENSE b/static/public/assets/fonts/mononoki/LICENSE
index 760e2b3..38d251b 100644
--- a/static/public/assets/fonts/mononoki/LICENSE
+++ b/static/public/assets/fonts/mononoki/LICENSE
@@ -19,7 +19,7 @@ with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
-fonts, including any derivative works, can be bundled, embedded,
+fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
@@ -92,4 +92,3 @@ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
-
diff --git a/static/public/assets/fonts/mononoki/README.md b/static/public/assets/fonts/mononoki/README.md
deleted file mode 100644
index 6ea402a..0000000
--- a/static/public/assets/fonts/mononoki/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# mononoki
-
-> A font for programming and code review.
-
-For a closer look [http://madmalik.github.io/mononoki/](http://madmalik.github.io/mononoki/).
-
-## Features
-
-* Alternate stylistic set with dotted zero, configurable with `ss01`.
-
-## Installation
-
-[Download mononoki.zip](https://github.com/madmalik/mononoki/releases/download/1.6/mononoki.zip) and unpack it.
-* [macOS](http://support.apple.com/kb/HT2509), alternatively there is also a [homebrew formula](https://github.com/Homebrew/homebrew-cask/blob/main/Casks/font/font-m/font-mononoki.rb).
-* [Windows](https://support.microsoft.com/en-us/office/add-a-font-b7c5f17c-4426-4b53-967f-455339c564c1)
-* Linux/Unix - distro dependent, if you have a font manager installed on your system, open the font file and hit "Install". Alternatively, there are [mononoki-packages](https://repology.org/project/fonts:mononoki/versions) in many of the package repos, if you prefer installing via package manager.
-
-## Credit
-
-Box drawing characters created with [box drawing](https://github.com/adobe-type-tools/box-drawing).
diff --git a/static/public/assets/fonts/mononoki/header.LICENSE b/static/public/assets/fonts/mononoki/header.LICENSE
new file mode 100644
index 0000000..e72c9a7
--- /dev/null
+++ b/static/public/assets/fonts/mononoki/header.LICENSE
@@ -0,0 +1,9 @@
+Copyright (c) 2022, Matthias Tellen matthias.tellen@googlemail.com,
+with Reserved Font Name mononoki.
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+
diff --git a/static/public/assets/fonts/rawengulk/SIL Open Font License.txt b/static/public/assets/fonts/rawengulk/LICENSE
similarity index 100%
rename from static/public/assets/fonts/rawengulk/SIL Open Font License.txt
rename to static/public/assets/fonts/rawengulk/LICENSE
diff --git a/static/public/assets/fonts/rawengulk/header.LICENSE b/static/public/assets/fonts/rawengulk/header.LICENSE
new file mode 100644
index 0000000..a581c0b
--- /dev/null
+++ b/static/public/assets/fonts/rawengulk/header.LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2010, gluk (gluksza@wp.pl),
+with Reserved Font Name Rawengulk.
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
+
+
diff --git a/static/public/assets/fonts/reforma/LICENSE.txt b/static/public/assets/fonts/reforma/LICENSE
old mode 100755
new mode 100644
similarity index 100%
rename from static/public/assets/fonts/reforma/LICENSE.txt
rename to static/public/assets/fonts/reforma/LICENSE
diff --git a/static/public/assets/fonts/reforma/README.txt b/static/public/assets/fonts/reforma/README.txt
deleted file mode 100755
index bf61ff4..0000000
--- a/static/public/assets/fonts/reforma/README.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# Reforma
-
-Reforma is a bespoke typeface designed for the Universidad Nacional de Córdoba. The UNC commissioned PampaType to create this typeface as part of the celebrations for the centenary of the University Reform, occurred in this house in 1918. Following Argentina’s national education policy, libre and free, the typeface Reforma is freely available for anyone, under the Creative Commons license BY-ND 4.0 International. This full license is available at: https://creativecommons.org/licenses/by-nd/4.0/
-
-© Copyright 2018 by the Universidad Nacional de Córdoba [AR]. Designed by Alejandro Lo Celso. Programmed by Guido Ferreyra. PampaType font foundry.
-http://pampatype.com.
-
-# Changelog
-
-Version 1.000 (Roman and Italic) created 24/04/2018
-
- First release
-
-Versión 1.001 (Roman) creada 07/06/2018
-
- Bug fix on dieresis
-
-
diff --git a/static/public/assets/fonts/reforma/header.LICENSE b/static/public/assets/fonts/reforma/header.LICENSE
new file mode 100644
index 0000000..8521b49
--- /dev/null
+++ b/static/public/assets/fonts/reforma/header.LICENSE
@@ -0,0 +1,6 @@
+© Copyright 2018 by the Universidad Nacional de Córdoba [AR]. Designed by Alejandro Lo Celso. Programmed by Guido Ferreyra. PampaType font foundry.
+http://pampatype.com.
+
+This Font Software is licensed under the Creative Commons BY-ND 4.0. This full license is available at: https://creativecommons.org/licenses/by-nd/4.0/
+
+## creative commons
diff --git a/static/public/assets/fonts/split.sh b/static/public/assets/fonts/split.sh
new file mode 100755
index 0000000..75829d3
--- /dev/null
+++ b/static/public/assets/fonts/split.sh
@@ -0,0 +1,127 @@
+#!/usr/bin/env sh
+
+set -eu
+
+log() {
+ printf ' [split] %s\n' "$@" >&2
+}
+
+get_marker() {
+ # extended regex syntax
+ cc_marker='^\#? ?Attribution-NoDerivatives 4.0 International$'
+ ofl_marker='^SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007$'
+
+ m_file="$1"
+
+ if grep -Eq "$ofl_marker" "$m_file"; then
+ printf '%s' "$ofl_marker"
+ elif grep -Eq "$cc_marker" "$m_file"; then
+ printf '%s' "$cc_marker"
+ else
+ log "$m_file matches no marker"
+ printf ''
+ fi
+}
+
+behead() {
+ b_file="$1"
+ b_marker="$2"
+ b_head_out_path="$3"
+ b_body_out_path="$4"
+
+ log "Beheading $b_file on marker $b_marker"
+ b_body=$(sed -En "/$b_marker/, \$p" "$b_file")
+ b_head=$(sed -E "/$b_marker/, \$d" "$b_file")
+
+ if [ -n "$b_head_out_path" ]; then
+ log "Keeping head of $b_file on $b_head_out_path"
+ printf '%s\n' "$b_head" \
+ | sed -E 's/^-+$//' \
+ > "$b_head_out_path"
+ fi
+
+ if [ -n "$b_body_out_path" ]; then
+ log "Keeping body of $b_file on $b_body_out_path"
+ printf '%s\n' "$b_body" > "$b_body_out_path"
+ fi
+
+}
+
+compact() {
+ c_file="$1"
+ c_marker="$2"
+ c_out_path="$3"
+
+ sed -En "/$c_marker/, \$p" "$c_file" \
+ | tr -d '[:space:]' \
+ > "$c_out_path"
+}
+
+log "Iterating over font directories"
+for dir in *; do
+ [ -d "$dir" ] || continue
+ [ "$dir" != _canon ] || continue
+ license="$dir/LICENSE"; [ -f "$license" ]
+
+ log "On license $license"
+
+ marker=$(get_marker "$license")
+ log "Got '$marker' marker for license $license"
+
+ if [ -n "$marker" ]; then
+ behead "$license" "$marker" "$dir/header.LICENSE" ""
+ compact "$license" "$marker" "$dir/compact.LICENSE"
+ fi
+done
+
+log "Iterating over canonical licenses"
+for license in _canon/*.LICENSE; do
+ printf '%s' "$license" \
+ | grep -qEv '(header|compact|body)\.LICENSE' \
+ || continue
+
+ marker=$(get_marker "$license")
+ log "Got '$marker' marker for license $license"
+
+ body_name=$(printf '%s' "$license" | sed "s*\.LICENSE*.body.LICENSE*")
+ compact_name=$(printf '%s' "$license" | sed "s*\.LICENSE*.compact.LICENSE*")
+ log "Using names $body_name (body) and $compact_name (compact)"
+
+ behead "$license" "$marker" "" "$body_name"
+ compact "$license" "$marker" "$compact_name"
+done
+
+for file in ./*/*LICENSE*; do
+ size=$(du "$file" | awk '{print $1}')
+ if [ "$size" -le 0 ]; then
+ log "$file is empty"
+ exit 1
+ fi
+done
+
+sha256sum ./*/*LICENSE* > LICENSES.sha256sum
+grep compact LICENSES.sha256sum | sort
+
+unique_licenses=$(
+ find _canon/ \
+ -name '*.LICENSE' \
+ -not -name '*.compact.LICENSE' \
+ -not -name '*.body.LICENSE' \
+ | wc -l
+)
+unique_hashes=$(
+ cat LICENSES.sha256sum \
+ | grep compact \
+ | awk '{print $1}' \
+ | sort \
+ | uniq \
+ | wc -l
+)
+
+if [ "$unique_hashes" -ne "$unique_licenses" ]; then
+ log "Number of distinct hashes and licenses don't match."
+ log "unique hashes: $unique_hashes"
+ log "unique licenses: $unique_licenses"
+ exit 1
+fi
+
diff --git a/static/public/assets/style.css b/static/public/assets/style.css
index 5859c52..b92a157 100644
--- a/static/public/assets/style.css
+++ b/static/public/assets/style.css
@@ -1,4 +1,5 @@
:root {
+ color-scheme: light dark;
--base-font-size: 1em;
}
@@ -15,6 +16,8 @@ body {
line-height: 1.75;
box-sizing: border-box;
min-width: 0;
+ background: light-dark(#eee, #222);
+ color: light-dark(#000, #f1e9e5);
}
main {
@@ -25,12 +28,13 @@ main {
box-sizing: border-box;
}
-p, section li {
+p:not(.quote-citation), section li {
font-family: prose, sans-serif;
}
section p {
line-height: 2;
+ margin: 4px 0 16px;
}
pre {
@@ -43,71 +47,78 @@ pre {
transition: 1000ms;
}
-pre:hover {
- box-shadow: 1px 1px 3px 2.5px #00777777;
-}
-
code {
padding: 3px 6px;
margin-right: 3px;
white-space: nowrap;
- font-size: calc(var(--base-font-size) * 0.8);
- box-shadow: 1px 1px 1px 1px #00000077;
transition: 1000ms;
-}
-
-code:hover {
- box-shadow: 1px 1px 1px 1px #00777799;
+ box-shadow: 1px 1px 0.5px 0.5px #00000077;
}
pre, code {
+ background: light-dark(#e0e0e0, #333);
font-family: mono, monospace;
- background: #e0e0e0;
- border: solid 2px #d0d0d0;
+ border: solid 1px light-dark(#d0d0d0, #434343);
border-radius: 6px;
}
-a {
- color: #0f6366;
- text-decoration: underline dotted #138e8e;
- text-decoration-thickness: 1.5px;
- text-underline-offset: 3px;
+h1 , h2 , h3 , h4 , h5 , h6 {
+ code { font-size: calc(var(--base-font-size) * 0.6); }
}
-a.attached {
+a {
+ color: light-dark(#0f6366, #1dd7d7);
+ text-decoration: underline dotted #159b9b;
+ text-decoration-thickness: 2.5px;
+ text-underline-offset: 3px;
transition: 1500ms;
}
a.attached:hover,
#nav-main a:hover
{
- color: #117c7c;
- text-decoration-color: #10afaf;
+ color: light-dark(#117c7c, #00ffff);
text-shadow: 0px 0px 22px #10afaf;
+ transition: 1500ms;
}
a.detached {
- color: #595959;
- text-decoration-color: #444444;
+ color: light-dark(#595959, #acacac);
+ text-decoration-color: light-dark(#444444, #777);
}
a.external {
- color: #1958a7;
- text-decoration-color: #2A7CDF;
+ color: light-dark(#1958a7, #2fbae4);
+ text-decoration-color: light-dark(#2A7CDF, #46c1e7);
text-decoration-style: solid;
+ text-decoration-thickness: 1.5px;
transition: 1500ms;
}
a.external:hover {
- color: #0393b2;
- text-decoration-color: #1ed4f1;
+ color: light-dark(#037cb2, #74e5ff);
+ transition: 1500ms;
+}
+
+a.absolute {
+ color: light-dark(#196719, #2fe471);
+ text-decoration-color: light-dark(#196719, #2fe471);
+ text-decoration-style: solid;
+ text-decoration-thickness: 1.5px;
+ transition: 1500ms;
+}
+
+a.absolute:hover {
+ filter: brightness(1.25);
+ transition: 1500ms;
}
a:visited,
a.detached:visited,
a.external:visited
{
- text-decoration-color: #999;
+ text-decoration-color: light-dark(#bbb, #999);
+ transition: 1500ms;
}
footer div a {
@@ -143,18 +154,19 @@ span.root-label {
span.id-label {
font-family: mono, monospace;
- background: #e0e0e0;
- border: solid 1px #d0d0d0;
+ background: light-dark(#e0e0e0, #444);
+ border: solid 1px light-dark(#d0d0d0, #666);
}
-span.hidden-label {
- background: #888;
- color: #eee;
- border: solid 1px #d0d0d0;
+span.unlisted-label {
+ background: light-dark(#888, #000);
+ color: light-dark(#eee, #969696);
+ border: solid 1px light-dark(#d0d0d0, #555);
}
h1 {
font-family: title, serif;
+ line-height: 1;
}
h2, h3, h4, h5, h6 {
@@ -167,7 +179,8 @@ main h2 {
h1, h2, h3, h4, h5, h6 {
font-weight: 1;
- margin: 10px 0;
+ margin: 10px 0 5px;
+ overflow-wrap: break-word;
}
h1.node-title {
@@ -184,11 +197,11 @@ h3.connections-title {
}
h1 { font-size: calc(var(--base-font-size) * 3.6); }
-h2 { font-size: calc(var(--base-font-size) * 3.4); }
-h3 { font-size: calc(var(--base-font-size) * 3.0); }
-h4 { font-size: calc(var(--base-font-size) * 2.6); }
-h5 { font-size: calc(var(--base-font-size) * 2.2); }
-h6 { font-size: calc(var(--base-font-size) * 1.8); }
+h2 { font-size: calc(var(--base-font-size) * 2.8); }
+h3 { font-size: calc(var(--base-font-size) * 2.4); }
+h4 { font-size: calc(var(--base-font-size) * 2.0); }
+h5 { font-size: calc(var(--base-font-size) * 1.6); }
+h6 { font-size: calc(var(--base-font-size) * 1.2); }
footer div {
margin: 20px 0;
@@ -274,8 +287,8 @@ button
border-radius: 5px;
padding: 5px 8px;
margin-right: 3px;
- background: #eeeeff00;
- border-color: #216767;
+ background: light-dark(#eeeeff00, #002020);
+ border-color: light-dark(#216767, #138e8e);
border-width: 0.5px;
transition: 1500ms;
}
@@ -285,7 +298,7 @@ input[type="submit"]:hover,
select:hover,
button:hover
{
- border-color: #36a9a9;
+ border-color: light-dark(#36a9a9, #00ffff);
box-shadow: 2px 2px #36a9a9ee;
}
@@ -298,7 +311,6 @@ div#error-poem {
}
em, i {
- font-style: oblique 20deg;
font-weight: 300;
padding-right: 2px;
}
@@ -308,11 +320,17 @@ em#index-node-count {
}
table {
- margin: auto;
+ margin: 20px auto;
border-collapse: collapse;
border: 0.5px dotted #666;
}
+table th {
+ background: light-dark(#099, #002929);
+ color: #fff;
+ border-color: light-dark(#222, #666);
+}
+
td, th {
padding: 10px;
border: 0.5px dotted #666;
@@ -320,6 +338,7 @@ td, th {
summary {
margin-bottom: 15px;
+ cursor: pointer;
}
hr {
@@ -330,77 +349,33 @@ footer hr {
margin-top: 60px;
}
+blockquote {
+ font-family: serifed;
+ font-size: calc(var(--base-font-size) * 1.6);
+}
+
+p.verse {
+ font-family: serifed;
+ font-size: calc(var(--base-font-size) * 1.6);
+ margin-left: 2em;
+}
+
+.quote-citation {
+ display: block;
+ margin: 0.5em 0 0 0;
+ text-indent: -1.2em;
+ padding-left: 1em;
+ font-size: calc(var(--base-font-size) * 0.8);
+}
+
+.quote-citation::before {
+ content: "— ";
+}
+
@media (prefers-color-scheme: dark) {
- * {
- background: #222222;
- color: #f1e9e5;
- }
-
- pre, code {
- background: #333333;
- border: solid 1px #434343;
- }
-
- a {
- color: #1dd7d7;
- text-decoration-color: #159b9b;
- }
-
- a.attached:hover,
- #nav-main a:hover
- {
- color: #00ffff;
- text-decoration-color: #66ffff;
- }
-
- a.external {
- color: #2fbae4;
- text-decoration-color: #46c1e7;
- }
-
- a.external:hover {
- color: #74e5ff;
- text-decoration-color: #aeffff;
- }
-
- a.detached {
- color: #acacac;
- text-decoration-color: #777;
- }
-
- span.id-label {
- background: #444;
- border-color: #666;
- }
-
- span.hidden-label {
- background: #000;
- border-color: #555;
- color: #969696;
- }
-
-
- input[type="text"],
- input[type="submit"],
- select,
- button
- {
- background: #002020;
- border-color: #138e8e;
- }
-
- input[type="text"]:hover,
- input[type="submit"]:hover,
- select:hover,
- button:hover
- {
- border-color: #00ffff;
- }
-
span.root-label {
border-width: 1px;
}
-
}
@media (max-width: 600px) {
diff --git a/static/welcome.toml b/static/welcome.toml
new file mode 100644
index 0000000..90341de
--- /dev/null
+++ b/static/welcome.toml
@@ -0,0 +1,19 @@
+#:schema ./graph-schema.json
+
+[nodes.GettingStarted]
+title = "Getting Started"
+text = """
+## Welcome to en!
+#
+If you are seeing this, it's working!
+
+Now that you know how to run it, tell en how to find your graph file by adding a `--graph` option:
+
+`
+en --graph my_graph.toml
+`
+
+Alternatively, you can also add a `static` directory next to the en binary with a `graph.toml` file in it.
+
+To learn how to write your first graph and everything else about en, check out the |documentation|https://en.jutty.dev|.
+"""
diff --git a/templates/about.html b/templates/about.html
index 2746039..ce09cf9 100644
--- a/templates/about.html
+++ b/templates/about.html
@@ -8,17 +8,17 @@
{% if graph.meta.config.about_text %}
{{ graph.meta.config.about_text | safe }}
{% else %}
-en is a program to create a connected collection of texts.
+en is a writing instrument to create a connected collection of texts.
-You define your graph using a plain-text configuration file, en reads this file and generates a website like the one you are browsing right now.
+You define your graph using plain-text files, en reads these files and generates a website like the one you are browsing right now.
If you'd like to learn more:
{% endif %}
diff --git a/templates/base.html b/templates/base.html
index 6e5dfc8..61043bd 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -1,3 +1,16 @@
+{% if graph.meta.version %}
+ {% set en_version =
+ graph.meta.version.major
+ ~ "." ~ graph.meta.version.minor
+ ~ "." ~ graph.meta.version.patch
+ %}
+ {% if graph.meta.version.qualifier %}
+ {% set en_version = en_version ~ "-" ~ graph.meta.version.qualifier %}
+ {% endif -%}
+{% else %}
+ {% set en_version = "?.?.?" %}
+{% endif -%}
+
{% if graph.meta.config.content_language %}
@@ -12,6 +25,7 @@
{% endif %}
+
@@ -38,8 +52,8 @@
Nodes
{% for _, node in graph.nodes %}
- {% if node.hidden or node.redirect %}{% continue %}{% endif %}
- {% if not node.hidden and not node.redirect %}
+ {% if not node.listed or node.redirect %}{% continue %}{% endif %}
+ {% if node.listed and not node.redirect %}
{{node.title}}
{% endif %}
{% endfor %}
@@ -62,7 +76,7 @@
{% block body %}
{% endblock body %}
- {% if graph.meta.config.footer %}
+ {% if graph.meta.config.footer or graph.meta.config.serve_fonts %}
{% endif %}
diff --git a/templates/data.html b/templates/data.html
index ef70757..3a18a7f 100644
--- a/templates/data.html
+++ b/templates/data.html
@@ -4,21 +4,21 @@
{%- block body %}
Data
-
-Metadata
+Graph insights
-Detached edges
+Detached connections
+These are the destinations to which connections exist, but the target node doesn't.
Expand to see all detached edges.
@@ -30,9 +30,19 @@
-{% if graph.meta.config.raw and (graph.meta.config.raw_toml or graph.meta.config.raw_json) %}
-Raw formats
-Structured data representing this graph is available in the following formats:
+Metadata
+
+ This graph was rendered using en {{ en_version }}
+ (release notes ).
+
+
+{% if graph.meta.config.raw
+ and (graph.meta.config.raw_toml
+ or graph.meta.config.raw_json)
+%}
+Structured data for this graph is available in the following formats:
{% if graph.meta.config.raw_toml %}
@@ -43,4 +53,5 @@
{% endif %}
{% endif %}
+
{%- endblock body %}
diff --git a/templates/index.html b/templates/index.html
index f2b1e75..69a0737 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -37,7 +37,7 @@
{% if loop.index > graph.meta.config.index_node_count %}
{% break %}
{% endif %}
- {% if node.id != graph.root_node and not node.hidden and not node.redirect %}
+ {% if node.id != graph.root_node and node.listed and not node.redirect %}
{{node.title}}
{% endif %}
{% endfor %}
diff --git a/templates/legal.html b/templates/legal.html
new file mode 100644
index 0000000..be2453a
--- /dev/null
+++ b/templates/legal.html
@@ -0,0 +1,41 @@
+{% extends "base.html" %}
+
+{% block title %}Legal{% endblock title %}
+
+{%- block body %}
+Legal
+
+The following licenses and attributions are made available here in accordance with their terms:
+
+Fonts
+
+{% for font_tuple in fonts %}
+ {% set font = font_tuple.1 %}
+ {{ font.name }}
+
+ From
+
+ {{ font.attribution.project_name -}}
+ ,
+ by
+
+ {{ font.attribution.author -}}
+ .
+
+ License:
+
+ {{ font.license.name -}}
+
+
+
+
+ Expand full license text
+
+
+ {{ font.attribution.license_header | linebreaksbr | safe }}
+ {{ font.license.text | linebreaksbr | safe }}
+
+
+{% endfor %}
+
+{%- endblock body %}
diff --git a/templates/node.html b/templates/node.html
index 0c686e4..f3d9397 100644
--- a/templates/node.html
+++ b/templates/node.html
@@ -8,7 +8,7 @@
{{ node.title }}
{% if node.title != node.id %}ID: {{ node.id }} {% endif %}
- {% if node.hidden %}Hidden {% endif %}
+ {% if not node.listed %}Unlisted {% endif %}
{% if node.id == graph.root_node %}Root {% endif %}
@@ -44,7 +44,7 @@
{% endif %}
{% if incoming %}
-
Incoming
+ Incoming
{% for connection in incoming %}
diff --git a/templates/tree.html b/templates/tree.html
index 243bab5..3d47d40 100644
--- a/templates/tree.html
+++ b/templates/tree.html
@@ -6,7 +6,7 @@
{% if graph.nodes or root_node %}
Tree
- {% if root_node and not root_node.hidden %}
+ {% if root_node and root_node.listed %}
{{root_node.title}}
Root
@@ -34,7 +34,7 @@
{% endif %}
{% if graph.nodes %}
{% for id, node in graph.nodes %}
- {% if node.hidden or (root_node and node.id == root_node.id ) %}{% continue %}{% endif %}
+ {% if not node.listed or (root_node and node.id == root_node.id ) %}{% continue %}{% endif %}
{{node.title}}
{% if node.connections or graph.meta.config.tree_node_summary %}
diff --git a/tests/mocks/bad_graph/static/graph.toml b/tests/mocks/bad_graph/static/graph.toml
deleted file mode 100644
index 2d79863..0000000
--- a/tests/mocks/bad_graph/static/graph.toml
+++ /dev/null
@@ -1,3 +0,0 @@
-[meta]
-config = {
-'
diff --git a/tests/mocks/good_json/graph.json b/tests/mocks/good_json/graph.json
deleted file mode 100644
index 31363fb..0000000
--- a/tests/mocks/good_json/graph.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "nodes": {
- "JSON": {
- "text": "",
- "title": "JSON",
- "links": [],
- "id": "JSON",
- "hidden": false,
- "connections": []
- }
- },
- "root_node": "JSON"
-}
diff --git a/tests/mocks/no_graph/.git_placeholder b/tests/mocks/no_graph/.git_placeholder
deleted file mode 100644
index e69de29..0000000