Skip to content

Commit

Permalink
feat(filters): Add filter to fix title-casing of headings
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jul 8, 2023
1 parent ced8869 commit 2abf654
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fontsdir = $(datadir)/fonts
dist_fonts_DATA = fonts/Almendra-Bold.otf fonts/Almendra-BoldItalic.otf fonts/Almendra-Italic.otf fonts/Almendra-Regular.otf fonts/AlmendraDisplay-Regular.otf fonts/AlmendraSC-Bold.otf fonts/AlmendraSC-BoldItalic.otf fonts/AlmendraSC-Italic.otf fonts/AlmendraSC-Regular.otf fonts/FeFlow2.otf fonts/NexaRustExtras-Free.otf fonts/NexaRustHandmade-Extended-Free.otf fonts/NexaRustSans-Black-Free.otf fonts/NexaRustScriptL-0-Free.otf fonts/NexaRustSlab-BlackShadow01-Free.otf fonts/Nymphette.ttf fonts/PrintersOrnamentsOne.ttf

filtersdir = $(datadir)/pandoc-filters
dist_filters_DATA = pandoc-filters/chapterid.lua pandoc-filters/epubclean.lua pandoc-filters/strip_for_mdbook.lua pandoc-filters/svg2pdf.py pandoc-filters/withoutfootnotes.lua pandoc-filters/withoutheadinglinks.lua pandoc-filters/withoutlinks.lua pandoc-filters/withverses.lua
dist_filters_DATA = pandoc-filters/chapterid.lua pandoc-filters/epubclean.lua pandoc-filters/strip_for_mdbook.lua pandoc-filters/titlecase_titles.lua pandoc-filters/svg2pdf.py pandoc-filters/withoutfootnotes.lua pandoc-filters/withoutheadinglinks.lua pandoc-filters/withoutlinks.lua pandoc-filters/withverses.lua

classesdir = $(datadir)/classes
dist_classes_DATA = classes/cabook.lua classes/cabinding.lua classes/cageometry.lua
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
AX_PROGVAR([bc])
AX_PROGVAR([curl])
AX_PROGVAR([cut])
AX_PROGVAR([decasify])
AX_PROGVAR([deepl])
AX_PROGVAR([diff])
AX_PROGVAR([entr])
Expand Down Expand Up @@ -145,6 +146,7 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
])
AX_PROG_LUA(5.1, [], [], AC_MSG_ERROR([lua interpreter is required]))
AX_LUAROCKS_ROCK(decasify)
AX_LUAROCKS_ROCK(yaml)
AC_PATH_PROG([PERL], [perl])
Expand Down
4 changes: 2 additions & 2 deletions hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set -e

REVISION=$(git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')

RUNTIME_DEPS='bc bcprov curl entr epubcheck fontconfig ghostscript git git-warp-time imagemagick inetutils'\
RUNTIME_DEPS='bc bcprov curl decasify entr epubcheck fontconfig ghostscript git git-warp-time imagemagick inetutils'\
' inkscape java-commons-lang jq kindlegen libertinus-font libgit2 m4 make mdbook moreutils nodejs'\
' pandoc-sile-git pcre pdftk podofo-tools poppler povray sassc sile sqlite'\
' tex-gyre-fonts texlive ttf-hack yq zint zola zsh'\
' lua luarocks lua-colors-git lua-filesystem lua-yaml'\
' lua luarocks lua-decasify lua-colors-git lua-filesystem lua-yaml'\
' perl perl-yaml perl-yaml-merge-simple'\
' python python-isbnlib python-deepl python-pandocfilters python-pantable python-ruamel-yaml python-usfm2osis-cw-git'\
' xcftools xorg-server-xvfb'
Expand Down
16 changes: 16 additions & 0 deletions pandoc-filters/titlecase_titles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Convert all headings to title case following document language rules

local decasify = require("decasify")
local locale = os.getenv("LANGUAGE") or "en"

Pandoc = function (doc)
local language = pandoc.utils.stringify(doc.meta.language or locale)
return doc:walk {
Header = function (element)
local title = pandoc.utils.stringify(element.content)
local cased = decasify.titlecase(title, language)
element.content = cased
return element
end
}
end
3 changes: 2 additions & 1 deletion rules/casile.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ _ENV := _WRAPTARGET=false
# with paths of their own.
AWK ?= @AWK@
BC ?= @BC@
DIFF ?= @DIFF@
CMP ?= @CMP@
CURL ?= @CURL@
CUT ?= @CUT@
DECASIFY ?= @DECASIFY@
DEEPL ?= @DEEPL@
DIFF ?= @DIFF@
EGREP ?= @EGREP@
ENTR ?= @ENTR@
EPUBCHECK ?= @EPUBCHECK@
Expand Down
2 changes: 2 additions & 0 deletions rules/utilities.mk
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ normalize_lua: $(LUASOURCES)
$(call munge,$^,$(SED) -e 's/function */function /g',Normalize Lua coding style)

.PHONY: normalize_markdown
normalize_markdown: private PANDOCFILTERS += --lua-filter=$(CASILEDIR)/pandoc-filters/titlecase_titles.lua
normalize_markdown: $(MARKDOWNSOURCES)
$(call munge,$(filter %.md,$^),msword_escapes.pl,Fixup bad MS word typing habits that Pandoc tries to preserve)
$(call munge,$(filter %.md,$^),lazy_quotes.pl,Replace lazy double single quotes with real doubles)
Expand Down Expand Up @@ -170,6 +171,7 @@ split_chapters:
$(foreach SOURCE,$(MARKDOWNSOURCES),$(call split_chapters,$(SOURCE)))

.PHONY: normalize_files
normalize_files: private PANDOCFILTERS = --lua-filter=$(CASILEDIR)/pandoc-filters/titlecase_titles.lua
normalize_files: private PANDOCFILTERS = --lua-filter=$(CASILEDIR)/pandoc-filters/chapterid.lua
normalize_files:
$(GIT) diff-index --quiet --cached HEAD || exit 1 # die if anything already staged
Expand Down

0 comments on commit 2abf654

Please sign in to comment.