pandoc_rb 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # This file was automatically generated by 'stack init'
2
+ #
3
+ # Some commonly used options have been documented as comments in this file.
4
+ # For advanced use and comprehensive documentation of the format, please see:
5
+ # http://docs.haskellstack.org/en/stable/yaml_configuration/
6
+
7
+ # Resolver to choose a 'specific' stackage snapshot or a compiler version.
8
+ # A snapshot resolver dictates the compiler version and the set of packages
9
+ # to be used for project dependencies. For example:
10
+ #
11
+ # resolver: lts-3.5
12
+ # resolver: nightly-2015-09-21
13
+ # resolver: ghc-7.10.2
14
+ # resolver: ghcjs-0.1.0_ghc-7.10.2
15
+ # resolver:
16
+ # name: custom-snapshot
17
+ # location: "./custom-snapshot.yaml"
18
+ resolver: lts-8.19
19
+
20
+ # User packages to be built.
21
+ # Various formats can be used as shown in the example below.
22
+ #
23
+ # packages:
24
+ # - some-directory
25
+ # - https://example.com/foo/bar/baz-0.0.2.tar.gz
26
+ # - location:
27
+ # git: https://github.com/commercialhaskell/stack.git
28
+ # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29
+ # - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30
+ # extra-dep: true
31
+ # subdirs:
32
+ # - auto-update
33
+ # - wai
34
+ #
35
+ # A package marked 'extra-dep: true' will only be built if demanded by a
36
+ # non-dependency (i.e. a user package), and its test suites and benchmarks
37
+ # will not be run. This is useful for tweaking upstream packages.
38
+ packages:
39
+ - '.'
40
+ - location:
41
+ git: https://github.com/Authorea/pandoc.git
42
+ commit: 1303092cdfcc3b6f13ab8d2996b6d3c3465279f2
43
+ extra-dep: true
44
+ # Dependency packages to be pulled from upstream that are not in the resolver
45
+ # (e.g., acme-missiles-0.3)
46
+ extra-deps: []
47
+
48
+ # Override default flag values for local packages and extra-deps
49
+ flags: {}
50
+
51
+ # Extra package databases containing global packages
52
+ extra-package-dbs: []
53
+
54
+ # Control whether we use the GHC we find on the path
55
+ # system-ghc: true
56
+ #
57
+ # Require a specific version of stack, using version ranges
58
+ # require-stack-version: -any # Default
59
+ # require-stack-version: ">=1.3"
60
+ #
61
+ # Override the architecture used by stack, especially useful on Windows
62
+ # arch: i386
63
+ # arch: x86_64
64
+ #
65
+ # Extra directories used by stack for building
66
+ # extra-include-dirs: [/path/to/dir]
67
+ # extra-lib-dirs: [/path/to/dir]
68
+ #
69
+ # Allow a newer minor version of GHC than the snapshot specifies
70
+ # compiler-check: newer-minor
@@ -0,0 +1,173 @@
1
+ {-# LANGUAGE PackageImports, NamedFieldPuns #-}
2
+ {-# LANGUAGE FlexibleInstances #-}
3
+
4
+ module DetailedSpec (tests) where
5
+
6
+ import qualified Test.QuickCheck as Q
7
+ import Distribution.TestSuite as TS
8
+
9
+ import Control.Monad
10
+ import Control.Monad.Fix
11
+ import Control.Monad.Trans.Class
12
+ import Control.Monad.Trans.Either
13
+ import Data.Bifunctor
14
+ import Data.Either
15
+ import Distribution.TestSuite
16
+ import Foreign.C.String
17
+ import Foreign.Marshal.Alloc
18
+ import Foreign.Ptr
19
+ import Foreign.Storable
20
+ import Test.QuickCheck
21
+ import Text.Pandoc
22
+ import Text.Pandoc.C
23
+ import Text.Pandoc.C.Types
24
+ import Text.Pandoc.C.Utils
25
+
26
+
27
+ instance Show (Bool -> Maybe Int) where
28
+ show f = concat ["f False = ", show (f False), "; f True = ", show (f True)]
29
+
30
+ instance (Arbitrary a, Arbitrary b) => Arbitrary (EitherT a Maybe b) where
31
+ arbitrary = oneof [ return . EitherT $ Nothing
32
+ , (EitherT . Just . Left ) <$> arbitrary
33
+ , (EitherT . Just . Right) <$> arbitrary
34
+ ]
35
+
36
+
37
+
38
+ testGotCReader :: String -> Property
39
+ testGotCReader readerStr = ioProperty $ withCStringLen readerStr (fmap isRight . runEitherT . getCReader)
40
+
41
+ testGotCWriter :: String -> Property
42
+ testGotCWriter writerStr = ioProperty $ withCStringLen writerStr (fmap isRight . runEitherT . getCWriter)
43
+
44
+ allProps :: (Functor t, Foldable t, Testable prop) => (a -> prop) -> t a -> Property
45
+ allProps f = foldr (.&&.) (property True) . fmap f
46
+
47
+ allPropsIO :: (Applicative t, Traversable t, Testable prop) => (a -> IO prop) -> t a -> Property
48
+ allPropsIO f = ioProperty . fmap (foldr (.&&.) (property True)) . mapM f
49
+
50
+
51
+ foreign import ccall "dynamic" freerFunc :: FunPtr (Ptr a -> IO ()) -> Ptr a -> IO ()
52
+
53
+
54
+ prop_mapMLIgnoresRight0 :: Bool
55
+ prop_mapMLIgnoresRight0 = mapML (const $ Just ()) (EitherT (Just (Right True))) == EitherT (Just (Right True))
56
+
57
+ prop_mapMLIgnoresRight1 :: Bool
58
+ prop_mapMLIgnoresRight1 = mapML (const $ Nothing) (EitherT (Just (Right True))) == (EitherT (Just (Right True)) :: EitherT () Maybe Bool)
59
+
60
+ prop_mapMLAppliesFunction0 :: Bool
61
+ prop_mapMLAppliesFunction0 = mapML (const $ Just ()) (EitherT (Just (Left 0))) == (EitherT (Just (Left ())) :: EitherT () Maybe Bool)
62
+
63
+ prop_mapMLAppliesFunction1 :: Bool
64
+ prop_mapMLAppliesFunction1 = mapML (const $ Nothing) (EitherT (Just (Left (0 :: Int)))) == (EitherT Nothing :: EitherT () Maybe Bool)
65
+
66
+ prop_mapMRIgnoresRight0 :: Bool
67
+ prop_mapMRIgnoresRight0 = mapMR (const $ Just ()) (EitherT (Just (Left True))) == EitherT (Just (Left True))
68
+
69
+ prop_mapMRIgnoresRight1 :: Bool
70
+ prop_mapMRIgnoresRight1 = mapMR (const $ Nothing) (EitherT (Just (Left True))) == (EitherT (Just (Left True)) :: EitherT Bool Maybe ())
71
+
72
+ prop_mapMRAppliesFunction0 :: Bool
73
+ prop_mapMRAppliesFunction0 = mapMR (const $ Just ()) (EitherT (Just (Right (0 :: Int)))) == (EitherT (Just (Right ())) :: EitherT Bool Maybe ())
74
+
75
+ prop_mapMRAppliesFunction1 :: Bool
76
+ prop_mapMRAppliesFunction1 = mapMR (const $ Nothing) (EitherT (Just (Right (0 :: Int)))) == (EitherT Nothing :: EitherT Bool Maybe ())
77
+
78
+ -- prop_mapMLisSwappedMapMR :: (Bool -> Maybe Int) -> EitherT Bool Maybe () -> Bool
79
+ -- prop_mapMLisSwappedMapMR f x = mapML f x == swapEitherT (mapMR f (swapEitherT x))
80
+
81
+ prop_getCReaderGetsReaders :: Property
82
+ prop_getCReaderGetsReaders = allProps testGotCReader (fst <$> readers)
83
+
84
+ prop_getCWriterGetsWriters :: Property
85
+ prop_getCWriterGetsWriters = allProps testGotCWriter (fst <$> writers)
86
+
87
+ -- prop_convert_hsWorks :: Property
88
+ -- prop_convert_hsWorks = ioProperty $ do
89
+ -- readerCStr <- newCStringLen "markdown"
90
+ -- writerCStr <- newCStringLen "latex"
91
+ -- inputCStr <- newCStringLen "hi there!"
92
+ -- readerRStr <- malloc
93
+ -- writerRStr <- malloc
94
+ -- inputRStr <- malloc
95
+ -- readerRStr `poke` second toEnum readerCStr
96
+ -- writerRStr `poke` second toEnum writerCStr
97
+ -- inputRStr `poke` second toEnum inputCStr
98
+ -- resultPtr <- convert_hs readerRStr writerRStr inputRStr
99
+ -- peek readerRStr >>= free . fst
100
+ -- peek writerRStr >>= free . fst
101
+ -- peek inputRStr >>= free . fst
102
+ -- free readerRStr
103
+ -- free writerRStr
104
+ -- free inputRStr
105
+ -- (success, freer, output) <- peek resultPtr
106
+ -- if success == 0
107
+ -- then return False
108
+ -- else do
109
+ -- (freerFunc freer) (castPtr resultPtr)
110
+ -- return True
111
+
112
+
113
+ testTimeoutEitherT :: Testable prop => Int -> (CStringLen -> IO prop) -> (a -> IO prop) -> EitherT CStringLen IO a -> Property
114
+ testTimeoutEitherT us ifLeft ifRight = ioProperty . eitherT ifLeft ifRight . timeoutEitherT us
115
+
116
+
117
+ prop_timeoutEitherT_times_out_on_0 :: Property
118
+ prop_timeoutEitherT_times_out_on_0 = testTimeoutEitherT 0 (\(ptr, _) -> free ptr >> return True) (\_->return False) $ return ()
119
+
120
+ prop_timeoutEitherT_times_out_on_loose_loop :: Property
121
+ prop_timeoutEitherT_times_out_on_loose_loop = testTimeoutEitherT 1 (\(ptr, _) -> free ptr >> return True) return $ lift $ mapM_ putStr (repeat "") >> return False
122
+
123
+ prop_timeoutEitherT_times_out_on_tight_loop :: Property
124
+ prop_timeoutEitherT_times_out_on_tight_loop = testTimeoutEitherT 1 (\(ptr, _) -> free ptr >> return True) (return . (== 0)) . lift . mfix $ (return $!)
125
+
126
+ prop_timeoutEitherT_does_not_time_out_on_result :: Property
127
+ prop_timeoutEitherT_does_not_time_out_on_result = testTimeoutEitherT 100 (\(ptr, _) -> free ptr >> return False) return $ return True
128
+
129
+ prop_timeoutEitherT_catches_exceptions :: Property
130
+ prop_timeoutEitherT_catches_exceptions = testTimeoutEitherT 100 (\(ptr, _) -> free ptr >> return True) (\_->return False) . lift . print $ (div 1 0 :: Int)
131
+
132
+ -- prop_timeoutEitherT_catches_errors :: Property
133
+ -- prop_timeoutEitherT_catches_errors = testTimeoutEitherT 100 (\(ptr, _) -> free ptr >> return True) (\_->return False) $ EitherT undefined
134
+
135
+ prop_timeoutEitherT_catches_lefts :: Property
136
+ prop_timeoutEitherT_catches_lefts = testTimeoutEitherT 100 (\(ptr, _) -> free ptr >> return True) (\_->return False) (EitherT $ Left <$> (newCStringLen ""))
137
+
138
+
139
+ toTSResult :: Q.Result -> TS.Result
140
+ toTSResult Q.Success {} = TS.Pass
141
+ toTSResult Q.GaveUp {} = TS.Fail "GaveUp"
142
+ toTSResult Q.Failure {Q.reason} = TS.Fail reason
143
+
144
+ runQuickCheck :: Q.Testable p => p -> IO TS.Progress
145
+ runQuickCheck prop = do
146
+ qres <- Q.quickCheckWithResult Q.stdArgs {Q.maxSuccess = 30,
147
+ Q.maxSize = 20} prop
148
+ return $ (Finished . toTSResult) qres
149
+
150
+ tests :: IO [Test]
151
+ tests = return [
152
+ Test $ TestInstance (runQuickCheck prop_mapMLIgnoresRight0) "prop_mapMLIgnoresRight0" ["tag"] [] undefined,
153
+ Test $ TestInstance (runQuickCheck prop_mapMLIgnoresRight1) "prop_mapMLIgnoresRight1" ["tag"] [] undefined,
154
+ Test $ TestInstance (runQuickCheck prop_mapMLAppliesFunction0) "prop_mapMLAppliesFunction0" ["tag"] [] undefined,
155
+ Test $ TestInstance (runQuickCheck prop_mapMLAppliesFunction1) "prop_mapMLAppliesFunction1" ["tag"] [] undefined,
156
+ Test $ TestInstance (runQuickCheck prop_mapMRIgnoresRight0) "prop_mapMRIgnoresRight0" ["tag"] [] undefined,
157
+ Test $ TestInstance (runQuickCheck prop_mapMRIgnoresRight1) "prop_mapMRIgnoresRight1" ["tag"] [] undefined,
158
+ Test $ TestInstance (runQuickCheck prop_mapMRAppliesFunction0) "prop_mapMRAppliesFunction0" ["tag"] [] undefined,
159
+ Test $ TestInstance (runQuickCheck prop_mapMRAppliesFunction1) "prop_mapMRAppliesFunction1" ["tag"] [] undefined,
160
+ Test $ TestInstance (runQuickCheck prop_getCReaderGetsReaders) "prop_getCReaderGetsReaders" ["tag"] [] undefined,
161
+ Test $ TestInstance (runQuickCheck prop_getCWriterGetsWriters) "prop_getCWriterGetsWriters" ["tag"] [] undefined,
162
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_times_out_on_0) "prop_timeoutEitherT_times_out_on_0" ["tag"] [] undefined,
163
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_does_not_time_out_on_result) "prop_timeoutEitherT_does_not_time_out_on_result" ["tag"] [] undefined,
164
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_catches_exceptions) "prop_timeoutEitherT_catches_exceptions" ["tag"] [] undefined,
165
+ -- Test $ TestInstance (runQuickCheck prop_timeoutEitherT_catches_errors) "prop_timeoutEitherT_catches_errors" ["tag"] [] undefined,
166
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_catches_lefts) "prop_timeoutEitherT_catches_lefts" ["tag"] [] undefined,
167
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_times_out_on_loose_loop) "prop_timeoutEitherT_times_out_on_loose_loop" ["tag"] [] undefined,
168
+ Test $ TestInstance (runQuickCheck prop_timeoutEitherT_times_out_on_tight_loop) "prop_timeoutEitherT_times_out_on_tight_loop" ["tag"] [] undefined
169
+ ]
170
+
171
+
172
+
173
+
@@ -0,0 +1,96 @@
1
+ require 'pandoc_rb/pandoc_rb'
2
+ require 'json'
3
+ require 'pandoc_rb/error'
4
+ require 'pandoc_rb/parse_failure'
5
+ require 'pandoc_rb/parsec_error'
6
+ require 'pandoc_rb/readers'
7
+ require 'pandoc_rb/version'
8
+ require 'pandoc_rb/writers'
9
+ require 'timeout'
10
+
11
+
12
+ module PandocRb
13
+ def self.raise_exception(result)
14
+ if /^Unknown reader: / === result
15
+ raise ArgumentError, result
16
+ elsif /^Unknown writer: / === result
17
+ raise ArgumentError, result
18
+ elsif /^Pandoc timed out/ === result
19
+ raise Timeout::Error
20
+ elsif /^Pandoc internal / === result
21
+ raise PandocRb::Error, result.sub(/^Pandoc internal error: /, '')
22
+ end
23
+ result = JSON.parse result
24
+ if result['tag'] == 'ParseFailure'
25
+ raise PandocRb::ParseFailure.new(result['contents'])
26
+ elsif result['tag'] == 'ParsecError'
27
+ raise PandocRb::ParsecError.new( result['contents'])
28
+ else
29
+ raise "Unknown error type returned from pandoc: #{result}"
30
+ end
31
+ end
32
+
33
+ def self.convert(in_format_str, out_format_str, input_str, extract_media_path='')
34
+ unless @PandocRb_loaded
35
+ self.convert_init
36
+ Kernel.at_exit do
37
+ PandocRb.convert_exit
38
+ end
39
+ @PandocRb_loaded = true
40
+ end
41
+
42
+ if in_format_str.to_s == 'docx'
43
+ input_str.force_encoding "UTF-8"
44
+ end
45
+
46
+ begin
47
+ in_format = in_format_str.to_s.encode "UTF-8"
48
+ out_format = out_format_str.to_s.encode "UTF-8"
49
+ input = input_str.to_s.encode "UTF-8"
50
+ extract_media_path = extract_media_path.to_s.encode "UTF-8"
51
+ success, result = PandocRb.convert_raw in_format, out_format, input, extract_media_path
52
+ self.raise_exception result if (success == false)
53
+ result
54
+ end
55
+ end
56
+
57
+ def self.reader_from_ext(extension)
58
+ {
59
+ "" => "markdown",
60
+ ".tex" => "latex",
61
+ ".latex" => "latex",
62
+ ".ltx" => "latex",
63
+ ".context" => "context",
64
+ ".ctx" => "context",
65
+ ".rtf" => "rtf",
66
+ ".rst" => "rst",
67
+ ".s5" => "s5",
68
+ ".native" => "native",
69
+ ".json" => "json",
70
+ ".txt" => "markdown",
71
+ ".text" => "markdown",
72
+ ".md" => "markdown",
73
+ ".markdown" => "markdown",
74
+ ".textile" => "textile",
75
+ ".lhs" => "markdown+lhs",
76
+ ".texi" => "texinfo",
77
+ ".texinfo" => "texinfo",
78
+ ".db" => "docbook",
79
+ ".odt" => "odt",
80
+ ".docx" => "docx",
81
+ ".epub" => "epub",
82
+ ".org" => "org",
83
+ ".asciidoc" => "asciidoc",
84
+ ".adoc" => "asciidoc",
85
+ ".pdf" => "latex",
86
+ ".fb2" => "fb2",
87
+ ".opml" => "opml",
88
+ ".icml" => "icml",
89
+ ".tei.xml" => "tei",
90
+ ".tei" => "tei",
91
+ }[extension&.downcase] || !!extension&.downcase&.match(/\.\d$/)
92
+ end
93
+
94
+
95
+ end
96
+
@@ -0,0 +1,6 @@
1
+
2
+ module PandocRb
3
+ class Error < Exception
4
+ end
5
+ end
6
+
@@ -0,0 +1,11 @@
1
+
2
+ module PandocRb
3
+ class ParseFailure < PandocRb::Error
4
+ attr_accessor :json
5
+
6
+ def initialize(json)
7
+ self.json = json
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,13 @@
1
+
2
+ module PandocRb
3
+ class ParsecError < PandocRb::Error
4
+ attr_accessor :input, :source_name, :line, :column, :messages
5
+
6
+ def initialize(json)
7
+ self.input, parse_error = json
8
+ source_pos, self.messages = parse_error
9
+ self.source_name, self.line, self.column = source_pos
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,27 @@
1
+
2
+ module PandocRb
3
+ Readers = [ "commonmark",
4
+ "docbook",
5
+ "docx",
6
+ "epub",
7
+ "haddock",
8
+ "html",
9
+ "json",
10
+ "latex",
11
+ "markdown",
12
+ "markdown_github",
13
+ "markdown_mmd",
14
+ "markdown_phpextra",
15
+ "markdown_strict",
16
+ "mediawiki",
17
+ "native",
18
+ "odt",
19
+ "opml",
20
+ "org",
21
+ "rst",
22
+ "t2t",
23
+ "textile",
24
+ "twiki"
25
+ ]
26
+ end
27
+
@@ -0,0 +1,5 @@
1
+
2
+ module PandocRb
3
+ VERSION = "0.2.2"
4
+ end
5
+
@@ -0,0 +1,46 @@
1
+
2
+ module PandocRb
3
+ Writers = [ "asciidoc",
4
+ "beamer",
5
+ "commonmark",
6
+ "context",
7
+ "docbook",
8
+ "docbook5",
9
+ "docx",
10
+ "dokuwiki",
11
+ "dzslides",
12
+ "epub",
13
+ "epub3",
14
+ "fb2",
15
+ "haddock",
16
+ "html",
17
+ "html5",
18
+ "icml",
19
+ "json",
20
+ "latex",
21
+ "man",
22
+ "markdown",
23
+ "markdown_github",
24
+ "markdown_mmd",
25
+ "markdown_phpextra",
26
+ "markdown_strict",
27
+ "mediawiki",
28
+ "native",
29
+ "odt",
30
+ "opendocument",
31
+ "opml",
32
+ "org",
33
+ "plain",
34
+ "revealjs",
35
+ "rst",
36
+ "rtf",
37
+ "s5",
38
+ "slideous",
39
+ "slidy",
40
+ "tei",
41
+ "texinfo",
42
+ "textile",
43
+ "zimwiki"
44
+ ]
45
+ end
46
+