forked from scielo-edo/jats2tex
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Main where | ||
|
||
import Data.Maybe | ||
import Data.Monoid | ||
import qualified Data.Text.IO as Text (hPutStr) | ||
import System.Environment (getArgs) | ||
import qualified Data.Text.IO as Text (hPutStr) | ||
import System.Environment (getArgs) | ||
import System.IO | ||
|
||
import Options.Applicative | ||
import Text.JaTex | ||
|
||
data Options = Options { optsOutputFile :: Maybe FilePath | ||
, optsTemplateFile :: Maybe String | ||
, optsInputFile :: FilePath | ||
} | ||
|
||
options :: Parser Options | ||
options = | ||
Options <$> | ||
optional | ||
(strOption | ||
(long "output" <> metavar "OUTPUT_FILE" <> help "LaTeX Output File")) <*> | ||
optional | ||
(strOption | ||
(long "template" <> metavar "TEMPLATE_FILE" <> help "Template File")) <*> | ||
argument str (metavar "INPUT_FILE" <> help "XML Input File") | ||
|
||
optionsPI :: ParserInfo Options | ||
optionsPI = | ||
info | ||
(options <**> helper) | ||
(fullDesc <> progDesc "Convert JATS-XML INPUT_FILE to LaTeX OUTPUT_FILE" | ||
<> header "jats2tex - Customizable JATS to LaTeX Conversion") | ||
|
||
main :: IO () | ||
main = getArgs >>= \case | ||
[inputFile, outputFile] -> run inputFile =<< openFile outputFile WriteMode | ||
[inputFile] -> run inputFile stdout | ||
_ -> error "Usage: jatex <input-file> <output-file>" | ||
main = do | ||
Options{..} <- execParser optionsPI | ||
outputFile <- case optsOutputFile of | ||
Nothing -> return stdout | ||
Just f -> openFile f WriteMode | ||
run optsInputFile outputFile | ||
|
||
run :: FilePath -> Handle -> IO () | ||
run inputFile outputHandle = do | ||
hPutStrLn stderr ("Using " <> inputFile <> " writting " <> show outputHandle) | ||
-- hPutStrLn stderr ("Using " <> inputFile <> " writting " <> show outputHandle) | ||
contents <- readJats inputFile | ||
Text.hPutStr outputHandle (jatsXmlToLaTeXText contents) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<front> | ||
<article-meta> | ||
<title-group> | ||
<article-title xml:lang="pt"><![CDATA[A influência do genótipo da ECA sobre a aptidão cardiovascular de jovens do sexo masculino moderadamente ativos]]></article-title> | ||
<article-title xml:lang="en"><![CDATA[The influence of ACE genotype on cardiovascular fitness of moderately active young men]]></article-title> | ||
</title-group> | ||
</article-meta> | ||
</front> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters