HTML reader: parse div with class line-block as LineBlock.

See #4162.
This commit is contained in:
John MacFarlane 2017-12-27 12:26:15 -08:00
parent cc9e3a9172
commit a888083ee1
3 changed files with 24 additions and 1 deletions

View file

@ -321,6 +321,7 @@ getDefaultExtensions "org" = extensionsFromList
getDefaultExtensions "html" = extensionsFromList
[Ext_auto_identifiers,
Ext_native_divs,
Ext_line_blocks,
Ext_native_spans]
getDefaultExtensions "html4" = getDefaultExtensions "html"
getDefaultExtensions "html5" = getDefaultExtensions "html"

View file

@ -51,7 +51,7 @@ import Data.Char (isAlphaNum, isDigit, isLetter)
import Data.Default (Default (..), def)
import Data.Foldable (for_)
import Data.List (intercalate, isPrefixOf)
import Data.List.Split (wordsBy)
import Data.List.Split (wordsBy, splitWhen)
import qualified Data.Map as M
import Data.Maybe (fromMaybe, isJust, isNothing)
import Data.Monoid (First (..), (<>))
@ -66,6 +66,7 @@ import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class (PandocMonad (..))
import Text.Pandoc.CSS (foldOrElse, pickStyleAttrProps)
import Text.Pandoc.Definition
import Text.Pandoc.Extensions (Extension(..))
import Text.Pandoc.Error
import Text.Pandoc.Logging
import Text.Pandoc.Options (
@ -191,6 +192,7 @@ block = do
, pHtml
, pHead
, pBody
, pLineBlock
, pDiv
, pPlain
, pFigure
@ -377,6 +379,16 @@ pRawTag = do
then return mempty
else return $ renderTags' [tag]
pLineBlock :: PandocMonad m => TagParser m Blocks
pLineBlock = try $ do
guardEnabled Ext_line_blocks
_ <- pSatisfy $ tagOpen (=="div") (== [("class","line-block")])
ils <- trimInlines . mconcat <$> manyTill inline (pSatisfy (tagClose (=="div")))
let lns = map B.fromList $
splitWhen (== LineBreak) $ filter (/= SoftBreak) $
B.toList ils
return $ B.lineBlock lns
pDiv :: PandocMonad m => TagParser m Blocks
pDiv = try $ do
guardEnabled Ext_native_divs

10
test/command/4162.md Normal file
View file

@ -0,0 +1,10 @@
```
% pandoc -f html -t native
<div class="line-block">hi<br /><br>
 there</div>
^D
[LineBlock
[[Str "hi"]
,[]
,[Str "\160there"]]]
```