Permalink
Browse files

Merge branch 'new-image-attributes' of https://github.com/mb21/pandoc

…into mb21-new-image-attributes

* Bumped version to 1.16.
* Added Attr field to Link and Image.
* Added `common_link_attributes` extension.
* Updated readers for link attributes.
* Updated writers for link attributes.
* Updated tests
* Updated stack.yaml to build against unreleased versions of
  pandoc-types and texmath.
* Fixed various compiler warnings.

Closes #261.

TODO:

* Relative (percentage) image widths in docx writer.
* ODT/OpenDocument writer (untested, same issue about percentage widths).
* Update pandoc-citeproc.
  • Loading branch information...
jgm committed Nov 20, 2015
2 parents 1ad296d + 08243d5 commit 244cd5644b44f43722530379138bd7bb9cbace9b
Showing with 1,181 additions and 748 deletions.
  1. +62 −5 README
  2. +4 −4 pandoc.cabal
  3. +16 −2 pandoc.hs
  4. +1 −1 src/Text/Pandoc.hs
  5. +138 −15 src/Text/Pandoc/ImageSize.hs
  6. +5 −0 src/Text/Pandoc/Options.hs
  7. +6 −6 src/Text/Pandoc/PDF.hs
  8. +14 −2 src/Text/Pandoc/Parsing.hs
  9. +1 −1 src/Text/Pandoc/Pretty.hs
  10. +2 −2 src/Text/Pandoc/Readers/CommonMark.hs
  11. +17 −7 src/Text/Pandoc/Readers/DocBook.hs
  12. +2 −2 src/Text/Pandoc/Readers/Docx.hs
  13. +6 −6 src/Text/Pandoc/Readers/EPUB.hs
  14. +11 −15 src/Text/Pandoc/Readers/HTML.hs
  15. +19 −10 src/Text/Pandoc/Readers/LaTeX.hs
  16. +31 −26 src/Text/Pandoc/Readers/Markdown.hs
  17. +19 −11 src/Text/Pandoc/Readers/MediaWiki.hs
  18. +10 −8 src/Text/Pandoc/Readers/RST.hs
  19. +4 −4 src/Text/Pandoc/Shared.hs
  20. +18 −6 src/Text/Pandoc/Writers/AsciiDoc.hs
  21. +2 −2 src/Text/Pandoc/Writers/CommonMark.hs
  22. +32 −9 src/Text/Pandoc/Writers/ConTeXt.hs
  23. +3 −3 src/Text/Pandoc/Writers/Custom.hs
  24. +28 −7 src/Text/Pandoc/Writers/Docbook.hs
  25. +11 −13 src/Text/Pandoc/Writers/Docx.hs
  26. +18 −6 src/Text/Pandoc/Writers/DokuWiki.hs
  27. +6 −6 src/Text/Pandoc/Writers/EPUB.hs
  28. +8 −8 src/Text/Pandoc/Writers/FB2.hs
  29. +47 −20 src/Text/Pandoc/Writers/HTML.hs
  30. +5 −5 src/Text/Pandoc/Writers/Haddock.hs
  31. +54 −41 src/Text/Pandoc/Writers/ICML.hs
  32. +35 −12 src/Text/Pandoc/Writers/LaTeX.hs
  33. +3 −3 src/Text/Pandoc/Writers/Man.hs
  34. +30 −21 src/Text/Pandoc/Writers/Markdown.hs
  35. +27 −6 src/Text/Pandoc/Writers/MediaWiki.hs
  36. +9 −8 src/Text/Pandoc/Writers/ODT.hs
  37. +8 −8 src/Text/Pandoc/Writers/OpenDocument.hs
  38. +4 −4 src/Text/Pandoc/Writers/Org.hs
  39. +48 −20 src/Text/Pandoc/Writers/RST.hs
  40. +7 −7 src/Text/Pandoc/Writers/RTF.hs
  41. +17 −8 src/Text/Pandoc/Writers/Texinfo.hs
  42. +23 −6 src/Text/Pandoc/Writers/Textile.hs
  43. +8 −0 stack.yaml
  44. +6 −4 tests/Tests/Arbitrary.hs
  45. +1 −1 tests/Tests/Writers/LaTeX.hs
  46. +33 −33 tests/docbook-reader.native
  47. +5 −5 tests/docbook-xref.native
  48. +1 −1 tests/docx/already_auto_ident.native
  49. +1 −1 tests/docx/image_no_embed.native
  50. +1 −1 tests/docx/image_no_embed_writer.native
  51. +1 −1 tests/docx/image_vml.native
  52. +2 −2 tests/docx/inline_images.native
  53. +2 −2 tests/docx/inline_images_writer.native
  54. +1 −1 tests/docx/link_in_notes.native
  55. +4 −4 tests/docx/links.native
  56. +4 −4 tests/docx/links_writer.native
  57. +1 −1 tests/dokuwiki_external_images.native
  58. +1 −1 tests/dokuwiki_multiblock_table.native
  59. +3 −3 tests/epub/features.native
  60. +4 −4 tests/epub/formatting.native
  61. +51 −51 tests/epub/wasteland.native
  62. +4 −4 tests/haddock-reader.native
  63. +32 −32 tests/html-reader.native
  64. +0 −27 tests/latex-reader.latex
  65. +34 −43 tests/latex-reader.native
  66. +25 −25 tests/markdown-reader-more.native
  67. +19 −17 tests/mediawiki-reader.native
  68. +4 −0 tests/mediawiki-reader.wiki
  69. +1 −1 tests/odt/native/referenceToChapter.native
  70. +1 −1 tests/odt/native/referenceToListItem.native
  71. +1 −1 tests/odt/native/referenceToText.native
  72. +1 −1 tests/opml-reader.native
  73. +10 −10 tests/rst-reader.native
  74. +1 −1 tests/tables.icml
  75. +33 −33 tests/testsuite.native
  76. +8 −8 tests/textile-reader.native
  77. +4 −4 tests/twiki-reader.native
  78. +13 −13 tests/txt2tags.native
  79. +14 −16 tests/writer.icml
  80. +33 −33 tests/writer.native
  81. +2 −2 tests/writer.rtf
67 README
@@ -517,14 +517,22 @@ General writer options
: Print a system default data file. Files in the user data directory
are ignored.

`--dpi`=*NUMBER*
: Specify the dpi (dots per inch) value for conversion from pixels
to inch/centimeters and vice versa. The default is 96dpi.
Technically, the correct term would be ppi (pixels per inch).

`--no-wrap`

: Disable text wrapping in output. By default, text is wrapped
appropriately for the output format.
appropriately for the output format. This affects only the
generated source code, not the layout on the rendered page.

`--columns=`*NUMBER*

: Specify length of lines in characters (for text wrapping).
This affects only the generated source code, not the layout on
the rendered page.

`--toc`, `--table-of-contents`

@@ -2909,6 +2917,49 @@ nonbreaking space after the image:

![This image won't be a figure](/url/of/image.png)\

#### Extension: `common_link_attributes` ####

Attributes can be set on links and images:

An inline ![image](foo.jpg){#id .class width=30 height=20px}
and a reference ![image][ref] with attributes.

[ref]: foo.jpg "optional title" {#id .class key=val key2="val 2"}

(This syntax is compatible with [PHP Markdown Extra] when only `#id`
and `.class` are used.)

For HTML and EPUB, all attributes except `width` and `height` (but
including `srcset` and `sizes`) are passed through as is. The other
writers ignore attributes that are not supported by their output
format.

The `width` and `height` attributes on images are treated specially. When
used without a unit, the unit is assumed to be pixels. However, any of
the following unit identifiers can be used: `px`, `cm`, `mm`, `in`, `inch`
and `%`. There must not be any spaces between the number and the unit.
For example:

```
![](file.jpg){ width=50% }
```

- Dimensions are converted to inches for output in page-based formats like
LaTeX. Dimensions are converted to pixels for output in HTML-like
formats. Use the `--dpi` option to specify the number of pixels per
inch. The default is 96dpi.
- The `%` unit is generally relative to some available space.
For example the above example will render to
`<img href="file.jpg" style="width: 50%;" />` (HTML),
`\includegraphics[width=0.5\textwidth]{file.jpg}` (LaTeX), or
`\externalfigure[file.jpg][width=0.5\textwidth]` (ConTeXt).
- Some output formats have a notion of a class
([ConTeXt](http://wiki.contextgarden.net/Using_Graphics#Multiple_Image_Settings))
or a unique identifier (LaTeX `\caption`), or both (HTML).
- When no `width` or `height` attributes are specified, the fallback
is to look at the image resolution and the dpi metadata embedded in
the image file.


Footnotes
---------
@@ -3221,9 +3272,14 @@ letters are omitted.

#### Extension: `link_attributes` ####

Parses multimarkdown style key-value attributes on link and image references.
Note that pandoc's internal document model provides nowhere to put
these, so they are presently just ignored.
Parses multimarkdown style key-value attributes on link
and image references. This extension should not be confused with the
[`common_link_attributes`](#extension-common_link_attributes) extension.

This is a reference ![image][ref] with multimarkdown attributes.

[ref]: http://path.to/image "Image title" width=20px height=30px
id=myId class="myClass1 myClass2"

#### Extension: `mmd_header_identifiers` ####

@@ -3266,7 +3322,8 @@ variants are supported:
`markdown_phpextra` (PHP Markdown Extra)
: `footnotes`, `pipe_tables`, `raw_html`, `markdown_attribute`,
`fenced_code_blocks`, `definition_lists`, `intraword_underscores`,
`header_attributes`, `abbreviations`, `shortcut_reference_links`.
`header_attributes`, `common_link_attributes`, `abbreviations`,
`shortcut_reference_links`.

`markdown_github` (GitHub-Flavored Markdown)
: `pipe_tables`, `raw_html`, `tex_math_single_backslash`,
@@ -1,5 +1,5 @@
Name: pandoc
Version: 1.15.2.1
Version: 1.16
Cabal-Version: >= 1.10
Build-Type: Custom
License: GPL
@@ -264,7 +264,7 @@ Library
xml >= 1.3.12 && < 1.4,
random >= 1 && < 1.2,
extensible-exceptions >= 0.1 && < 0.2,
pandoc-types >= 1.12.4 && < 1.13,
pandoc-types >= 1.16 && < 1.17,
aeson >= 0.7 && < 0.11,
tagsoup >= 0.13.1 && < 0.14,
base64-bytestring >= 0.1 && < 1.1,
@@ -412,7 +412,7 @@ Library

Executable pandoc
Build-Depends: pandoc,
pandoc-types >= 1.12.4 && < 1.13,
pandoc-types >= 1.16 && < 1.17,
base >= 4.2 && <5,
directory >= 1 && < 1.3,
filepath >= 1.1 && < 1.5,
@@ -469,7 +469,7 @@ Test-Suite test-pandoc
Build-Depends: base >= 4.2 && < 5,
syb >= 0.1 && < 0.7,
pandoc,
pandoc-types >= 1.12.4 && < 1.13,
pandoc-types >= 1.16 && < 1.17,
bytestring >= 0.9 && < 0.11,
text >= 0.11 && < 1.3,
directory >= 1 && < 1.3,
@@ -196,6 +196,7 @@ data Opt = Opt
, optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
, optVerbose :: Bool -- ^ Verbose diagnostic output
, optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
, optDpi :: Int -- ^ Dpi
, optWrapText :: Bool -- ^ Wrap text
, optColumns :: Int -- ^ Line length in characters
, optFilters :: [FilePath] -- ^ Filters to apply
@@ -258,6 +259,7 @@ defaultOpts = Opt
, optIgnoreArgs = False
, optVerbose = False
, optReferenceLinks = False
, optDpi = 96
, optWrapText = True
, optColumns = 72
, optFilters = []
@@ -454,6 +456,16 @@ options =
"FILE")
"" -- "Print default data file"

, Option "" ["dpi"]
(ReqArg
(\arg opt ->
case safeRead arg of
Just t | t > 0 -> return opt { optDpi = t }
_ -> err 31
"dpi must be a number greater than 0")
"NUMBER")
"" -- "Dpi (default 96)"

, Option "" ["no-wrap"]
(NoArg
(\opt -> return opt { optWrapText = False }))
@@ -1029,8 +1041,8 @@ extractMedia media dir d =
return $ walk (adjustImagePath dir fps) d

adjustImagePath :: FilePath -> [FilePath] -> Inline -> Inline
adjustImagePath dir paths (Image lab (src, tit))
| src `elem` paths = Image lab (dir ++ "/" ++ src, tit)
adjustImagePath dir paths (Image attr lab (src, tit))
| src `elem` paths = Image attr lab (dir ++ "/" ++ src, tit)
adjustImagePath _ _ x = x

adjustMetadata :: M.Map String MetaValue -> Pandoc -> IO Pandoc
@@ -1104,6 +1116,7 @@ main = do
, optIgnoreArgs = ignoreArgs
, optVerbose = verbose
, optReferenceLinks = referenceLinks
, optDpi = dpi
, optWrapText = wrap
, optColumns = columns
, optFilters = filters
@@ -1327,6 +1340,7 @@ main = do
writerNumberOffset = numberFrom,
writerSectionDivs = sectionDivs,
writerReferenceLinks = referenceLinks,
writerDpi = dpi,
writerWrapText = wrap,
writerColumns = columns,
writerEmailObfuscation = obfuscationMethod,
@@ -266,7 +266,7 @@ writers = [
,("html" , PureStringWriter writeHtmlString)
,("html5" , PureStringWriter $ \o ->
writeHtmlString o{ writerHtml5 = True })
,("icml" , PureStringWriter writeICML)
,("icml" , IOStringWriter writeICML)
,("s5" , PureStringWriter $ \o ->
writeHtmlString o{ writerSlideVariant = S5Slides
, writerTableOfContents = False })
Oops, something went wrong.

0 comments on commit 244cd56

Please sign in to comment.