Skip to content

Use the SimpleFigure in Readers - #7611

Closed
argent0 wants to merge 2 commits into
jgm:masterfrom
argent0:figures-gsoc-only-simple-figure
Closed

Use the SimpleFigure in Readers#7611
argent0 wants to merge 2 commits into
jgm:masterfrom
argent0:figures-gsoc-only-simple-figure

Conversation

@argent0

@argent0 argent0 commented Oct 6, 2021

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@argent0 argent0 Oct 21, 2021

Copy link
Copy Markdown
Contributor Author

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)

@argent0 argent0 Oct 21, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@argent0 argent0 Oct 21, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.

toClose LineBlock{} = False
toClose HorizontalRule = False
toClose (Para [Image _ _ (_,t)]) = "fig:" `T.isPrefixOf` t
toClose SimpleFigure{} = True

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Align =

@jgm

jgm commented Oct 8, 2021

Copy link
Copy Markdown
Owner

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

@jgm

jgm commented Oct 20, 2021

Copy link
Copy Markdown
Owner

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

argent0 commented Oct 20, 2021

Copy link
Copy Markdown
Contributor Author

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

@jgm

jgm commented Oct 22, 2021

Copy link
Copy Markdown
Owner

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

@jgm jgm closed this Oct 22, 2021

@vadiknartiko vadiknartiko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

``

@vadiknartiko vadiknartiko left a comment

Copy link
Copy Markdown

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