@@ -146,6 +146,7 @@ data Opt = Opt
146146 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
147147 , optWrapText :: Bool -- ^ Wrap text
148148 , optSanitizeHTML :: Bool -- ^ Sanitize HTML
149+ , optLHSIn :: Bool -- ^ Treat input as literate haskell
149150#ifdef _CITEPROC
150151 , optModsFile :: String
151152 , optCslFile :: String
@@ -179,6 +180,7 @@ defaultOpts = Opt
179180 , optReferenceLinks = False
180181 , optWrapText = True
181182 , optSanitizeHTML = False
183+ , optLHSIn = False
182184#ifdef _CITEPROC
183185 , optModsFile = []
184186 , optCslFile = []
@@ -288,6 +290,11 @@ options =
288290 (\opt -> return opt { optSanitizeHTML = True }))
289291 "" -- "Sanitize HTML"
290292
293+ , Option "" ["lhs-in"]
294+ (NoArg
295+ (\opt -> return opt { optLHSIn = True }))
296+ "" -- "Treat input as literate haskell"
297+
291298 , Option "" ["toc", "table-of-contents"]
292299 (NoArg
293300 (\opt -> return opt { optTableOfContents = True }))
@@ -419,6 +426,11 @@ defaultReaderName (x:xs) =
419426 ".native" -> "native"
420427 _ -> defaultReaderName xs
421428
429+-- Returns True if extension of first source is .lhs
430+lhsExtension :: [FilePath] -> Bool
431+lhsExtension (x:_) = takeExtension x == ".lhs"
432+lhsExtension _ = False
433+
422434-- Determine default writer based on output file extension
423435defaultWriterName :: FilePath -> String
424436defaultWriterName "-" = "html" -- no output file
@@ -498,6 +510,7 @@ main = do
498510 , optReferenceLinks = referenceLinks
499511 , optWrapText = wrap
500512 , optSanitizeHTML = sanitize
513+ , optLHSIn = lhsIn
501514#ifdef _CITEPROC
502515 , optModsFile = modsFile
503516 , optCslFile = cslFile
@@ -556,17 +569,19 @@ main = do
556569#endif
557570
558571 let startParserState =
559− defaultParserState { stateParseRaw = parseRaw,
560− stateTabStop = tabStop,
561− stateSanitizeHTML = sanitize,
562− stateStandalone = standalone',
572+ defaultParserState { stateParseRaw = parseRaw,
573+ stateTabStop = tabStop,
574+ stateSanitizeHTML = sanitize,
575+ stateLiterateHaskell = lhsIn ||
576+ lhsExtension sources,
577+ stateStandalone = standalone',
563578#ifdef _CITEPROC
564− stateCitations = map citeKey refs,
579+ stateCitations = map citeKey refs,
565580#endif
566− stateSmart = smart || writerName' `elem`
567− ["latex", "context"],
568− stateColumns = columns,
569− stateStrict = strict }
581+ stateSmart = smart || writerName' `elem`
582+ ["latex", "context"],
583+ stateColumns = columns,
584+ stateStrict = strict }
570585 let csslink = if null css
571586 then ""
572587 else concatMap