Skip to content

Commit

Permalink
Merge pull request #3 from timjb/master
Browse files Browse the repository at this point in the history
Remove empty paragraphs
  • Loading branch information
michael committed Aug 11, 2011
2 parents 62673c9 + 29cf0c3 commit 04c1856
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
@@ -1,2 +1,2 @@
convert: Pandoc/Filters/ParseHtml.hs Pandoc/Readers/HTML.hs Pandoc/convert.hs
convert: Pandoc/Filters/ParseHtml.hs Pandoc/Filters/Compact.hs Pandoc/Readers/HTML.hs Pandoc/convert.hs
ghc --make Pandoc/convert.hs -o convert
18 changes: 18 additions & 0 deletions Pandoc/Filters/Compact.hs
@@ -0,0 +1,18 @@
module Pandoc.Filters.Compact
( compact
) where

import Text.Pandoc (bottomUp, Pandoc(..), Block(..), Inline(..))

-- | Removes empty paragraphs
compact :: Pandoc -> Pandoc
compact = bottomUp (filter $ not . isEmpty)

isEmpty :: Block -> Bool
isEmpty (Para inlines) = null $ filter (not . isSpace) inlines
isEmpty _ = False

isSpace :: Inline -> Bool
isSpace Space = True
isSpace LineBreak = True
isSpace _ = False
3 changes: 2 additions & 1 deletion Pandoc/convert.hs
Expand Up @@ -13,6 +13,7 @@ import Text.Pandoc.Templates (getDefaultTemplate)
import Text.JSON.Generic (decodeJSON)

import Pandoc.Filters.ParseHtml (parseHtml)
import Pandoc.Filters.Compact (compact)

binaryWriters :: [(String, WriterOptions -> Pandoc -> IO B.ByteString)]
binaryWriters =
Expand All @@ -24,7 +25,7 @@ binaryWriters =
main :: IO ()
main = do
[format,outputFile,templatesDir] <- getArgs
doc <- liftM (parseHtml . decodeJSON) getContents
doc <- liftM (compact . parseHtml . decodeJSON) getContents
template <- getTemplate templatesDir format
let writerOptions = defaultWriterOptions
{ writerStandalone = True
Expand Down
5 changes: 5 additions & 0 deletions server.coffee
Expand Up @@ -69,6 +69,11 @@ app.get /^\/[a-zA-Z0-9_]+\.([a-z0-9]+)/, (req, res) ->
{url} = req.query
handleConversion(res, url, formats.byExtension[extension])

# Fallback for those who have JavaScript disabled
app.get '/render', (req, res) ->
{url,format} = req.query
handleConversion(res, url, formats.byName[format])


# Start the fun
# =============
Expand Down

0 comments on commit 04c1856

Please sign in to comment.