diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-04-01 15:52:32 -0700 |
---|---|---|
committer | mb21 <mb21@users.noreply.github.com> | 2015-07-27 21:52:43 +0200 |
commit | 5df099957e0ed252a4d36161fc6c4ce7b18f528b (patch) | |
tree | 0abf62e67dfdd1d57b9512f66a39dc367c9985e1 | |
parent | 2e8064346d17bbb25a16650fc074393e834d67f7 (diff) | |
download | pandoc-5df099957e0ed252a4d36161fc6c4ce7b18f528b.tar.gz |
Text.Pandoc.Options: modifications for image attributes.
* Added `Ext_common_link_attributes` constructor to `Extension`
(for link and image attributes).
* Added this to `pandocExtensions` and `phpMarkdownExtraExtensions`.
* Added `writerDpi` to `WriterOptions`.
* pandoc.hs: Added `--dpi` option.
* Updated README for `--dpi` and `common_link_attributes` extension.
Patch due to mb21, with some modifications: `writerDpi` is now an
`Int` rather than a `Double`.
-rw-r--r-- | README | 72 | ||||
-rw-r--r-- | pandoc.hs | 18 | ||||
-rw-r--r-- | src/Text/Pandoc/Options.hs | 5 |
3 files changed, 88 insertions, 7 deletions
@@ -420,14 +420,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` @@ -2634,6 +2642,53 @@ 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 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. + +Note that while attributes are also parsed on links, pandoc's internal +document model provides nowhere to put them, so they are presently +just ignored. + Footnotes --------- @@ -2908,9 +2963,15 @@ 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. (Since pandoc's internal document model +provides nowhere to put these for links, they are presently just +ignored, but they work for images.) + + 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` #### @@ -2953,7 +3014,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`, @@ -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 })) @@ -1012,8 +1024,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 @@ -1087,6 +1099,7 @@ main = do , optIgnoreArgs = ignoreArgs , optVerbose = verbose , optReferenceLinks = referenceLinks + , optDpi = dpi , optWrapText = wrap , optColumns = columns , optFilters = filters @@ -1304,6 +1317,7 @@ main = do writerNumberOffset = numberFrom, writerSectionDivs = sectionDivs, writerReferenceLinks = referenceLinks, + writerDpi = dpi, writerWrapText = wrap, writerColumns = columns, writerEmailObfuscation = obfuscationMethod, diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index 17eb4a15c..060fa6c05 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -86,6 +86,7 @@ data Extension = | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown -- iff container has attribute 'markdown' | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak + | Ext_common_link_attributes -- ^ link and image attributes | Ext_link_attributes -- ^ MMD style reference link attributes | Ext_autolink_bare_uris -- ^ Make all absolute URIs into links | Ext_fancy_lists -- ^ Enable fancy list numbers and delimiters @@ -154,6 +155,7 @@ pandocExtensions = Set.fromList , Ext_subscript , Ext_auto_identifiers , Ext_header_attributes + , Ext_common_link_attributes , Ext_implicit_header_references , Ext_line_blocks , Ext_shortcut_reference_links @@ -187,6 +189,7 @@ phpMarkdownExtraExtensions = Set.fromList , Ext_definition_lists , Ext_intraword_underscores , Ext_header_attributes + , Ext_common_link_attributes , Ext_abbreviations , Ext_shortcut_reference_links ] @@ -324,6 +327,7 @@ data WriterOptions = WriterOptions , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML , writerExtensions :: Set Extension -- ^ Markdown extensions that can be used , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst + , writerDpi :: Int -- ^ Dpi for pixel to/from inch/cm conversions , writerWrapText :: Bool -- ^ Wrap text to line length , writerColumns :: Int -- ^ Characters in a line (for text wrapping) , writerEmailObfuscation :: ObfuscationMethod -- ^ How to obfuscate emails @@ -370,6 +374,7 @@ instance Default WriterOptions where , writerSectionDivs = False , writerExtensions = pandocExtensions , writerReferenceLinks = False + , writerDpi = 96 , writerWrapText = True , writerColumns = 72 , writerEmailObfuscation = JavascriptObfuscation |