"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Text/Pandoc/Writers/Org.hs" between
pandoc-2.11.1.1.tar.gz and pandoc-2.11.2.tar.gz

About: Pandoc converts files from one markup format into another.

Org.hs  (pandoc-2.11.1.1):Org.hs  (pandoc-2.11.2)
skipping to change at line 109 skipping to change at line 109
=> Block -- ^ Block element => Block -- ^ Block element
-> Org m (Doc Text) -> Org m (Doc Text)
blockToOrg Null = return empty blockToOrg Null = return empty
blockToOrg (Div attr bs) = divToOrg attr bs blockToOrg (Div attr bs) = divToOrg attr bs
blockToOrg (Plain inlines) = inlineListToOrg inlines blockToOrg (Plain inlines) = inlineListToOrg inlines
-- title beginning with fig: indicates that the image is a figure -- title beginning with fig: indicates that the image is a figure
blockToOrg (Para [Image attr txt (src,tgt)]) blockToOrg (Para [Image attr txt (src,tgt)])
| Just tit <- T.stripPrefix "fig:" tgt = do | Just tit <- T.stripPrefix "fig:" tgt = do
capt <- if null txt capt <- if null txt
then return empty then return empty
else ("#+CAPTION: " <>) `fmap` inlineListToOrg txt else ("#+caption: " <>) `fmap` inlineListToOrg txt
img <- inlineToOrg (Image attr txt (src,tit)) img <- inlineToOrg (Image attr txt (src,tit))
return $ capt $$ img $$ blankline return $ capt $$ img $$ blankline
blockToOrg (Para inlines) = do blockToOrg (Para inlines) = do
contents <- inlineListToOrg inlines contents <- inlineListToOrg inlines
return $ contents <> blankline return $ contents <> blankline
blockToOrg (LineBlock lns) = do blockToOrg (LineBlock lns) = do
let splitStanza [] = [] let splitStanza [] = []
splitStanza xs = case break (== mempty) xs of splitStanza xs = case break (== mempty) xs of
(l, []) -> [l] (l, []) -> [l]
(l, _:r) -> l : splitStanza r (l, _:r) -> l : splitStanza r
let joinWithLinefeeds = nowrap . mconcat . intersperse cr let joinWithLinefeeds = nowrap . mconcat . intersperse cr
let joinWithBlankLines = mconcat . intersperse blankline let joinWithBlankLines = mconcat . intersperse blankline
let prettifyStanza ls = joinWithLinefeeds <$> mapM inlineListToOrg ls let prettifyStanza ls = joinWithLinefeeds <$> mapM inlineListToOrg ls
contents <- joinWithBlankLines <$> mapM prettifyStanza (splitStanza lns) contents <- joinWithBlankLines <$> mapM prettifyStanza (splitStanza lns)
return $ blankline $$ "#+BEGIN_VERSE" $$ return $ blankline $$ "#+begin_verse" $$
nest 2 contents $$ "#+END_VERSE" <> blankline nest 2 contents $$ "#+end_verse" <> blankline
blockToOrg (RawBlock "html" str) = blockToOrg (RawBlock "html" str) =
return $ blankline $$ "#+BEGIN_HTML" $$ return $ blankline $$ "#+begin_html" $$
nest 2 (literal str) $$ "#+END_HTML" $$ blankline nest 2 (literal str) $$ "#+end_html" $$ blankline
blockToOrg b@(RawBlock f str) blockToOrg b@(RawBlock f str)
| isRawFormat f = return $ literal str | isRawFormat f = return $ literal str
| otherwise = do | otherwise = do
report $ BlockNotRendered b report $ BlockNotRendered b
return empty return empty
blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
blockToOrg (Header level attr inlines) = do blockToOrg (Header level attr inlines) = do
contents <- inlineListToOrg inlines contents <- inlineListToOrg inlines
let headerStr = text $ if level > 999 then " " else replicate level '*' let headerStr = text $ if level > 999 then " " else replicate level '*'
let drawerStr = if attr == nullAttr let drawerStr = if attr == nullAttr
skipping to change at line 151 skipping to change at line 151
return $ headerStr <> " " <> contents <> drawerStr <> cr return $ headerStr <> " " <> contents <> drawerStr <> cr
blockToOrg (CodeBlock (_,classes,kvs) str) = do blockToOrg (CodeBlock (_,classes,kvs) str) = do
let startnum = maybe "" (\x -> " " <> trimr x) $ lookup "startFrom" kvs let startnum = maybe "" (\x -> " " <> trimr x) $ lookup "startFrom" kvs
let numberlines = if "numberLines" `elem` classes let numberlines = if "numberLines" `elem` classes
then if "continuedSourceBlock" `elem` classes then if "continuedSourceBlock" `elem` classes
then " +n" <> startnum then " +n" <> startnum
else " -n" <> startnum else " -n" <> startnum
else "" else ""
let at = map pandocLangToOrg classes `intersect` orgLangIdentifiers let at = map pandocLangToOrg classes `intersect` orgLangIdentifiers
let (beg, end) = case at of let (beg, end) = case at of
[] -> ("#+BEGIN_EXAMPLE" <> numberlines, "#+END_EXAMPLE [] -> ("#+begin_example" <> numberlines, "#+end_example
") ")
(x:_) -> ("#+BEGIN_SRC " <> x <> numberlines, "#+END_SRC") (x:_) -> ("#+begin_src " <> x <> numberlines, "#+end_src")
return $ literal beg $$ nest 2 (literal str) $$ text end $$ blankline return $ literal beg $$ nest 2 (literal str) $$ text end $$ blankline
blockToOrg (BlockQuote blocks) = do blockToOrg (BlockQuote blocks) = do
contents <- blockListToOrg blocks contents <- blockListToOrg blocks
return $ blankline $$ "#+BEGIN_QUOTE" $$ return $ blankline $$ "#+begin_quote" $$
nest 2 contents $$ "#+END_QUOTE" $$ blankline nest 2 contents $$ "#+end_quote" $$ blankline
blockToOrg (Table _ blkCapt specs thead tbody tfoot) = do blockToOrg (Table _ blkCapt specs thead tbody tfoot) = do
let (caption', _, _, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot let (caption', _, _, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
caption'' <- inlineListToOrg caption' caption'' <- inlineListToOrg caption'
let caption = if null caption' let caption = if null caption'
then empty then empty
else "#+CAPTION: " <> caption'' else "#+caption: " <> caption''
headers' <- mapM blockListToOrg headers headers' <- mapM blockListToOrg headers
rawRows <- mapM (mapM blockListToOrg) rows rawRows <- mapM (mapM blockListToOrg) rows
let numChars = maximum . map offset let numChars = maximum . map offset
-- FIXME: width is not being used. -- FIXME: width is not being used.
let widthsInChars = let widthsInChars =
map numChars $ transpose (headers' : rawRows) map numChars $ transpose (headers' : rawRows)
-- FIXME: Org doesn't allow blocks with height more than 1. -- FIXME: Org doesn't allow blocks with height more than 1.
let hpipeBlocks blocks = hcat [beg, middle, end] let hpipeBlocks blocks = hcat [beg, middle, end]
where sep' = vfill " | " where sep' = vfill " | "
beg = vfill "| " beg = vfill "| "
skipping to change at line 294 skipping to change at line 294
isGreaterBlockClass = (`elem` ["center", "quote"]) . T.toLower isGreaterBlockClass = (`elem` ["center", "quote"]) . T.toLower
-- | Converts a Div to an org-mode element. -- | Converts a Div to an org-mode element.
divToOrg :: PandocMonad m divToOrg :: PandocMonad m
=> Attr -> [Block] -> Org m (Doc Text) => Attr -> [Block] -> Org m (Doc Text)
divToOrg attr bs = do divToOrg attr bs = do
contents <- blockListToOrg bs contents <- blockListToOrg bs
case divBlockType attr of case divBlockType attr of
GreaterBlock blockName attr' -> GreaterBlock blockName attr' ->
-- Write as greater block. The ID, if present, is added via -- Write as greater block. The ID, if present, is added via
-- the #+NAME keyword; other classes and key-value pairs -- the #+name keyword; other classes and key-value pairs
-- are kept as #+ATTR_HTML attributes. -- are kept as #+attr_html attributes.
return $ blankline $$ attrHtml attr' return $ blankline $$ attrHtml attr'
$$ "#+BEGIN_" <> literal blockName $$ "#+begin_" <> literal blockName
$$ contents $$ contents
$$ "#+END_" <> literal blockName $$ blankline $$ "#+end_" <> literal blockName $$ blankline
Drawer drawerName (_,_,kvs) -> do Drawer drawerName (_,_,kvs) -> do
-- Write as drawer. Only key-value pairs are retained. -- Write as drawer. Only key-value pairs are retained.
let keys = vcat $ map (\(k,v) -> let keys = vcat $ map (\(k,v) ->
":" <> literal k <> ":" ":" <> literal k <> ":"
<> space <> literal v) kvs <> space <> literal v) kvs
return $ ":" <> literal drawerName <> ":" $$ cr return $ ":" <> literal drawerName <> ":" $$ cr
$$ keys $$ blankline $$ keys $$ blankline
$$ contents $$ blankline $$ contents $$ blankline
$$ text ":END:" $$ blankline $$ text ":END:" $$ blankline
UnwrappedWithAnchor ident -> do UnwrappedWithAnchor ident -> do
skipping to change at line 322 skipping to change at line 322
-- div contents. -- div contents.
let contents' = if T.null ident let contents' = if T.null ident
then contents then contents
else "<<" <> literal ident <> ">>" $$ contents else "<<" <> literal ident <> ">>" $$ contents
return (blankline $$ contents' $$ blankline) return (blankline $$ contents' $$ blankline)
attrHtml :: Attr -> Doc Text attrHtml :: Attr -> Doc Text
attrHtml ("" , [] , []) = mempty attrHtml ("" , [] , []) = mempty
attrHtml (ident, classes, kvs) = attrHtml (ident, classes, kvs) =
let let
name = if T.null ident then mempty else "#+NAME: " <> literal ident <> cr name = if T.null ident then mempty else "#+name: " <> literal ident <> cr
keyword = "#+ATTR_HTML" keyword = "#+attr_html"
classKv = ("class", T.unwords classes) classKv = ("class", T.unwords classes)
kvStrings = map (\(k,v) -> ":" <> k <> " " <> v) (classKv:kvs) kvStrings = map (\(k,v) -> ":" <> k <> " " <> v) (classKv:kvs)
in name <> keyword <> ": " <> literal (T.unwords kvStrings) <> cr in name <> keyword <> ": " <> literal (T.unwords kvStrings) <> cr
-- | Convert list of Pandoc block elements to Org. -- | Convert list of Pandoc block elements to Org.
blockListToOrg :: PandocMonad m blockListToOrg :: PandocMonad m
=> [Block] -- ^ List of block elements => [Block] -- ^ List of block elements
-> Org m (Doc Text) -> Org m (Doc Text)
blockListToOrg blocks = vcat <$> mapM blockToOrg blocks blockListToOrg blocks = vcat <$> mapM blockToOrg blocks
skipping to change at line 441 skipping to change at line 441
let (scheme, path) = T.break (== ':') cs let (scheme, path) = T.break (== ':') cs
in T.all (\c -> isAlphaNum c || c `elemText` ".-") scheme in T.all (\c -> isAlphaNum c || c `elemText` ".-") scheme
&& not (T.null path) && not (T.null path)
-- | Translate from pandoc's programming language identifiers to those used by -- | Translate from pandoc's programming language identifiers to those used by
-- org-mode. -- org-mode.
pandocLangToOrg :: Text -> Text pandocLangToOrg :: Text -> Text
pandocLangToOrg cs = pandocLangToOrg cs =
case cs of case cs of
"c" -> "C" "c" -> "C"
"cpp" -> "C++"
"commonlisp" -> "lisp" "commonlisp" -> "lisp"
"r" -> "R" "r" -> "R"
"bash" -> "sh" "bash" -> "shell"
"lillypond" -> "ly"
_ -> cs _ -> cs
-- | List of language identifiers recognized by org-mode. -- | List of language identifiers recognized by org-mode.
orgLangIdentifiers :: [Text] orgLangIdentifiers :: [Text]
orgLangIdentifiers = orgLangIdentifiers =
[ "asymptote", "awk", "C", "C++", "clojure", "css", "d", "ditaa", "dot" [ "abc", "asymptote", "awk", "axiom", "C", "cpp", "calc", "clojure","comint"
, "calc", "emacs-lisp", "fortran", "gnuplot", "haskell", "java", "js" , "coq", "css", "D", "ditaa", "dot", "ebnf", "elixir", "eukleides", "fomus"
, "latex", "ledger", "lisp", "lilypond", "matlab", "mscgen", "ocaml" , "forth", "F90", "gnuplot", "Translate", "groovy", "haskell" , "browser"
, "octave", "org", "oz", "perl", "plantuml", "processing", "python", "R" , "request", "io", "ipython", "J", "java", "js", "julia", "kotlin", "latex"
, "ruby", "sass", "scheme", "screen", "sed", "sh", "sql", "sqlite" , "ledger", "ly", "lisp", "Flavored", "makefile", "mathematica", "mathomatic"
, "matlab", "max", "mongo", "mscgen", "cypher", "Caml", "octave" , "org", "oz"
, "perl", "picolisp", "plantuml", "processing", "prolog", "python" , "R"
, "rec", "ruby", "sass", "scala", "scheme", "screen", "sed", "shell", "shen"
, "sql", "sqlite", "stan", "ML", "stata", "tcl", "typescript", "vala"
] ]
 End of changes. 13 change blocks. 
24 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)