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

Recognize pdf.less and use the style.css of the wrap plugin by default #325

Merged
merged 2 commits into from
Jan 10, 2018

Conversation

micgro42
Copy link
Contributor

@micgro42 micgro42 commented Jan 10, 2018

The wrap plugin's styles are sufficiently simple that mpdf can handle them. Also, the print-styles of wrap are very bland, which constitutes a great loss for a plugin with the main focus on colorful styling. Finally the wrap plugin is widely spread, hence many users will benefit from this.

For the best result, this depends on the merge of selfthinker/dokuwiki_plugin_wrap#156

The wrap plugin's styles are sufficiently simple that mpdf can handle
them. Also the print-styles of wrap are very bland, which constitutes a
great loss for a plugin with a main focus of colorful styling. Finally
the wrap plugin is widely spread, hence many users will benefit from
this.
@Klap-in
Copy link
Collaborator

Klap-in commented Jan 10, 2018

Well spotted!

@Klap-in Klap-in merged commit 25ad3e4 into splitbrain:master Jan 10, 2018
@micgro42 micgro42 deleted the recognizePdfDotless branch January 11, 2018 10:02
@selfthinker
Copy link

I've merged the changes to the Wrap plugin, so that will be available in the next release.

After I made some other changes, I thought I could just add @import 'style.less'; to pdf.less, remove wrap, from usestyles and that would work the same and not need this change anymore. But for some reason that wasn't working. Any idea why?

@splitbrain
Copy link
Owner

Hmm just a wild guess, but it might be that the import path for less imports isn't properly set while handling plugin styles in dw2pdf...

@selfthinker
Copy link

selfthinker commented Mar 29, 2018

The other change I made was to move overlapping styles between print and pdf styles into their own LESS file and import it in the print and pdf styles and that works. (See selfthinker/dokuwiki_plugin_wrap@9c20817)
So, the weird thing is that @import 'print_or_pdf.less'; works while @import 'style.less'; does not.

@micgro42
Copy link
Contributor Author

Fixed it in selfthinker/dokuwiki_plugin_wrap#167 I think.

@selfthinker
Copy link

Thanks. As mentioned on that PR, it works much better but still has issues. Background images are not showing, which is maybe not very surprising. But two styles are also not displayed correctly (spoiler and default box) which doesn't make much sense as the rest is fine.

@selfthinker
Copy link

I just realised why the two styles are not showing while the rest is: They are the only ones which include CSS placeholders.

@micgro42
Copy link
Contributor Author

micgro42 commented Apr 3, 2018

Ok, the reason for the problems is in the following lines:

foreach($files as $file => $location) {
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
$css .= "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
$css .= css_loadfile($file, $location);
}
if(function_exists('css_parseless')) {
// apply pattern replacements
$styleini = css_styleini($conf['template']);
$css = css_applystyle($css, $styleini['replacements']);
// parse less
$css = css_parseless($css);
} else {

The replacement of the relative urls for the background images is done in line 746, the replacement for the __placeholders__ is done in line 752. However, the less is only parsed (and hence the imports executed) in line 756. After that point, no further replacements are made.

So workaround for the styles could be to use less placeholders, i.e. @ini_background works.

I'm not sure how to fix the images yet, because we cannot simply use the full path, because while that works in pdf, it then fails on screen. However, that could be fixed by moving the current styles in style.less to a common.less and @importing them from a new style.less. Thus disabling url replacement. But this is still not a nice solution.

This problem might affect DokuWiki core as well?

@selfthinker
Copy link

Thanks for looking into this.
I can switch the __placeholders__ with @ini_placeholders, no problem. I should have done that ages ago anyway. I've just done it but haven't merged it yet.

The potential solution to solve the images via common.less sounds a bit too hacky to me.
What is the difference between the image urls from styles added via the usestyles config option and added via importing them in pdf.less? Wouldn't both use the same underlying mechanism?

@micgro42
Copy link
Contributor Author

micgro42 commented Apr 4, 2018

No, because including a file via usestyles makes it one of the $files looped over in line 743 and thus handled by css_loadfile which does the URL-adjustments. However, adding a file via @import only includes its contents in line 755 -- too late for the URL-adjustments.

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

Successfully merging this pull request may close these issues.

4 participants