Skip to content

Commit

Permalink
feat(mdbook): Markup numbered vs. unnumbered chapters in TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Feb 25, 2023
1 parent e5d59ef commit 56f4b6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pandoc-filters/strip_for_mdbook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ end

-- c.f. pandoc-filters/withoutheadinglinks.lua
Header = function (element)
element = remove_attr(element)
if element.level ~= 1 then
element = remove_attr(element)
end
return pandoc.walk_block(element, {
-- c.f. pandoc-filters/epubclean.lua
Note = function (_)
Expand Down
12 changes: 8 additions & 4 deletions scripts/split_mdbook_src.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ trunc $dir/$of
while read line; do
unset title slug
# Check for chapter header
if [[ $line =~ "^# .*" ]]; then
[[ $line =~ ".*unnumbered.*" ]] || let i=$i+1
if [[ $line =~ "^# " ]]; then
[[ $line =~ "\.unnumbered\b" ]] || let i=$i+1
@PANDOC@ --to=plain-smart <<< "$line" |
read title
test -n "$title"
Expand All @@ -36,12 +36,16 @@ while read line; do
test -n "$slug"
of="$(printf %02d $i)-$slug.md"
trunc $dir/$of
[[ $line =~ "\.unnumbered\b" ]] || echo -n "- "
echo "[$title](./$of)"
# Strip attrs we *used* via commonmark_x for our own use from markup going to mdbook
@PANDOC@ --to=commonmark-smart <<< "$line" |
read line
fi
>> $dir/$of <<< $line
done

# Some "books" have no chapters. If we didn't find any, at least list the blob
if [[ ! -v title ]]; then
echo -e "[](./$of)"
if [[ $of = "00.md" ]]; then
echo "[](./$of)"
fi

0 comments on commit 56f4b6d

Please sign in to comment.