]> git.wincent.com - docvim.git/commitdiff
Add initial stub for Vim help printer
authorGreg Hurrell <greg@hurrell.net>
Wed, 30 Mar 2016 04:12:07 +0000 (21:12 -0700)
committerGreg Hurrell <greg@hurrell.net>
Wed, 30 Mar 2016 04:13:32 +0000 (21:13 -0700)
19 files changed:
docvim.cabal
lib/Docvim/Printer/Vim.hs [new file with mode: 0644]
tests/fixtures/vim/basic-paragraphs.golden [new file with mode: 0644]
tests/fixtures/vim/basic-paragraphs.vim [new symlink]
tests/fixtures/vim/blockquotes.golden [new file with mode: 0644]
tests/fixtures/vim/blockquotes.vim [new symlink]
tests/fixtures/vim/code.golden [new file with mode: 0644]
tests/fixtures/vim/code.vim [new symlink]
tests/fixtures/vim/fenced.golden [new file with mode: 0644]
tests/fixtures/vim/fenced.vim [new symlink]
tests/fixtures/vim/headings.golden [new file with mode: 0644]
tests/fixtures/vim/headings.vim [new symlink]
tests/fixtures/vim/link-targets.golden [new file with mode: 0644]
tests/fixtures/vim/link-targets.vim [new symlink]
tests/fixtures/vim/links.golden [new file with mode: 0644]
tests/fixtures/vim/links.vim [new symlink]
tests/fixtures/vim/list-items.golden [new file with mode: 0644]
tests/fixtures/vim/list-items.vim [new symlink]
tests/tasty.hs

index 81e8cba344f8a51e6e4069024ea62c4e804fb587..c1a7dd9825ed04658f7d597cadd517e3cb170063 100644 (file)
@@ -84,6 +84,7 @@ library
                  ,  Docvim.Options
                  ,  Docvim.Parse
                  ,  Docvim.Printer.Markdown
+                 ,  Docvim.Printer.Vim
                  ,  Docvim.ReadDir
                  ,  Paths_docvim
   hs-source-dirs:   lib
diff --git a/lib/Docvim/Printer/Vim.hs b/lib/Docvim/Printer/Vim.hs
new file mode 100644 (file)
index 0000000..7240ed3
--- /dev/null
@@ -0,0 +1,33 @@
+module Docvim.Printer.Vim
+  ( vimHelp
+  , ppv
+  , pv
+  ) where
+
+import Data.Char (toUpper)
+import Docvim.AST
+import Docvim.Parse (parseUnit)
+
+vimHelp :: Unit -> String
+vimHelp (Unit nodes) = concatMap vh nodes
+
+vh :: Node -> String
+vh (DocBlock d) = concatMap node d
+
+node :: Node -> String
+-- TODO: Vim will only highlight this as a heading if it has a trailing
+-- LinkTarget on the same line; figure out how to handle that; may need to
+-- address it in the Parser
+node (HeadingAnnotation h) = map toUpper h ++ "\n\n"
+node (SubheadingAnnotation s) = s ++ " ~\n\n"
+node _ = "[not yet implemented]"
+
+-- | For unit testing.
+pv :: String -> String
+pv input = case parseUnit input of
+            Left error -> show error
+            Right ast -> vimHelp ast
+
+-- | For logging in the REPL.
+ppv :: String -> IO ()
+ppv = putStr . pv
diff --git a/tests/fixtures/vim/basic-paragraphs.golden b/tests/fixtures/vim/basic-paragraphs.golden
new file mode 100644 (file)
index 0000000..f623e2b
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/basic-paragraphs.vim b/tests/fixtures/vim/basic-paragraphs.vim
new file mode 120000 (symlink)
index 0000000..8cda7c8
--- /dev/null
@@ -0,0 +1 @@
+../markdown/basic-paragraphs.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/blockquotes.golden b/tests/fixtures/vim/blockquotes.golden
new file mode 100644 (file)
index 0000000..f623e2b
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/blockquotes.vim b/tests/fixtures/vim/blockquotes.vim
new file mode 120000 (symlink)
index 0000000..990f4da
--- /dev/null
@@ -0,0 +1 @@
+../markdown/blockquotes.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/code.golden b/tests/fixtures/vim/code.golden
new file mode 100644 (file)
index 0000000..9679731
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented]
diff --git a/tests/fixtures/vim/code.vim b/tests/fixtures/vim/code.vim
new file mode 120000 (symlink)
index 0000000..5eee0f7
--- /dev/null
@@ -0,0 +1 @@
+../markdown/code.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/fenced.golden b/tests/fixtures/vim/fenced.golden
new file mode 100644 (file)
index 0000000..3640c71
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented][not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/fenced.vim b/tests/fixtures/vim/fenced.vim
new file mode 120000 (symlink)
index 0000000..4e41030
--- /dev/null
@@ -0,0 +1 @@
+../markdown/fenced.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/headings.golden b/tests/fixtures/vim/headings.golden
new file mode 100644 (file)
index 0000000..82b14da
--- /dev/null
@@ -0,0 +1,4 @@
+A HEADING
+
+A subheading ~
+
diff --git a/tests/fixtures/vim/headings.vim b/tests/fixtures/vim/headings.vim
new file mode 120000 (symlink)
index 0000000..23a84cf
--- /dev/null
@@ -0,0 +1 @@
+../markdown/headings.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/link-targets.golden b/tests/fixtures/vim/link-targets.golden
new file mode 100644 (file)
index 0000000..066dcf8
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/link-targets.vim b/tests/fixtures/vim/link-targets.vim
new file mode 120000 (symlink)
index 0000000..7d2dbd9
--- /dev/null
@@ -0,0 +1 @@
+../markdown/link-targets.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/links.golden b/tests/fixtures/vim/links.golden
new file mode 100644 (file)
index 0000000..f623e2b
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/links.vim b/tests/fixtures/vim/links.vim
new file mode 120000 (symlink)
index 0000000..ddb7fcd
--- /dev/null
@@ -0,0 +1 @@
+../markdown/links.vim
\ No newline at end of file
diff --git a/tests/fixtures/vim/list-items.golden b/tests/fixtures/vim/list-items.golden
new file mode 100644 (file)
index 0000000..f623e2b
--- /dev/null
@@ -0,0 +1 @@
+[not yet implemented][not yet implemented][not yet implemented]
diff --git a/tests/fixtures/vim/list-items.vim b/tests/fixtures/vim/list-items.vim
new file mode 120000 (symlink)
index 0000000..b00f87e
--- /dev/null
@@ -0,0 +1 @@
+../markdown/list-items.vim
\ No newline at end of file
index d44670f41f9b2b877ab4ac75e11749dd1f8c23b9..895574e85dcc5db82ee769826901acdb8fb3e169 100644 (file)
@@ -9,6 +9,7 @@ import Data.Char (chr)
 import Data.List (isPrefixOf)
 import Docvim.Parse (p, parseUnit)
 import Docvim.Printer.Markdown (pm)
+import Docvim.Printer.Vim (pv)
 import System.Exit (ExitCode(ExitSuccess))
 import System.FilePath ((<.>), replaceExtension, takeBaseName, takeFileName)
 import System.IO (hFlush, readFile)
@@ -112,8 +113,10 @@ main :: IO ()
 main = do
   parserSources <- getFixtures "tests/fixtures/parser"
   markdownSources <- getFixtures "tests/fixtures/markdown"
+  vimHelpSources <- getFixtures "tests/fixtures/vim"
   defaultMain $ testGroup "Test suite"
     [ unitTests
     , goldenTests "parser" parserSources p
     , goldenTests "Markdown printer" markdownSources pm
+    , goldenTests "Vim help printer" vimHelpSources pv
     ]