git.iko.soy/typeable/pandoc
on master help sign in
Allow em for image height/width in HTML, LaTeX.
cb7b0a6John MacFarlane
src/Text/Pandoc/ImageSize.hs+18−2
@@ -43,6 +43,7 @@ module Text.Pandoc.ImageSize ( ImageType(..)
43 , inInch
43 , inInch
44 , inPixel
44 , inPixel
45 , inPoints
45 , inPoints
46+ , inEm
46 , numUnit
47 , numUnit
47 , showInInch
48 , showInInch
48 , showInPixel
49 , showInPixel
@@ -80,12 +81,14 @@ data Dimension = Pixel Integer
80 | Centimeter Double
81 | Centimeter Double
81 | Inch Double
82 | Inch Double
82 | Percent Double
83 | Percent Double
84+ | Em Double
83
85
84instance Show Dimension where
86instance Show Dimension where
85 show (Pixel a) = show a ++ "px"
87 show (Pixel a) = show a ++ "px"
86 show (Centimeter a) = showFl a ++ "cm"
88 show (Centimeter a) = showFl a ++ "cm"
87 show (Inch a) = showFl a ++ "in"
89 show (Inch a) = showFl a ++ "in"
88 show (Percent a) = show a ++ "%"
90 show (Percent a) = show a ++ "%"
91+ show (Em a) = showFl a ++ "em"
89
92
90data ImageSize = ImageSize{
93data ImageSize = ImageSize{
91 pxX :: Integer
94 pxX :: Integer
@@ -97,7 +100,13 @@ instance Default ImageSize where
97 def = ImageSize 300 200 72 72
100 def = ImageSize 300 200 72 72
98
101
99showFl :: (RealFloat a) => a -> String
102showFl :: (RealFloat a) => a -> String
100−showFl a = showFFloat (Just 5) a ""
103+showFl a = removeExtra0s $ showFFloat (Just 5) a ""
104+
105+removeExtra0s :: String -> String
106+removeExtra0s s =
107+ case dropWhile (=='0') $ reverse s of
108+ '.':xs -> reverse xs
109+ xs -> reverse xs
101
110
102imageType :: ByteString -> Maybe ImageType
111imageType :: ByteString -> Maybe ImageType
103imageType img = case B.take 4 img of
112imageType img = case B.take 4 img of
@@ -167,6 +176,9 @@ desiredSizeInPoints opts attr s =
167inPoints :: WriterOptions -> Dimension -> Double
176inPoints :: WriterOptions -> Dimension -> Double
168inPoints opts dim = 72 * inInch opts dim
177inPoints opts dim = 72 * inInch opts dim
169
178
179+inEm :: WriterOptions -> Dimension -> Double
180+inEm opts dim = (64/11) * inInch opts dim
181+
170inInch :: WriterOptions -> Dimension -> Double
182inInch :: WriterOptions -> Dimension -> Double
171inInch opts dim =
183inInch opts dim =
172 case dim of
184 case dim of
@@ -174,6 +186,7 @@ inInch opts dim =
174 (Centimeter a) -> a * 0.3937007874
186 (Centimeter a) -> a * 0.3937007874
175 (Inch a) -> a
187 (Inch a) -> a
176 (Percent _) -> 0
188 (Percent _) -> 0
189+ (Em a) -> a * (11/64)
177
190
178inPixel :: WriterOptions -> Dimension -> Integer
191inPixel :: WriterOptions -> Dimension -> Integer
179inPixel opts dim =
192inPixel opts dim =
@@ -181,7 +194,8 @@ inPixel opts dim =
181 (Pixel a) -> a
194 (Pixel a) -> a
182 (Centimeter a) -> floor $ dpi * a * 0.3937007874 :: Integer
195 (Centimeter a) -> floor $ dpi * a * 0.3937007874 :: Integer
183 (Inch a) -> floor $ dpi * a :: Integer
196 (Inch a) -> floor $ dpi * a :: Integer
184− _ -> 0
197+ (Percent _) -> 0
198+ (Em a) -> floor $ dpi * a * (11/64) :: Integer
185 where
199 where
186 dpi = fromIntegral $ writerDpi opts
200 dpi = fromIntegral $ writerDpi opts
187
201
@@ -213,6 +227,7 @@ scaleDimension factor dim =
213 Centimeter x -> Centimeter (factor * x)
227 Centimeter x -> Centimeter (factor * x)
214 Inch x -> Inch (factor * x)
228 Inch x -> Inch (factor * x)
215 Percent x -> Percent (factor * x)
229 Percent x -> Percent (factor * x)
230+ Em x -> Em (factor * x)
216
231
217-- | Read a Dimension from an Attr attribute.
232-- | Read a Dimension from an Attr attribute.
218-- `dimension Width attr` might return `Just (Pixel 3)` or for example `Just (Centimeter 2.0)`, etc.
233-- `dimension Width attr` might return `Just (Pixel 3)` or for example `Just (Centimeter 2.0)`, etc.
@@ -236,6 +251,7 @@ lengthToDim s = numUnit s >>= uncurry toDim
236 toDim a "" = Just $ Pixel (floor a::Integer)
251 toDim a "" = Just $ Pixel (floor a::Integer)
237 toDim a "pt" = Just $ Inch (a / 72)
252 toDim a "pt" = Just $ Inch (a / 72)
238 toDim a "pc" = Just $ Inch (a / 6)
253 toDim a "pc" = Just $ Inch (a / 6)
254+ toDim a "em" = Just $ Em a
239 toDim _ _ = Nothing
255 toDim _ _ = Nothing
240
256
241epsSize :: ByteString -> Maybe ImageSize
257epsSize :: ByteString -> Maybe ImageSize
src/Text/Pandoc/Writers/HTML.hs+3−4
@@ -533,10 +533,9 @@ dimensionsToAttrList :: WriterOptions -> Attr -> [(String, String)]
533dimensionsToAttrList opts attr = (go Width) ++ (go Height)
533dimensionsToAttrList opts attr = (go Width) ++ (go Height)
534 where
534 where
535 go dir = case (dimension dir attr) of
535 go dir = case (dimension dir attr) of
536+ (Just (Pixel a)) -> [(show dir, show a)]
536− (Just (Percent a)) -> [("style", show dir ++ ":" ++ show (Percent a))]
537+ (Just x) -> [("style", show dir ++ ":" ++ show x)]
537− (Just dim) -> [(show dir, showInPixel opts dim)]
538+ Nothing -> []
538− _ -> []
539−
540
539
541imageExts :: [String]
540imageExts :: [String]
542imageExts = [ "art", "bmp", "cdr", "cdt", "cpt", "cr2", "crw", "djvu", "erf",
541imageExts = [ "art", "bmp", "cdr", "cdt", "cpt", "cr2", "crw", "djvu", "erf",
test/command/3450.mdnew file+12
@@ -0,0 +1,12 @@
1+```
2+% pandoc -fmarkdown-implicit_figures
3+![image](lalune.jpg){height=2em}
4+^D
5+<p><img src="lalune.jpg" alt="image" style="height:2em" /></p>
6+```
7+```
8+% pandoc -fmarkdown-implicit_figures -t latex
9+![image](lalune.jpg){height=2em}
10+^D
11+\includegraphics[height=2em]{lalune.jpg}
12+```
test/command/svg.md+24−24
@@ -5,20 +5,20 @@
5[warning] Could not determine image size for 'command/corrupt.svg': could not determine image type
5[warning] Could not determine image size for 'command/corrupt.svg': could not determine image type
6<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
6<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
7 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
7 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
8− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 150.00000 -100.00000">
8+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
9 <Properties>
9 <Properties>
10 <PathGeometry>
10 <PathGeometry>
11 <GeometryPathType PathOpen="false">
11 <GeometryPathType PathOpen="false">
12 <PathPointArray>
12 <PathPointArray>
13− <PathPointType Anchor="-150.00000 -100.00000" LeftDirection="-150.00000 -100.00000" RightDirection="-150.00000 -100.00000" />
13+ <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
14− <PathPointType Anchor="-150.00000 100.00000" LeftDirection="-150.00000 100.00000" RightDirection="-150.00000 100.00000" />
14+ <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
15− <PathPointType Anchor="150.00000 100.00000" LeftDirection="150.00000 100.00000" RightDirection="150.00000 100.00000" />
15+ <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
16− <PathPointType Anchor="150.00000 -100.00000" LeftDirection="150.00000 -100.00000" RightDirection="150.00000 -100.00000" />
16+ <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
17 </PathPointArray>
17 </PathPointArray>
18 </GeometryPathType>
18 </GeometryPathType>
19 </PathGeometry>
19 </PathGeometry>
20 </Properties>
20 </Properties>
21− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -150.00000 -100.00000">
21+ <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
22 <Properties>
22 <Properties>
23 <Profile type="string">
23 <Profile type="string">
24 $ID/Embedded
24 $ID/Embedded
@@ -38,20 +38,20 @@
38[warning] Could not determine image size for 'command/SVG_logo.svg': could not determine SVG size
38[warning] Could not determine image size for 'command/SVG_logo.svg': could not determine SVG size
39<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
39<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
40 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
40 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
41− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 150.00000 -100.00000">
41+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
42 <Properties>
42 <Properties>
43 <PathGeometry>
43 <PathGeometry>
44 <GeometryPathType PathOpen="false">
44 <GeometryPathType PathOpen="false">
45 <PathPointArray>
45 <PathPointArray>
46− <PathPointType Anchor="-150.00000 -100.00000" LeftDirection="-150.00000 -100.00000" RightDirection="-150.00000 -100.00000" />
46+ <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
47− <PathPointType Anchor="-150.00000 100.00000" LeftDirection="-150.00000 100.00000" RightDirection="-150.00000 100.00000" />
47+ <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
48− <PathPointType Anchor="150.00000 100.00000" LeftDirection="150.00000 100.00000" RightDirection="150.00000 100.00000" />
48+ <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
49− <PathPointType Anchor="150.00000 -100.00000" LeftDirection="150.00000 -100.00000" RightDirection="150.00000 -100.00000" />
49+ <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
50 </PathPointArray>
50 </PathPointArray>
51 </GeometryPathType>
51 </GeometryPathType>
52 </PathGeometry>
52 </PathGeometry>
53 </Properties>
53 </Properties>
54− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -150.00000 -100.00000">
54+ <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
55 <Properties>
55 <Properties>
56 <Profile type="string">
56 <Profile type="string">
57 $ID/Embedded
57 $ID/Embedded
@@ -71,20 +71,20 @@
71[warning] Could not determine image size for 'command/SVG_logo-without-xml-declaration.svg': could not determine SVG size
71[warning] Could not determine image size for 'command/SVG_logo-without-xml-declaration.svg': could not determine SVG size
72<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
72<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
73 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
73 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
74− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 150.00000 -100.00000">
74+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 150 -100">
75 <Properties>
75 <Properties>
76 <PathGeometry>
76 <PathGeometry>
77 <GeometryPathType PathOpen="false">
77 <GeometryPathType PathOpen="false">
78 <PathPointArray>
78 <PathPointArray>
79− <PathPointType Anchor="-150.00000 -100.00000" LeftDirection="-150.00000 -100.00000" RightDirection="-150.00000 -100.00000" />
79+ <PathPointType Anchor="-150 -100" LeftDirection="-150 -100" RightDirection="-150 -100" />
80− <PathPointType Anchor="-150.00000 100.00000" LeftDirection="-150.00000 100.00000" RightDirection="-150.00000 100.00000" />
80+ <PathPointType Anchor="-150 100" LeftDirection="-150 100" RightDirection="-150 100" />
81− <PathPointType Anchor="150.00000 100.00000" LeftDirection="150.00000 100.00000" RightDirection="150.00000 100.00000" />
81+ <PathPointType Anchor="150 100" LeftDirection="150 100" RightDirection="150 100" />
82− <PathPointType Anchor="150.00000 -100.00000" LeftDirection="150.00000 -100.00000" RightDirection="150.00000 -100.00000" />
82+ <PathPointType Anchor="150 -100" LeftDirection="150 -100" RightDirection="150 -100" />
83 </PathPointArray>
83 </PathPointArray>
84 </GeometryPathType>
84 </GeometryPathType>
85 </PathGeometry>
85 </PathGeometry>
86 </Properties>
86 </Properties>
87− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -150.00000 -100.00000">
87+ <Image Self="ue6" ItemTransform="1 0 0 1 -150 -100">
88 <Properties>
88 <Properties>
89 <Profile type="string">
89 <Profile type="string">
90 $ID/Embedded
90 $ID/Embedded
@@ -104,20 +104,20 @@
104^D
104^D
105<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
105<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Paragraph">
106 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
106 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
107− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 54.75000 -65.25000">
107+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 54.75 -65.25">
108 <Properties>
108 <Properties>
109 <PathGeometry>
109 <PathGeometry>
110 <GeometryPathType PathOpen="false">
110 <GeometryPathType PathOpen="false">
111 <PathPointArray>
111 <PathPointArray>
112− <PathPointType Anchor="-54.75000 -65.25000" LeftDirection="-54.75000 -65.25000" RightDirection="-54.75000 -65.25000" />
112+ <PathPointType Anchor="-54.75 -65.25" LeftDirection="-54.75 -65.25" RightDirection="-54.75 -65.25" />
113− <PathPointType Anchor="-54.75000 65.25000" LeftDirection="-54.75000 65.25000" RightDirection="-54.75000 65.25000" />
113+ <PathPointType Anchor="-54.75 65.25" LeftDirection="-54.75 65.25" RightDirection="-54.75 65.25" />
114− <PathPointType Anchor="54.75000 65.25000" LeftDirection="54.75000 65.25000" RightDirection="54.75000 65.25000" />
114+ <PathPointType Anchor="54.75 65.25" LeftDirection="54.75 65.25" RightDirection="54.75 65.25" />
115− <PathPointType Anchor="54.75000 -65.25000" LeftDirection="54.75000 -65.25000" RightDirection="54.75000 -65.25000" />
115+ <PathPointType Anchor="54.75 -65.25" LeftDirection="54.75 -65.25" RightDirection="54.75 -65.25" />
116 </PathPointArray>
116 </PathPointArray>
117 </GeometryPathType>
117 </GeometryPathType>
118 </PathGeometry>
118 </PathGeometry>
119 </Properties>
119 </Properties>
120− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -54.75000 -65.25000">
120+ <Image Self="ue6" ItemTransform="1 0 0 1 -54.75 -65.25">
121 <Properties>
121 <Properties>
122 <Profile type="string">
122 <Profile type="string">
123 $ID/Embedded
123 $ID/Embedded
test/writer.icml+12−12
@@ -2833,20 +2833,20 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
2833<Br />
2833<Br />
2834<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Figure">
2834<ParagraphStyleRange AppliedParagraphStyle="ParagraphStyle/Figure">
2835 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
2835 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
2836− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 75.00000 -75.00000">
2836+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 75 -75">
2837 <Properties>
2837 <Properties>
2838 <PathGeometry>
2838 <PathGeometry>
2839 <GeometryPathType PathOpen="false">
2839 <GeometryPathType PathOpen="false">
2840 <PathPointArray>
2840 <PathPointArray>
2841− <PathPointType Anchor="-75.00000 -75.00000" LeftDirection="-75.00000 -75.00000" RightDirection="-75.00000 -75.00000" />
2841+ <PathPointType Anchor="-75 -75" LeftDirection="-75 -75" RightDirection="-75 -75" />
2842− <PathPointType Anchor="-75.00000 75.00000" LeftDirection="-75.00000 75.00000" RightDirection="-75.00000 75.00000" />
2842+ <PathPointType Anchor="-75 75" LeftDirection="-75 75" RightDirection="-75 75" />
2843− <PathPointType Anchor="75.00000 75.00000" LeftDirection="75.00000 75.00000" RightDirection="75.00000 75.00000" />
2843+ <PathPointType Anchor="75 75" LeftDirection="75 75" RightDirection="75 75" />
2844− <PathPointType Anchor="75.00000 -75.00000" LeftDirection="75.00000 -75.00000" RightDirection="75.00000 -75.00000" />
2844+ <PathPointType Anchor="75 -75" LeftDirection="75 -75" RightDirection="75 -75" />
2845 </PathPointArray>
2845 </PathPointArray>
2846 </GeometryPathType>
2846 </GeometryPathType>
2847 </PathGeometry>
2847 </PathGeometry>
2848 </Properties>
2848 </Properties>
2849− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -75.00000 -75.00000">
2849+ <Image Self="ue6" ItemTransform="1 0 0 1 -75 -75">
2850 <Properties>
2850 <Properties>
2851 <Profile type="string">
2851 <Profile type="string">
2852 $ID/Embedded
2852 $ID/Embedded
@@ -2869,20 +2869,20 @@ These should not be escaped: \$ \\ \&gt; \[ \{</Content>
2869 <Content>Here is a movie </Content>
2869 <Content>Here is a movie </Content>
2870 </CharacterStyleRange>
2870 </CharacterStyleRange>
2871 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
2871 <CharacterStyleRange AppliedCharacterStyle="$ID/NormalCharacterStyle">
2872− <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1.00000 0 0 1.00000 10.00000 -11.00000">
2872+ <Rectangle Self="uec" StrokeWeight="0" ItemTransform="1 0 0 1 10 -11">
2873 <Properties>
2873 <Properties>
2874 <PathGeometry>
2874 <PathGeometry>
2875 <GeometryPathType PathOpen="false">
2875 <GeometryPathType PathOpen="false">
2876 <PathPointArray>
2876 <PathPointArray>
2877− <PathPointType Anchor="-10.00000 -11.00000" LeftDirection="-10.00000 -11.00000" RightDirection="-10.00000 -11.00000" />
2877+ <PathPointType Anchor="-10 -11" LeftDirection="-10 -11" RightDirection="-10 -11" />
2878− <PathPointType Anchor="-10.00000 11.00000" LeftDirection="-10.00000 11.00000" RightDirection="-10.00000 11.00000" />
2878+ <PathPointType Anchor="-10 11" LeftDirection="-10 11" RightDirection="-10 11" />
2879− <PathPointType Anchor="10.00000 11.00000" LeftDirection="10.00000 11.00000" RightDirection="10.00000 11.00000" />
2879+ <PathPointType Anchor="10 11" LeftDirection="10 11" RightDirection="10 11" />
2880− <PathPointType Anchor="10.00000 -11.00000" LeftDirection="10.00000 -11.00000" RightDirection="10.00000 -11.00000" />
2880+ <PathPointType Anchor="10 -11" LeftDirection="10 -11" RightDirection="10 -11" />
2881 </PathPointArray>
2881 </PathPointArray>
2882 </GeometryPathType>
2882 </GeometryPathType>
2883 </PathGeometry>
2883 </PathGeometry>
2884 </Properties>
2884 </Properties>
2885− <Image Self="ue6" ItemTransform="1.00000 0 0 1.00000 -10.00000 -11.00000">
2885+ <Image Self="ue6" ItemTransform="1 0 0 1 -10 -11">
2886 <Properties>
2886 <Properties>
2887 <Profile type="string">
2887 <Profile type="string">
2888 $ID/Embedded
2888 $ID/Embedded