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

link_attributes does not convert size unit #6353

Closed
CodeSandwich opened this issue May 10, 2020 · 11 comments
Closed

link_attributes does not convert size unit #6353

CodeSandwich opened this issue May 10, 2020 · 11 comments
Labels

Comments

@CodeSandwich
Copy link

CodeSandwich commented May 10, 2020

I'm converting an MD to a HTML. According to the docs, the link_attributes extension should convert an image size unit to px for the HTML output. It doesn't seem to happen:

echo '![](pic.jpg){width=5cm}' | pandoc -f markdown -t html

prints

<p><img src="pic.jpg" style="width:5cm" /></p>

Enabling the extension manually doesn't fix the issue. -f markdown+link_attributes has no effect, but -t html+link_attributes causes an error: The extension link_attributes is not supported for html.

pandoc --version:

pandoc 2.9.2.1
Compiled with pandoc-types 1.20, texmath 0.12.0.2, skylighting 0.8.3.4
@mb21
Copy link
Collaborator

mb21 commented May 10, 2020

Indeed, the behaviour was changed in cb7b0a6#diff-9da4893eeab88b87f94db2b69af787ff without updating the MANUAL. The commit says:

Allow em, cm, in to pass through without conversion in HTML, LaTeX.

Closes #3450

Should we just update the MANUAL, or..?

@CodeSandwich
Copy link
Author

Interesting! I'm no haskeller, but it looks like the unit conversion funcitonality was completely removed? Or is there some other way to do that in Pandoc?

@mb21
Copy link
Collaborator

mb21 commented May 10, 2020

No, it's still there for certain output format and unit combinations... but centimeters are actually valid units in CSS, and some people want them to be passed through as is.

I'm not sure I agree with this, since CSS just defines 1cm = 96px, which is the default behaviour of pandoc's --dpi option anyway... so maybe we should revert this? @jgm Passing through em makes sense, but why cm and in?

@jgm
Copy link
Owner

jgm commented May 10, 2020

The manual says:
"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 %."

So, the attributes are treated as pixels only if no unit is specified. Here a unit is specified, and it's passed through unchanged. That accords with the docs, no?

@jgm
Copy link
Owner

jgm commented May 10, 2020

Oh, I see now: " Dimensions are converted to pixels for output in HTML-like formats. "

@jgm
Copy link
Owner

jgm commented May 10, 2020

Seems like we just need to update the documentation?
The current behavior in HTML seems fine: style is used to set the width and height (rather than width/height attributes, which only accept pixel values). And CSS allows all of these dimensions, if I'm not mistaken?

@jgm
Copy link
Owner

jgm commented May 10, 2020

See https://www.w3.org/Style/Examples/007/units.en.html
in and cm are definitely allowed, and there are cases where they might be preferred in HTML (esp. when you're targeting print).

@jgm jgm added the docs label May 10, 2020
@CodeSandwich
Copy link
Author

CodeSandwich commented May 10, 2020

You're right, I'll stick with cms. After all for CSS they are strictly equivalent to pxs, just with a multiplier.

I got mislead by all the materials on the internet discouraging from using real life units, but they seem to be focused on manual designing sites from scratch. For documents generated automatically using them seems fine.

Thank you!

@jgm jgm closed this as completed in 82eb4df May 11, 2020
@mb21
Copy link
Collaborator

mb21 commented May 11, 2020

Yeah, I actually liked having the width and height HTML attributes, as they can be easily overriden with CSS, and it's good practice anyway to have them, as browsers use them to calculate aspect ratio before external CSS is loaded.

But yeah, guess it doesn't really matter. The markdown width/height attributes are probably only used mostly for one-off documents anyway, and nobody appears to have complained about the change.

@CodeSandwich
Copy link
Author

CodeSandwich commented May 11, 2020

@jgm You've closed this issue, are the docs updated already?

@mb21
Copy link
Collaborator

mb21 commented May 11, 2020

will be put live in the next release, you can see the change here 82eb4df

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

No branches or pull requests

3 participants