From ec9753e7b57775bfd03270cbe754784d79429b68 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Fri, 9 Nov 2018 09:08:30 +0100 Subject: [PATCH] Use Pandoc and introduce HTML template for synopsis - Remove isLatex flag - Plan to convert to Markdown and simply format --- doc/.gitignore | 5 ++ doc/Makefile | 16 ++++++- doc/MkSynopsis.hs | 49 ++++++++----------- doc/_template.html | 116 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 29 deletions(-) create mode 100644 doc/.gitignore create mode 100644 doc/_template.html diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 00000000..d8273c26 --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1,5 @@ +api-examples-*.txt +api-examples.gfs +categories-imagemap.html +synopsis.txt +synopsis.html diff --git a/doc/Makefile b/doc/Makefile index 90133f78..d8145fdd 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -24,9 +24,23 @@ SRC_FILES=$(S)/abstract/Common.gf $(S)/abstract/Cat.gf $(S)/api/Constructors.gf EXAMPLES_OUT=$(patsubst %,api-examples-%.txt,$(LANGS)) INCLUDES=synopsis-intro.txt categories-intro.txt categories-imagemap.html synopsis-additional.txt synopsis-browse.txt synopsis-example.txt -synopsis.html: MkSynopsis.hs MkExxTable.hs $(INCLUDES) $(EXAMPLES_OUT) $(SRC_FILES) +synopsis.txt: MkSynopsis.hs MkExxTable.hs $(INCLUDES) $(EXAMPLES_OUT) $(SRC_FILES) runghc -i.. MkSynopsis.hs +TMP=tmp.html +synopsis.html: synopsis.txt + txt2tags --target=html --no-headers --quiet --toc --outfile=$@ --infile=$^ + pandoc \ + --from=html \ + --to=html5 \ + --standalone \ + --template=_template.html \ + --metadata='title:"GF Resource Grammar Library: Synopsis"' \ + --variable='rel-root:../..' \ + --output=$(TMP) \ + $@ + mv $(TMP) $@ + categories.png: categories.dot dot -Tpng $^ > $@ diff --git a/doc/MkSynopsis.hs b/doc/MkSynopsis.hs index 777c3aad..a843f5a2 100644 --- a/doc/MkSynopsis.hs +++ b/doc/MkSynopsis.hs @@ -29,17 +29,13 @@ apiExxFiles = do , langSynopsis lang ] +-- | This function puts together a txt2tags file which is then converted to HTML by the Makefile main :: IO () main = do - xx <- getArgs - let isLatex = case xx of - "-tex":_ -> True - _ -> False cs1 <- getCats commonAPI cs2 <- getCats catAPI let cs = sortCats (cs1 ++ cs2) writeFile synopsis "GF Resource Grammar Library: Synopsis" - -- append "B. Bringert, T. Hallgren, and A. Ranta" space append "%!Encoding:utf-8" append "%!style(html): ./revealpopup.css" @@ -56,7 +52,7 @@ main = do append "%!postproc(html): '#quicklinks' ''" append "%!postproc(tex): '#quicklinks' ''" delimit $ addToolTips cs - include "synopsis-intro.txt" + include "synopsis-intro.txt" -- TODO dynamic language list title "Categories" space link "Source 1:" commonAPI @@ -66,7 +62,7 @@ main = do append "==A hierarchic view==\n" include "categories-intro.txt" append "==Explanations==\n" - delimit $ mkCatTable isLatex cs + delimit $ mkCatTable cs space title "Syntax Rules and Structural Words" space @@ -81,17 +77,17 @@ main = do rs2 <- getRules apiExx structuralAPI let rss = rs ++ rs2 --- mapM_ putStrLn [f ++ " " ++ e | (f,_,e) <- rss] - delimit $ mkSplitTables True isLatex apiExx cs rss + delimit $ mkSplitTables True apiExx cs rss space -- title "Structural Words" -- space -- link "Source:" structuralAPI -- space --- rs <- rulesTable False isLatex cs structuralAPI +-- rs <- rulesTable False cs structuralAPI -- delimit rs space title "Lexical Paradigms" - paradigmFiles >>= mapM_ (putParadigms isLatex cs) + paradigmFiles >>= mapM_ (putParadigms cs) space include "synopsis-additional.txt" space @@ -107,9 +103,6 @@ main = do space append "#quicklinks" space - let format = if isLatex then "tex" else "html" - system $ "txt2tags -t" ++ format ++ " " ++ " --toc " ++ synopsis - if isLatex then (system $ "pdflatex synopsis.tex") >> return () else return () addToolTips :: Cats -> [String] addToolTips = map f @@ -130,10 +123,10 @@ getCats file = do (expl,ex) = span (/="e.g.") exp _ -> getrs rs ss2 -rulesTable :: ApiExx -> Bool -> Bool -> Cats -> FilePath -> IO [String] -rulesTable aexx hasEx isLatex cs file = do +rulesTable :: ApiExx -> Bool -> Cats -> FilePath -> IO [String] +rulesTable aexx hasEx cs file = do rs <- getRules aexx file - return $ mkTable hasEx isLatex aexx cs rs + return $ mkTable hasEx aexx cs rs getRules :: ApiExx -> FilePath -> IO Rules @@ -161,14 +154,14 @@ getRules aexx file = do n:ws | last n == '.' && not (null (init n)) && all isDigit (init n) -> ws _ -> e -putParadigms :: Bool -> Cats -> (String, FilePath) -> IO () -putParadigms isLatex cs (lang,file) = do +putParadigms :: Cats -> (String, FilePath) -> IO () +putParadigms cs (lang,file) = do stitle ("Paradigms for " ++ lang) append "#LParadigms" space link "source" file space - rs <- rulesTable M.empty False isLatex cs file + rs <- rulesTable M.empty False cs file space delimit rs space @@ -180,23 +173,23 @@ inChunks i f = concat . intersperse ["\n\n"] . map f . chunks i where -- Makes one table per result category. -- Adds a subsection header for each table. -mkSplitTables :: Bool -> Bool -> ApiExx -> Cats -> Rules -> [String] -mkSplitTables hasEx isLatex aexx cs = concatMap t . addLexicalCats cs . sortRules +mkSplitTables :: Bool -> ApiExx -> Cats -> Rules -> [String] +mkSplitTables hasEx aexx cs = concatMap t . addLexicalCats cs . sortRules where t (c, xs) = [subtitle c expl] ++ tableOrLink where expl = case [e | (n,e,_) <- cs, n == c] of [] -> "" e:_ -> e - tableOrLink = if null xs then parad else mkTable hasEx isLatex aexx cs xs + tableOrLink = if null xs then parad else mkTable hasEx aexx cs xs parad = [ "Lexical category, constructors given in", "[lexical paradigms #RParadigms]." ] -mkTable :: Bool -> Bool -> ApiExx -> Cats -> Rules -> [String] -mkTable hasEx isLatex aexx cs = inChunks chsize (\rs -> header : map (unwords . row) rs) +mkTable :: Bool -> ApiExx -> Cats -> Rules -> [String] +mkTable hasEx aexx cs = inChunks chsize (\rs -> header : map (unwords . row) rs) where - chsize = if isLatex then 40 else 1000 + chsize = 1000 header = if hasEx then "|| Function | Type | Example ||" else "|| Function | Type | Explanation ||" row (name,typ,ex) = @@ -235,11 +228,11 @@ mkIdent = concatMap unspec where ':' -> "-" _ -> [c] -mkCatTable :: Bool -> Cats -> [String] -mkCatTable isLatex cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs +mkCatTable :: Cats -> [String] +mkCatTable cs = inChunks chsize (\rs -> header ++ map mk1 rs) cs where header = ["|| Category | Explanation | Example ||"] - chsize = if isLatex then 40 else 1000 + chsize = 1000 mk1 (name,expl,ex) = unwords ["|", showCat cs name, "|", expl, "|", typo ex, "|"] typo ex = if take 1 ex == "\"" then itf (init (tail ex)) else ex diff --git a/doc/_template.html b/doc/_template.html new file mode 100644 index 00000000..f94ac841 --- /dev/null +++ b/doc/_template.html @@ -0,0 +1,116 @@ + + + + + + +$for(author-meta)$ + +$endfor$ +$if(date-meta)$ + +$endif$ +$if(keywords)$ + +$endif$ + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ +$for(css)$ + +$endfor$ + +$if(math)$ + $math$ +$endif$ + +$for(header-includes)$ + $header-includes$ +$endfor$ + + +
+ +$if(title)$ +
+ + GF Logo + +

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$if(date)$ +

$date$

+$endif$ +
+$endif$ +$if(toc)$ + +$endif$ +$body$ +
+ + + + + + +