aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Readers/Org/BlockStarts.hs26
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs6
-rw-r--r--src/Text/Pandoc/Readers/Org/Inlines.hs15
-rw-r--r--tests/Tests/Readers/Org.hs34
4 files changed, 54 insertions, 27 deletions
diff --git a/src/Text/Pandoc/Readers/Org/BlockStarts.hs b/src/Text/Pandoc/Readers/Org/BlockStarts.hs
index e4dc31342..53a999307 100644
--- a/src/Text/Pandoc/Readers/Org/BlockStarts.hs
+++ b/src/Text/Pandoc/Readers/Org/BlockStarts.hs
@@ -37,9 +37,11 @@ module Text.Pandoc.Readers.Org.BlockStarts
, commentLineStart
, bulletListStart
, orderedListStart
+ , endOfBlock
) where
-import Text.Pandoc.Readers.Org.Parsing
+import Control.Monad ( void )
+import Text.Pandoc.Readers.Org.Parsing
-- | Horizontal Line (five -- dashes or more)
hline :: OrgParser ()
@@ -110,3 +112,25 @@ noteMarker = try $ do
, (++) <$> string "fn:"
<*> many1Till (noneOf "\n\r\t ") (char ']')
]
+
+ -- | Succeeds if the parser is at the end of a block.
+endOfBlock :: OrgParser ()
+endOfBlock = lookAhead . try $ do
+ void blankline <|> anyBlockStart <|> void noteMarker
+ where
+ -- | Succeeds if there is a new block starting at this position.
+ anyBlockStart :: OrgParser ()
+ anyBlockStart = try . choice $
+ [ exampleLineStart
+ , hline
+ , metaLineStart
+ , commentLineStart
+ , void noteMarker
+ , void tableStart
+ , void drawerStart
+ , void headerStart
+ , void latexEnvStart
+ , void bulletListStart
+ , void orderedListStart
+ ]
+
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index 481684600..807cce2fc 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -623,7 +623,7 @@ propertiesDrawer = try $ do
figure :: OrgParser (F Blocks)
figure = try $ do
figAttrs <- blockAttributes
- src <- skipSpaces *> selfTarget <* skipSpaces <* newline
+ src <- skipSpaces *> selfTarget <* skipSpaces <* endOfParagraph
case cleanLinkString src of
Nothing -> mzero
Just imgSrc -> do
@@ -652,6 +652,10 @@ figure = try $ do
then cs
else "fig:" ++ cs
+-- | Succeeds if looking at the end of the current paragraph
+endOfParagraph :: OrgParser ()
+endOfParagraph = try $ skipSpaces *> newline *> endOfBlock
+
--
-- Examples
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs
index 14e77dda9..97b36b388 100644
--- a/src/Text/Pandoc/Readers/Org/Inlines.hs
+++ b/src/Text/Pandoc/Readers/Org/Inlines.hs
@@ -33,7 +33,7 @@ module Text.Pandoc.Readers.Org.Inlines
, linkTarget
) where
-import Text.Pandoc.Readers.Org.BlockStarts
+import Text.Pandoc.Readers.Org.BlockStarts ( endOfBlock, noteMarker )
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Readers.Org.Parsing
import Text.Pandoc.Readers.Org.Shared
@@ -152,18 +152,7 @@ str = return . B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
endline :: OrgParser (F Inlines)
endline = try $ do
newline
- notFollowedBy blankline
- notFollowedBy' exampleLineStart
- notFollowedBy' hline
- notFollowedBy' noteMarker
- notFollowedBy' tableStart
- notFollowedBy' drawerStart
- notFollowedBy' headerStart
- notFollowedBy' metaLineStart
- notFollowedBy' latexEnvStart
- notFollowedBy' commentLineStart
- notFollowedBy' bulletListStart
- notFollowedBy' orderedListStart
+ notFollowedBy' endOfBlock
decEmphasisNewlinesCount
guard =<< newlinesCountWithinLimits
updateLastPreCharPos
diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs
index 882701644..6b07784b7 100644
--- a/tests/Tests/Readers/Org.hs
+++ b/tests/Tests/Readers/Org.hs
@@ -188,19 +188,29 @@ tests =
"=is_subst = True=" =?>
para (code "is_subst = True")
- , "Image" =:
- "[[./sunset.jpg]]" =?>
- (para $ image "./sunset.jpg" "" "")
-
- , "Image with explicit file: prefix" =:
- "[[file:sunrise.jpg]]" =?>
- (para $ image "sunrise.jpg" "" "")
+ , testGroup "Images"
+ [ "Image" =:
+ "[[./sunset.jpg]]" =?>
+ (para $ image "./sunset.jpg" "" "")
+
+ , "Image with explicit file: prefix" =:
+ "[[file:sunrise.jpg]]" =?>
+ (para $ image "sunrise.jpg" "" "")
+
+ , "Multiple images within a paragraph" =:
+ unlines [ "[[file:sunrise.jpg]]"
+ , "[[file:sunset.jpg]]"
+ ] =?>
+ (para $ (image "sunrise.jpg" "" "")
+ <> softbreak
+ <> (image "sunset.jpg" "" ""))
- , "Image with html attributes" =:
- unlines [ "#+ATTR_HTML: :width 50%"
- , "[[file:guinea-pig.gif]]"
- ] =?>
- (para $ imageWith ("", [], [("width", "50%")]) "guinea-pig.gif" "" "")
+ , "Image with html attributes" =:
+ unlines [ "#+ATTR_HTML: :width 50%"
+ , "[[file:guinea-pig.gif]]"
+ ] =?>
+ (para $ imageWith ("", [], [("width", "50%")]) "guinea-pig.gif" "" "")
+ ]
, "Explicit link" =:
"[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>