javiereguiluz / easybook

Book publishing as easy as it should be (built with Symfony components)
https://easycorp.io/EasyBook
Other
754 stars 81 forks source link

"highlight_code" is not working for epub (?) #101

Closed lionel-m closed 11 years ago

lionel-m commented 11 years ago

Hi,

I use easybook 5.0-DEV and "highlight_code" does not work for epub.

I modified the configuration file :

ebook:
            highlight_code: true
lionel-m commented 11 years ago

PS : ok with PDF

javiereguiluz commented 11 years ago

@lionel-m it's fixed as of a41d715d6424f0c638d559a5e5da2c02a0b3cbf3

However, keep in mind that syntax highlighting doesn't work right for epub books. I've spent countless hours trying to make it work, but I'm afraid it's "impossible". The same book looks completely different in every device and/or application. I haven't found a single epub book with proper syntax highlighting that works everywhere. If you are aware of any, please tell me and I'll study how they did it. Thanks!

javiereguiluz commented 11 years ago

@lionel-m I'm sorry but I deleted your comment by mistake :(

I guess that the problem with the code that you showed in that picture is that you added tabs for each line:

(4 spaces) ```php
(4 spaces) $lorem = 'ipsum';
(4 spaces) ```

You don't need to add any tabs or spaces to the code. That's the great advantage of the github-style or fenced-style code blocks: no more messing with tabs or spaces. For that reason they always work as expected, no matter what code you write:

```php
$lorem = 'ipsum';
```
lionel-m commented 11 years ago

I just added spaces for the example in the deleted comment. Otherwise GitHub processes the ```. It was a way to show the entire code... Sorry.

A screenshot of the ebook and the markdown document.

capture decran 2013-08-12 a 17 15 55

Normally the name of the language should not be displayed.

javiereguiluz commented 11 years ago

The problem may be that in your config.yml file, the code blocks aren't properly configured.

easybook:
    parameters:
        parser.options:
            code_block_type: github

book:
    title:  # ...

I know that it's a bit cumbersome to add that configuration, but you only have to do it once per book and it's common to configure other important parameters, such as the location of the kindlegen utility to generate MOBI books.

You can read more about this configuration for code blocks in this blog post: http://easybook-project.org/blog/easybook-improves-the-code-listings-for-technical-books/

After adding this configuration, I can see your code listing as expected:

github_code_blocks

As a side comment, in your image I can see that you leave one whitespace before each code line. It's ok to do it, but it's not mandatory for fenced or github code blocks.

lionel-m commented 11 years ago

The problem may be that in your config.yml file, the code blocks aren't properly configured.

Sorry it was my mistake. I added the code and it is ok now. Thank you !