Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Dec 17, 2024
0 parents commit 6c61beb
Show file tree
Hide file tree
Showing 26 changed files with 2,891 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on: [push]

jobs:
lint:
name: Codestyle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Stylua
uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --check .
docs:
name: Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pandoc
uses: pandoc/actions/setup@v1
with:
version: 3.5
- name: Regenerate docs
shell: bash
run: |
./.panvimdoc/panvimdoc.sh
- name: Check that docs are up-to-date
run: git diff --exit-code -- doc/jupytext.txt
test:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: rhysd/action-setup-vim@v1
id: vim
with:
neovim: true
version: v0.10.2
- name: Install Jupytext
run: |
python -m pip install --upgrade pip
pip install jupytext
- name: Run test
shell: bash
run: |
./run_tests.sh
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

build/
doc/tags
/.testenv/
35 changes: 35 additions & 0 deletions .panvimdoc/panvimdoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

# Paths are from the perspective of the Makefile
PROJECT_NAME="jupytext"
INPUT_FILE="README.md"
DESCRIPTION="Edit .ipynb files"
SCRIPTS_DIR=".panvimdoc/scripts"
DOC_MAPPING=true


# Define arguments in an array
ARGS=(
"--shift-heading-level-by=${SHIFT_HEADING_LEVEL_BY:-0}"
"--metadata=project:$PROJECT_NAME"
"--metadata=vimversion:${VIM_VERSION:-""}"
"--metadata=toc:${TOC:-true}"
"--metadata=description:${DESCRIPTION:-""}"
"--metadata=titledatepattern:${TITLE_DATE_PATTERN:-"%Y %B %d"}"
"--metadata=dedupsubheadings:${DEDUP_SUBHEADINGS:-true}"
"--metadata=ignorerawblocks:${IGNORE_RAWBLOCKS:-true}"
"--metadata=docmapping:${DOC_MAPPING:-false}"
"--metadata=docmappingproject:${DOC_MAPPING_PROJECT_NAME:-true}"
"--metadata=treesitter:${TREESITTER:-true}"
"--metadata=incrementheadinglevelby:${INCREMENT_HEADING_LEVEL_BY:-0}"
"--lua-filter=$SCRIPTS_DIR/include-files.lua"
"--lua-filter=$SCRIPTS_DIR/skip-blocks.lua"
)

ARGS+=("-t" "$SCRIPTS_DIR/panvimdoc.lua")

# Print and execute the command
printf "%s\n" "pandoc --citeproc ${ARGS[*]} $INPUT_FILE -o doc/$PROJECT_NAME.txt"
pandoc "${ARGS[@]}" "$INPUT_FILE" -o "doc/$PROJECT_NAME.txt"
108 changes: 108 additions & 0 deletions .panvimdoc/scripts/include-files.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
--- include-files.lua – filter to include Markdown files
---
--- Copyright: © 2019–2021 Albert Krewinkel
--- License: MIT – see LICENSE file for details
-- Module pandoc.path is required and was added in version 2.12
PANDOC_VERSION:must_be_at_least("3.0")

local List = require("pandoc.List")
local path = require("pandoc.path")
local system = require("pandoc.system")

function P(s)
require("scripts.logging").temp(s)
end

--- Get include auto mode
local include_auto = false
function get_vars(meta)
if meta["include-auto"] then
include_auto = true
end
end

--- Keep last heading level found
local last_heading_level = 0
function update_last_level(header)
last_heading_level = header.level
end

--- Update contents of included file
local function update_contents(blocks, shift_by, include_path)
local update_contents_filter = {
-- Shift headings in block list by given number
Header = function(header)
if shift_by then
header.level = header.level + shift_by
end
return header
end,
-- If image paths are relative then prepend include file path
Image = function(image)
if path.is_relative(image.src) then
image.src = path.normalize(path.join({ include_path, image.src }))
end
return image
end,
-- Update path for include-code-files.lua filter style CodeBlocks
CodeBlock = function(cb)
if cb.attributes.include and path.is_relative(cb.attributes.include) then
cb.attributes.include = path.normalize(path.join({ include_path, cb.attributes.include }))
end
return cb
end,
}
return pandoc.walk_block(pandoc.Div(blocks), update_contents_filter).content
end

--- Filter function for code blocks
local transclude
function transclude(cb)
-- ignore code blocks which are not of class "include".
if not cb.classes:includes("include") then
return
end

-- Markdown is used if this is nil.
local format = cb.attributes["format"]

-- Attributes shift headings
local shift_heading_level_by = 0
local shift_input = cb.attributes["shift-heading-level-by"]
if shift_input then
shift_heading_level_by = tonumber(shift_input)
else
if include_auto then
-- Auto shift headings
shift_heading_level_by = last_heading_level
end
end

--- keep track of level before recusion
local buffer_last_heading_level = last_heading_level

local blocks = List:new()
for line in cb.text:gmatch("[^\n]+") do
if line:sub(1, 2) ~= "//" then
-- local fh = io.open(pandoc.system.get_working_directory() .. line)
local mt, includecontents = pandoc.mediabag.fetch(line)
if not includecontents then
io.stderr:write("Cannot open file " .. line .. " | Skipping includes\n")
else
local contents = pandoc.read(includecontents, format).blocks
last_heading_level = 0
-- recursive transclusion
contents = system.with_working_directory(path.directory(line), function()
return pandoc.walk_block(pandoc.Div(contents), { Header = update_last_level, CodeBlock = transclude })
end).content
--- reset to level before recursion
last_heading_level = buffer_last_heading_level
blocks:extend(update_contents(contents, shift_heading_level_by, path.directory(line)))
-- fh:close()
end
end
end
return blocks
end

return { { Meta = get_vars }, { Header = update_last_level, CodeBlock = transclude } }
Loading

0 comments on commit 6c61beb

Please sign in to comment.