epub-press-clients icon indicating copy to clipboard operation
epub-press-clients copied to clipboard

Preserve text indentation

Open tarmo-t opened this issue 6 years ago • 3 comments

When converting content that contains indented text, for things such as lines of code, the resulting ePub removes all the indenting and left aligns the lines of code. This makes it hard to read the code examples.

tarmo-t avatar Nov 22 '17 03:11 tarmo-t

Thanks for the comment @tarmo-t !

Do you have an example page? I've looked into doing this before and it's not always simple.

For example, a code block might have a lot of HTML within it:

<span class="keyword">function</span> <span class="identifier">HelloWorld</span>()<span class="bracket>{</span><br><span class="bracket">}</span>
function HelloWorld() { }

Or maybe if looks completely different within the page depending on the styles given to the code block.

So it's somewhat on a case to case basis.

Most sites also make code blocks scroll, so long lines of code can go on forever. In ebooks, it's not possible to scroll so the code needs to wrap. And when the wrapping style isn't code aware so it just wraps everything to where the line starts.

Suggestions welcome if anyone has seen great code blocks within an ebook somewhere.

haroldtreen avatar Nov 23 '17 05:11 haroldtreen

It seems to me indentation works well, except that all lines but the first are offset 6 letters too far to the right.

Also, extra new lines seem not to be honored (the first two empty lines in the example code block), unless they also contain extra white space (the third empty line).

An example for both would be the last code block in http://doisinkidney.com/posts/2016-09-27-odds-lhs.html . The code blocks are wrapped in the PRE html element with just the standard "white-space: pre" css style.

I'm attaching a screenshot of the mobi file generated just now by the Firefox extension as displayed on Kindle PW3, version 5.9.4.

screenshot_2018_02_13t09_44_09 0100

pivisko avatar Feb 13 '18 08:02 pivisko

Every code blocks on https://laravel.com/docs/5.8/eloquent-relationships have the same problem with @pivisko 2019-03-27-10-43-26

quanengineering avatar Mar 27 '19 03:03 quanengineering