add initial version of pandoc filter
This commit is contained in:
parent
22b4411641
commit
d88c4c14b3
5 changed files with 64 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
_build
|
||||
_tmp
|
||||
dist-newstyle
|
||||
|
|
14
Makefile
14
Makefile
|
@ -12,20 +12,30 @@ OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE))
|
|||
|
||||
OUTPUT = $(OUTPUTPAGES) $(OUTPUTSTYLE)
|
||||
|
||||
LANGFILTER = $(TMPDIR)/langfilter
|
||||
EXECS = $(LANGFILTER)
|
||||
|
||||
.PHONY: all
|
||||
all: build
|
||||
|
||||
.PHONY: build
|
||||
build: $(OUTPUT)
|
||||
|
||||
$(BUILDDIR)/%.html: $(PAGESDIR)/%.md $(TEMPLATE)
|
||||
$(BUILDDIR)/%.html: $(PAGESDIR)/%.md $(TEMPLATE) $(LANGFILTER)
|
||||
mkdir -p $(dir $@)
|
||||
pandoc -s --toc --template $(TEMPLATE) -o $@ $<
|
||||
pandoc -s --toc --template $(TEMPLATE) --filter $(LANGFILTER) -o $@ $<
|
||||
|
||||
$(BUILDDIR)/%: %
|
||||
mkdir -p $(dir $@)
|
||||
cp $< $@
|
||||
|
||||
$(LANGFILTER): langfilter/*.hs langfilter/langfilter.cabal
|
||||
mkdir -p $(dir $@)
|
||||
cabal build -v0 all
|
||||
find dist-newstyle -name $(notdir $@) \
|
||||
-print -type f -exec cp {} $(TMPDIR) \;
|
||||
|
||||
|
||||
.PHONY: clean distclean
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
|
1
cabal.project
Normal file
1
cabal.project
Normal file
|
@ -0,0 +1 @@
|
|||
packages: ./langfilter
|
23
langfilter/langfilter.cabal
Normal file
23
langfilter/langfilter.cabal
Normal file
|
@ -0,0 +1,23 @@
|
|||
cabal-version: 2.2
|
||||
name: langfilter
|
||||
version: 0.1.0
|
||||
synopsis: filter for conlang stuff
|
||||
license: AGPL-3.0-or-later
|
||||
|
||||
author: Rhiannon Morris <rhi@rhiannon.website>
|
||||
maintainer: Rhiannon Morris <rhi@rhiannon.website>
|
||||
|
||||
executable langfilter
|
||||
hs-source-dirs: .
|
||||
main-is: langfilter.hs
|
||||
ghc-options:
|
||||
-Wall -threaded -rtsopts -with-rtsopts=-N
|
||||
default-language: Haskell2010
|
||||
default-extensions:
|
||||
BlockArguments,
|
||||
LambdaCase,
|
||||
PatternSynonyms,
|
||||
ViewPatterns
|
||||
build-depends:
|
||||
base ^>= 4.14.0.0,
|
||||
pandoc-types == 1.17.*
|
27
langfilter/langfilter.hs
Normal file
27
langfilter/langfilter.hs
Normal file
|
@ -0,0 +1,27 @@
|
|||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.JSON
|
||||
import Text.Pandoc.Builder
|
||||
|
||||
main :: IO ()
|
||||
main = toJSONFilter \case
|
||||
Code _ txt
|
||||
| Just _ <- enclosed '/' '/' txt ->
|
||||
Span (cls ["ipa", "ipa-broad"]) $ text' txt
|
||||
| Just _ <- enclosed '[' ']' txt ->
|
||||
Span (cls ["ipa", "ipa-narrow"]) $ text' txt
|
||||
| Just txt' <- enclosed '{' '}' txt ->
|
||||
Span (cls ["lang"]) $ text' txt'
|
||||
i -> i
|
||||
|
||||
cls :: [String] -> Attr
|
||||
cls cs = ("", cs, [])
|
||||
|
||||
text' :: String -> [Inline]
|
||||
text' = toList . text
|
||||
|
||||
|
||||
enclosed :: Char -> Char -> String -> Maybe String
|
||||
enclosed o c txt
|
||||
| length txt >= 2, head txt == o, last txt == c
|
||||
= Just $ init $ tail txt
|
||||
enclosed _ _ _ = Nothing
|
Loading…
Reference in a new issue