div inside p
u07 opened this issue · comments
Hi! There is a code in dw2pdf's renderer.php:
/**
* Wrap centered media in a div to center it
*/
function _media($src, $title = NULL, $align = NULL, $width = NULL,
$height = NULL, $cache = NULL, $render = true) {
$out = '';
if($align == 'center') {
$out .= '<div align="center" style="text-align: center">';
}
$out .= parent::_media($src, $title, $align, $width, $height, $cache, $render);
if($align == 'center') {
$out .= '</div>';
}
return $out;
}
This results in html code like this:
<p>
<a href="1.jpg" class="media" title="1.jpg"><div align="center" style="text-align: center"><img src="1.jpg" class="mediacenter" title="1.jpg" alt="1.jpg" /></div></a>
</p>
Here we have a <DIV> tag inside <A> tag inside <P> tag, which does not comply HTML standards: a P tag should contain phrasing content only. Also it breaks mpdf logic and makes links in PDF broken, so, it's impossible to click on the image. You know, in DokuWiki images are links to their full versions. So, in PDF right- or left-aligned images are links, and center-aligned are not .
Is it possible to rewrite this function to align images somehow else, without introducing new DIVs inside <a>?
As I see it, a solution could be to place <a> inside <div>, not the other way around. That fixes everything. But I don't see a way to implement that in code (renderer.php)
Okay, I've managed to patch it. Do you accept patches or pull requests, what's the right way to send it? or just here, in comments? I've never made pull requests :)
Is this issue also connected to #275?
Code example is welcome.
Pull request is welcome as well, but I'm wondering if it is worth to check more thoroughly the image handling.
Is this issue also connected to #275?
They are not. That patch can be applied alongside with this one. Actually №275 helped to notice broken links. It made them visible, like this:
Code example
I moved <div> tag outside of <a>. To do so I moved the div wrapping code from _media() to internalmedia() and externalmedia(), cause they actually produce <a> tags.
// Center-align images with their corresponding links
function internalmedia($src, $title = null, $align = null, $width = null,
$height = null, $cache = null, $linking = null, $return = false) {
$out = parent::internalmedia($src, $title, $align, $width, $height, $cache, $linking, true);
if($align == 'center') {
$out = '<div align="center" style="text-align: center">' .$out. '</div>';
}
if($return) return $out;
else $this->doc .= $out;
}
It's impossible to show on a screenshot :) but both images are links now. And #275 produces a nice paragraph flow:
Here is a live example with both patches applied: https://petelinsasha.ru/wiki/playground/dw2pdf_test
If the html is not proper, that should be 'fixed' before we feed it to mpdf, or mpdf should be improved (then tiny example that exactly replicate the case should be created, and used to open an issue there), or DokuWiki should be changed as well, if it is not proper html.