Skip to content

Commit 3fe014f

Browse files
committed
Use simpleFigureWith in DokuWiki reader
1 parent b7e2427 commit 3fe014f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/Text/Pandoc/Readers/DokuWiki.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,16 @@ blockFile :: PandocMonad m => DWParser m B.Blocks
505505
blockFile = codeTag B.codeBlockWith "file"
506506

507507
para :: PandocMonad m => DWParser m B.Blocks
508-
para = result . mconcat <$> many1Till inline endOfParaElement
508+
para = do
509+
result . B.trimInlines . mconcat <$> many1Till inline endOfParaElement
509510
where
510511
endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
511512
endOfInput = try $ skipMany blankline >> skipSpaces >> eof
512513
endOfPara = try $ blankline >> skipMany1 blankline
513514
newBlockElement = try $ blankline >> void blockElements
514515
result content = if F.all (==Space) content
515516
then mempty
516-
else B.para $ B.trimInlines content
517+
else case B.toList content of
518+
[Image attr figureCaption (src, _)] ->
519+
B.simpleFigureWith attr figureCaption src ""
520+
_ -> B.para content

test/Tests/Readers/DokuWiki.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Tests.Helpers
2020
import Text.Pandoc
2121
import Text.Pandoc.Arbitrary ()
2222
import Text.Pandoc.Builder
23+
import Data.List (intersperse)
2324

2425
dokuwiki :: Text -> Pandoc
2526
dokuwiki = purely $ readDokuWiki def{ readerStandalone = True }
@@ -144,31 +145,31 @@ tests = [ testGroup "inlines"
144145
, testGroup "Images"
145146
[ "Image" =:
146147
"{{image.jpg}}" =?>
147-
para (image "image.jpg" "" (str "image.jpg"))
148+
simpleFigure [Str "image.jpg"] "image.jpg" ""
148149
, "Image with caption" =:
149150
"{{image.png|This is the caption}}" =?>
150-
para (image "image.png" "" "This is the caption")
151+
simpleFigure (intersperse Space $ Str <$> T.words "This is the caption") "image.png" ""
151152
, "Image with } in caption" =:
152-
"{{image.png|There is an } in the caption}}" =?>
153-
para (image "image.png" "" "There is an } in the caption")
153+
"{{image.png|There is a } in the caption}}" =?>
154+
simpleFigure (intersperse Space $ Str <$> T.words "There is a } in the caption") "image.png" ""
154155
, "Wiki namespace starting with dot" =:
155156
"{{.wiki:image.jpg}}" =?>
156-
para (image "wiki/image.jpg" "" (str "image.jpg"))
157+
simpleFigure [Str "image.jpg"] "wiki/image.jpg" ""
157158
, "Left aligned image" =:
158159
"{{wiki:dokuwiki-128.png }}" =?>
159-
para (imageWith ("", ["align-left"], []) "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))
160+
simpleFigureWith ("", ["align-left"], []) [Str "dokuwiki-128.png"] "/wiki/dokuwiki-128.png" ""
160161
, "Right aligned image" =:
161162
"{{ wiki:dokuwiki-128.png}}" =?>
162-
para (imageWith ("", ["align-right"], []) "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))
163+
simpleFigureWith ("", ["align-right"], []) [Str "dokuwiki-128.png"] "/wiki/dokuwiki-128.png" ""
163164
, "Centered image" =:
164165
"{{ wiki:dokuwiki-128.png }}" =?>
165-
para (imageWith ("", ["align-center"], []) "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))
166+
simpleFigureWith ("", ["align-center"], []) [Str "dokuwiki-128.png"] "/wiki/dokuwiki-128.png" ""
166167
, "Image with width" =:
167168
"{{wiki:dokuwiki-128.png?50}}" =?>
168-
para (imageWith ("", [], [("width", "50")]) "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))
169+
simpleFigureWith ("", [], [("width","50")]) [Str "dokuwiki-128.png"] "/wiki/dokuwiki-128.png" ""
169170
, "Image with width and height" =:
170171
"{{wiki:dokuwiki-128.png?nocache&50x100}}" =?>
171-
para (imageWith ("", [], [("width", "50"), ("height", "100")]) "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))
172+
simpleFigureWith ("", [], [("width","50"), ("height", "100")]) [Str "dokuwiki-128.png"] "/wiki/dokuwiki-128.png" ""
172173
, "Linkonly" =:
173174
"{{wiki:dokuwiki-128.png?linkonly}}" =?>
174175
para (link "/wiki/dokuwiki-128.png" "" (str "dokuwiki-128.png"))

0 commit comments

Comments
 (0)