Keep comment-opening '%' along with the comment and support empty lines

This commit is contained in:
Tissevert 2019-05-31 15:07:41 +02:00
parent 85e4eb9273
commit 9dac275f68
2 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,7 @@ module PDF.Body (
import Control.Applicative ((<|>)) import Control.Applicative ((<|>))
import Control.Monad.State (get, gets, modify) import Control.Monad.State (get, gets, modify)
import Data.ByteString.Char8 (ByteString) import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS (drop, unpack) import qualified Data.ByteString.Char8 as BS (cons, drop, unpack)
import Data.Map ((!)) import Data.Map ((!))
import qualified Data.Map as Map (empty, insert, lookup) import qualified Data.Map as Map (empty, insert, lookup)
import qualified PDF.EOL as EOL (charset, parser) import qualified PDF.EOL as EOL (charset, parser)
@ -41,8 +41,9 @@ pushOccurrence newOccurrence = modifyFlow $ \flow -> flow {
} }
comment :: Parser u String comment :: Parser u String
comment = BS.unpack <$> comment = BS.unpack <$> (option "" afterPercent <* EOL.parser)
(char '%' *> takeAll (not . (`elem` EOL.charset)) <* EOL.parser) where
afterPercent = BS.cons <$> char '%' <*> takeAll (not . (`elem` EOL.charset))
lookupOffset :: Int -> XRefSection -> Maybe Int lookupOffset :: Int -> XRefSection -> Maybe Int
lookupOffset _ [] = Nothing lookupOffset _ [] = Nothing

View File

@ -242,7 +242,7 @@ data Occurrence = Comment String | Indirect IndirectObjCoordinates deriving Show
outputOccurrence :: Map Int Object -> Occurrence -> OBuilder outputOccurrence :: Map Int Object -> Occurrence -> OBuilder
outputOccurrence _ (Comment c) = outputOccurrence _ (Comment c) =
Output.string (printf "%%%s" c) `mappend` newLine Output.string c `mappend` newLine
outputOccurrence objects (Indirect (IndirectObjCoordinates {objectId, versionNumber})) = outputOccurrence objects (Indirect (IndirectObjCoordinates {objectId, versionNumber})) =
saveOffset (ObjectId objectId) saveOffset (ObjectId objectId)
>> Output.string (printf "%d %d obj" objectId versionNumber) >> Output.string (printf "%d %d obj" objectId versionNumber)