Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the SimpleFigure in Readers #7611

Closed
wants to merge 2 commits into from

Conversation

argent0
Copy link
Contributor

@argent0 argent0 commented Oct 6, 2021

Hi,

This is the first part of #7364. It uses the SimpleFigure pattern synonym in the readers without changing the output.

The SimpleFigure pattern synonym was merged into pandoc-types here.

@argent0 argent0 marked this pull request as ready for review October 7, 2021 00:13
Comment on lines +938 to +939
, ("figure", env "figure" $ skipopts *> Text.Pandoc.Readers.LaTeX.figure)
, ("subfigure", env "subfigure" $ skipopts *> tok *> Text.Pandoc.Readers.LaTeX.figure)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These qualifications won't be necessary until figure is added to Builder, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct

Comment on lines +205 to +208
-- For the MediaWiki format all images are considered figures
[Image attr figureCaption (src, title)] ->
return $ B.simpleFigureWith
attr (B.fromList figureCaption) src title
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on "For the MediaWiki format all images are considered figures"? Is this a change in behavior? What motivates it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original (before I rewrote it using simple figure) code had that behavior and I kept it. I just implemented the behavior here (at lines ~205-208)

Comment on lines -634 to +639
return $ B.imageWith attr fname ("fig:" <> stringify caption) caption
return $ B.imageWith attr fname (stringify caption) caption
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Copy link
Contributor Author

@argent0 argent0 Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the previous one this is where the "For the MediaWiki format all images are considered figures" came from. The original code used the "fig:" prefix all the time as the deleted 634 line shows.

MediaWiki supports inline images: https://www.mediawiki.org/wiki/Help:Images

I just kept the old behavior. (but implemented it at lines ~206)

Copy link
Contributor Author

@argent0 argent0 Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch's version

$ pandoc -f mediawiki -t native
this [[File:example.jpg|caption]] is
[ Para
    [ Str "this"
    , Space
    , Image
        ( "" , [] , [] )
        [ Str "caption" ]
        ( "example.jpg" , "caption" )
    , Space
    , Str "is"
    ]
]

pandoc 2.14.1

$ pandoc -f mediawiki -t native foo.mediawiki
[Para [Str "this",Space,Image ("",[],[]) [Str "caption"] ("example.jpg","fig:caption"),Space,Str "is"]]

Notice the 'fig:' prefixing the caption.

It doesn't actually create a figure ([Para [Image ..]]) but it adds a superfluous (?) 'fig:'. This patch omits the fig:

So the comment should be removed\

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for clarifying, this makes sense.

Comment on lines +224 to 251
let fig = "figure:: " <> literal src
alt = ":alt: " <> if T.null tit then description else literal tit
capt = description
(_,cls,_) = attr
classes = case cls of
[] -> empty
["align-right"] -> ":align: right"
["align-left"] -> ":align: left"
["align-center"] -> ":align: center"
_ -> ":figclass: " <> literal (T.unwords cls)
return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
blockToRST (Para [Image attr txt (src, _)]) = do
description <- inlineListToRST txt
dims <- imageDimsToRST attr
let fig = "image:: " <> literal src
alt | null txt = empty
| otherwise = ":alt: " <> description
capt | isfig = description
| otherwise = empty
capt = empty
(_,cls,_) = attr
classes = case cls of
[] -> empty
["align-right"] -> ":align: right"
["align-left"] -> ":align: left"
["align-center"] -> ":align: center"
_ | isfig -> ":figclass: " <> literal (T.unwords cls)
| otherwise -> ":class: " <> literal (T.unwords cls)
_ -> ":class: " <> literal (T.unwords cls)
return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
blockToRST (Para inlines)
| LineBreak `elem` inlines =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consolidate some of the duplicated code used here to handle image attributes?
Also, what if there are multiple classes, one of which is e.g. align-center? we probably shouldn't assume there will just be one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look

Copy link
Contributor Author

@argent0 argent0 Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although for this iteration of the code we (tarleb and me) intended to keep the original behavior as much as possible. I'll see to consolidate the code in this commit and then make another commit that considers the possibility of multiple classes.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, fair enough, if the old code had the same issue, then this change doesn't need to fix it.

@@ -406,7 +412,7 @@ blockListToRST' topLevel blocks = do
toClose Header{} = False
toClose LineBlock{} = False
toClose HorizontalRule = False
toClose (Para [Image _ _ (_,t)]) = "fig:" `T.isPrefixOf` t
toClose SimpleFigure{} = True
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align =

@jgm
Copy link
Owner

jgm commented Oct 8, 2021

Great, thanks for updating this! I've made a few small comments, but this seems close to ready.

@jgm
Copy link
Owner

jgm commented Oct 20, 2021

I'd like to get this merged before we need to do more rebasing.
If you don't have time to work on the code, maybe you could answer the questions above about the changes to mediawiki, and I could help with the revisions needed?

@argent0
Copy link
Contributor Author

argent0 commented Oct 20, 2021

Sorry for the delay jgm, I'll work on this in the following hours.

@jgm
Copy link
Owner

jgm commented Oct 22, 2021

I went ahead and merged this manually.
Thanks for this contribution!

@jgm jgm closed this Oct 22, 2021
Copy link

@vadiknartiko vadiknartiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

``

Copy link

@vadiknartiko vadiknartiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants