Skip to content

Commit

Permalink
Di 8. Mai 17:27:24 CEST 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
danse committed May 8, 2018
1 parent f0a4bb8 commit d7bf46f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
37 changes: 33 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
{-# LANGUAGE PatternGuards, OverloadedStrings #-}
module Main where

import Text.Pandoc
import Lib (transform)
import Text.Pandoc.JSON
import Text.Pandoc.Error (handleError)
import Text.Pandoc.Walk (walk, query)
import Text.Pandoc.Options (ReaderOptions(..))
import System.Environment (getArgs)
import Data.Text (Text(..), unlines, pack)
import qualified Data.Text.IO as T
import qualified Data.Map as M
import Data.Monoid ((<>))
import Control.Applicative ((<$>))
import Data.Maybe (maybeToList)
import Data.Either (fromRight)
import Options.Applicative
import Control.Monad (when, unless)

main :: IO ()
main = do


interact' :: (Pandoc -> IO a) -> IO a
interact' f = T.getContents >>= handleError . readJSON def >>= f

data Options = Options {
levelOption :: Maybe Int
}

toSphinx :: Options -> IO ()
toSphinx (Options levelOption) = interact' transform

options :: Parser Options
options = Options
<$> option auto (long "level"
<> short 'l'
<> help "the section level to use for splitting the document"
<> showDefault)

main = execParser (info options fullDesc) >>= toSphinx
4 changes: 2 additions & 2 deletions design.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`pandoc-to-sphinx`
# pandoc-to-sphinx

from any pandoc-compatible document to a set of files ready to be
published on read the docs
Expand All @@ -18,7 +18,7 @@ After installation, typing `pandoc-to-sphinx --help` will give you the
following:

```
pandoc-to-sphinx <document.ext> <output-dir>
pandoc-to-sphinx <output-dir>
-l --level: (optional) the section level to use for splitting the document
Expand Down
18 changes: 5 additions & 13 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,20 @@



licenza per una pubblicazione più graduale

o ci sono le funzioni di alto livello esportate in Text.Pandoc.App
collegando Text.Pandoc.Readers.getReader con il parsing di opzioni
o si specifica il writer manualmente

https://github.com/Hogeyama/pandoc-wrapper/blob/master/Main.hs
we want to put the result in a directory argument

in Main i can put together a minimal wrapper
https://hackage.haskell.org/package/optparse-applicative-0.14.2.0/docs/Options-Applicative-Builder.html#v:str
not sure about how to specify an optional option

accepting json input

if there is anything from `convert.hs`, i can add it eventually
what happens when pandoc reads an RST which refers to media?

i can add new options after we fix the problem with table wraps in docs2rst

un wrapper sarebbe semplicemente un client per la libreria
non mi sembra che ci sia supporto specifico per i wrapper

otherwise accepting json input
maybe we can do it with a pandoc wrapper like the existing ones
it requires a way to pass command line options through
accepting any pandoc-document as an input is more convenient for the users



7 changes: 1 addition & 6 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ import Control.Applicative ((<$>))
import Control.Monad (when)
import System.FilePath.Posix (dropExtension, addExtension)

main = do
c <- T.getContents
c' <- (onBody f . fromRight (Pandoc nullMeta []) . readJSON def) c
(T.putStr . writeJSON def) c'

transform :: Pandoc -> IO Pandoc
transform :: Pandoc -> IO ()
transform = onBody f

onBody :: ([Block] -> IO [Block]) -> Pandoc -> IO Pandoc
Expand Down

0 comments on commit d7bf46f

Please sign in to comment.