Skip to content

Commit ca2fa39

Browse files
committed
Initial commit
0 parents  commit ca2fa39

27 files changed

+2991
-0
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
lint:
7+
name: Codestyle
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Stylua
12+
uses: JohnnyMorganz/stylua-action@v4
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
version: latest
16+
args: --check .
17+
docs:
18+
name: Docs
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Install pandoc
23+
uses: pandoc/actions/setup@v1
24+
with:
25+
version: 3.5
26+
- name: Regenerate docs
27+
shell: bash
28+
run: |
29+
./.panvimdoc/panvimdoc.sh
30+
- name: Check that docs are up-to-date
31+
run: git diff --exit-code -- doc/jupytext.txt
32+
test:
33+
name: Tests
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: rhysd/action-setup-vim@v1
38+
id: vim
39+
with:
40+
neovim: true
41+
version: v0.10.2
42+
- name: Install Jupytext
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install jupytext
46+
- name: Run test
47+
shell: bash
48+
run: |
49+
./run_tests.sh

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Compiled Lua sources
2+
luac.out
3+
4+
# luarocks build files
5+
*.src.rock
6+
*.zip
7+
*.tar.gz
8+
9+
# Object files
10+
*.o
11+
*.os
12+
*.ko
13+
*.obj
14+
*.elf
15+
16+
# Precompiled Headers
17+
*.gch
18+
*.pch
19+
20+
# Libraries
21+
*.lib
22+
*.a
23+
*.la
24+
*.lo
25+
*.def
26+
*.exp
27+
28+
# Shared objects (inc. Windows DLLs)
29+
*.dll
30+
*.so
31+
*.so.*
32+
*.dylib
33+
34+
# Executables
35+
*.exe
36+
*.out
37+
*.app
38+
*.i*86
39+
*.x86_64
40+
*.hex
41+
42+
build/
43+
doc/tags
44+
/.testenv/
45+
46+
# tests
47+
/tests/notebooks/.ipynb_checkpoints
48+
/tests/notebooks/.virtual_documents

.panvimdoc/panvimdoc.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Paths are from the perspective of the Makefile
6+
PROJECT_NAME="jupytext"
7+
INPUT_FILE="README.md"
8+
DESCRIPTION="Edit .ipynb files"
9+
SCRIPTS_DIR=".panvimdoc/scripts"
10+
DOC_MAPPING=true
11+
12+
13+
# Define arguments in an array
14+
ARGS=(
15+
"--shift-heading-level-by=${SHIFT_HEADING_LEVEL_BY:-0}"
16+
"--metadata=project:$PROJECT_NAME"
17+
"--metadata=vimversion:${VIM_VERSION:-""}"
18+
"--metadata=toc:${TOC:-true}"
19+
"--metadata=description:${DESCRIPTION:-""}"
20+
"--metadata=titledatepattern:${TITLE_DATE_PATTERN:-"%Y %B %d"}"
21+
"--metadata=dedupsubheadings:${DEDUP_SUBHEADINGS:-true}"
22+
"--metadata=ignorerawblocks:${IGNORE_RAWBLOCKS:-true}"
23+
"--metadata=docmapping:${DOC_MAPPING:-false}"
24+
"--metadata=docmappingproject:${DOC_MAPPING_PROJECT_NAME:-true}"
25+
"--metadata=treesitter:${TREESITTER:-true}"
26+
"--metadata=incrementheadinglevelby:${INCREMENT_HEADING_LEVEL_BY:-0}"
27+
"--lua-filter=$SCRIPTS_DIR/include-files.lua"
28+
"--lua-filter=$SCRIPTS_DIR/skip-blocks.lua"
29+
)
30+
31+
ARGS+=("-t" "$SCRIPTS_DIR/panvimdoc.lua")
32+
33+
# Print and execute the command
34+
printf "%s\n" "pandoc --citeproc ${ARGS[*]} $INPUT_FILE -o doc/$PROJECT_NAME.txt"
35+
pandoc "${ARGS[@]}" "$INPUT_FILE" -o "doc/$PROJECT_NAME.txt"

.panvimdoc/scripts/include-files.lua

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
--- include-files.lua – filter to include Markdown files
2+
---
3+
--- Copyright: © 2019–2021 Albert Krewinkel
4+
--- License: MIT – see LICENSE file for details
5+
-- Module pandoc.path is required and was added in version 2.12
6+
PANDOC_VERSION:must_be_at_least("3.0")
7+
8+
local List = require("pandoc.List")
9+
local path = require("pandoc.path")
10+
local system = require("pandoc.system")
11+
12+
function P(s)
13+
require("scripts.logging").temp(s)
14+
end
15+
16+
--- Get include auto mode
17+
local include_auto = false
18+
function get_vars(meta)
19+
if meta["include-auto"] then
20+
include_auto = true
21+
end
22+
end
23+
24+
--- Keep last heading level found
25+
local last_heading_level = 0
26+
function update_last_level(header)
27+
last_heading_level = header.level
28+
end
29+
30+
--- Update contents of included file
31+
local function update_contents(blocks, shift_by, include_path)
32+
local update_contents_filter = {
33+
-- Shift headings in block list by given number
34+
Header = function(header)
35+
if shift_by then
36+
header.level = header.level + shift_by
37+
end
38+
return header
39+
end,
40+
-- If image paths are relative then prepend include file path
41+
Image = function(image)
42+
if path.is_relative(image.src) then
43+
image.src = path.normalize(path.join({ include_path, image.src }))
44+
end
45+
return image
46+
end,
47+
-- Update path for include-code-files.lua filter style CodeBlocks
48+
CodeBlock = function(cb)
49+
if cb.attributes.include and path.is_relative(cb.attributes.include) then
50+
cb.attributes.include = path.normalize(path.join({ include_path, cb.attributes.include }))
51+
end
52+
return cb
53+
end,
54+
}
55+
return pandoc.walk_block(pandoc.Div(blocks), update_contents_filter).content
56+
end
57+
58+
--- Filter function for code blocks
59+
local transclude
60+
function transclude(cb)
61+
-- ignore code blocks which are not of class "include".
62+
if not cb.classes:includes("include") then
63+
return
64+
end
65+
66+
-- Markdown is used if this is nil.
67+
local format = cb.attributes["format"]
68+
69+
-- Attributes shift headings
70+
local shift_heading_level_by = 0
71+
local shift_input = cb.attributes["shift-heading-level-by"]
72+
if shift_input then
73+
shift_heading_level_by = tonumber(shift_input)
74+
else
75+
if include_auto then
76+
-- Auto shift headings
77+
shift_heading_level_by = last_heading_level
78+
end
79+
end
80+
81+
--- keep track of level before recusion
82+
local buffer_last_heading_level = last_heading_level
83+
84+
local blocks = List:new()
85+
for line in cb.text:gmatch("[^\n]+") do
86+
if line:sub(1, 2) ~= "//" then
87+
-- local fh = io.open(pandoc.system.get_working_directory() .. line)
88+
local mt, includecontents = pandoc.mediabag.fetch(line)
89+
if not includecontents then
90+
io.stderr:write("Cannot open file " .. line .. " | Skipping includes\n")
91+
else
92+
local contents = pandoc.read(includecontents, format).blocks
93+
last_heading_level = 0
94+
-- recursive transclusion
95+
contents = system.with_working_directory(path.directory(line), function()
96+
return pandoc.walk_block(pandoc.Div(contents), { Header = update_last_level, CodeBlock = transclude })
97+
end).content
98+
--- reset to level before recursion
99+
last_heading_level = buffer_last_heading_level
100+
blocks:extend(update_contents(contents, shift_heading_level_by, path.directory(line)))
101+
-- fh:close()
102+
end
103+
end
104+
end
105+
return blocks
106+
end
107+
108+
return { { Meta = get_vars }, { Header = update_last_level, CodeBlock = transclude } }

0 commit comments

Comments
 (0)