最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】crifan的gitbook的模板make deploy出错:Could not find reasonable point at which to split Sub-tree size KB

gitbook crifan 1511浏览 0评论
用自己的gitbook的template去发布
make deploy
结果其中的epub生成报错:
。。。
Ignoring CSS rule with invalid selector: u'input[type=search]::-webkit-search-decoration' (The pseudo-class :-webkit-search-decoration is not supported)
Ignoring CSS rule with invalid selector: u'pre[class*="language-"]::selection' (The pseudo-class :selection is not supported)
Ignoring CSS rule with invalid selector: u'pre[class*="language-"] ::selection' (The pseudo-class :selection is not supported)
Ignoring CSS rule with invalid selector: u'code[class*="language-"]::selection' (The pseudo-class :selection is not supported)
Ignoring CSS rule with invalid selector: u'code[class*="language-"] ::selection' (The pseudo-class :selection is not supported)
Source base font size is 10.20000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Creating EPUB Output...
67% Running EPUB Output plugin
Rescaling image from 2340x1080 to 1586x732 anheijuexing_announcement_popop.jpg
Rescaling image from 2340x1080 to 1586x732 anheijuexing_first_charge.jpg
Splitting markup on page breaks and flow limits, if any...
        Looking for large trees in pillow.html...
        No large trees found
        Looking for large trees in baidu_ocr.html...
        Found large tree #0
Python function terminated unexpectedly: Could not find reasonable point at which to split: baidu_ocr.html Sub-tree size: 302 KB
Traceback (most recent call last):
  File "/Applications/calibre.app/Contents/Resources/Python/lib/python2.7/site.py", line 187, in main
    return run_entry_point()
  File "/Applications/calibre.app/Contents/Resources/Python/lib/python2.7/site.py", line 121, in run_entry_point
    return getattr(pmod, func)()
  File "site-packages/calibre/ebooks/conversion/cli.py", line 401, in main
  File "site-packages/calibre/ebooks/conversion/plumber.py", line 1275, in run
  File "site-packages/calibre/ebooks/conversion/plugins/epub_output.py", line 207, in convert
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 66, in __call__
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 76, in split_item
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 224, in __init__
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 372, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 372, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 372, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 372, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 357, in split_to_size
  File "site-packages/calibre/ebooks/oeb/transforms/split.py", line 350, in split_to_size
calibre.ebooks.oeb.transforms.split.SplitError: Could not find reasonable point at which to split: baidu_ocr.html Sub-tree size: 302 KB

make: *** [epub] Error 1
导致无法继续。
去看看什么原因或情况
如果实在无法解决,就暂时放弃此单个book的epub格式。
毕竟其他几十本的book都没有这个问题。
calibre.ebooks.oeb.transforms.split.SplitError: Could not find reasonable point at which to split: baidu_ocr.html Sub-tree size
Bug #1427694 “Converting MOBI to EPUB fails with “SplitError: Co…” : Bugs : calibre
2015年就有人报告此错误了?
好像是:
此处刚增加的百度OCR的章节,代码太长导致报错了?
That error indicates the input file contains some large block of
unstructured text. You can work around it by increasing the split size
int he epub output section of the conversion dialog, but be aware that
the resulting epub file might not work on some older e-ink devices.
那去找找,如何设置和增加epub转换时设置更大的split size?
ebook-convert book.mobi book.epub --flow-size 1000000
去参考此处,先确定此处的:302KB
给个更大的值,比如1MB=1073741824
calibre/split.py at master · kovidgoyal/calibre
去看看ebook-convert有哪些参数
 ~  ebook-convert --help
Usage: ebook-convert input_file output_file [options]


Convert an e-book from one format to another.


input_file is the input and output_file is the output. Both must be specified as the first two arguments to the command.


The output e-book format is guessed from the file extension of output_file. output_file can also be of the special format .EXT where EXT is the output file extension. In this case, the name of the output file is derived from the name of the input file. Note that the filenames must not start with a hyphen. Finally, if output_file has no extension, then it is treated as a directory and an "open e-book" (OEB) consisting of HTML files is written to that directory. These files are the files that would normally have been passed to the output plugin.


After specifying the input and output file you can customize the conversion by specifying various options. The available options depend on the input and output file types. To get help on them specify the input and output file and then use the -h option.


For full documentation of the conversion system see
https://manual.calibre-ebook.com/conversion.html


Whenever you pass arguments to ebook-convert that have spaces in them, enclose the arguments in quotation marks. For example: "/some path/with spaces"


Options:
  --version       show program's version number and exit


  -h, --help      show this help message and exit


  --list-recipes  List builtin recipe names. You can create an e-book from a
                  builtin recipe like this: ebook-convert "Recipe Name.recipe"
                  output.epub
->竟然没有options的介绍
Mobi to Epub Failed to Convert
‘flow_size’: 260,
Failure to convert from mobi to epub
‘flow_size’: 260,
calibre/split.py at master · kovidgoyal/calibre
class FlowSplitter(object):
    'The actual splitting logic'
    def __init__(self, item, page_breaks, page_break_ids, max_flow_size, oeb,
            opts):
。。。
        self.max_flow_size  = max_flow_size
ebook-convert options
Ubuntu Manpage: ebook-convert – ebook-convert
--flow-size
              Split all HTML files larger than this size (in KB). This is necessary as most  EPUB
              readers  cannot  handle large file sizes. The default of 260KB is the size required
              for Adobe Digital Editions. Set to 0 to disable size based splitting.
默认是260KB
-》此处巧了,超过了,是302KB
-》所以可以改为:512KB
ebook-convert book.mobi book.epub --flow-size 512
去试试
此处没有直接用欧诺个ebook-convert,而是gitbook:
/Users/xxx/dev/crifan/gitbook/gitbook_template/common/gitbook_makefile.mk
GITBOOK_COMMON_FLAGS= --log debug

## Generate ePub file
epub: sync_content clean_epub create_folder_epub
    @echo ================================================================================
    @echo Generate ePub for $(BOOK_NAME)
    gitbook epub $(CURRENT_DIR) $(EPUB_FULLNAME) $(GITBOOK_COMMON_FLAGS)
-》感觉是:可以单独给epub后面加上参数?
去试试
    gitbook epub $(CURRENT_DIR) $(EPUB_FULLNAME) $(GITBOOK_COMMON_FLAGS) --flow-size 512
结果:
log
Generate ePub for python_common_code_snippet
gitbook epub /Users/xxx/dev/crifan/gitbook/gitbook_template/books/python_common_code_snippet /Users/xxx/dev/crifan/gitbook/gitbook_template/generated/books/python_common_code_snippet/release/python_common_code_snippet/epub/python_common_code_snippet.epub --log debug --flow-size 512
。。。
debug: Splitting markup on page breaks and flow limits, if any...
debug:  Looking for large trees in pillow.html...
debug:  No large trees found
debug:  Looking for large trees in baidu_ocr.html...
debug:  Found large tree #0
debug: Python function terminated unexpectedly: Could not find reasonable point at which to split: baidu_ocr.html Sub-tree size: 302 KB
错误依旧。
看来是参数没有从gitbook传递进去
去看看gitbook是否有其他机制允许参数传递进入ebook-convert
  gitbook --help   

  Usage: gitbook [options] [command]

  Options:
    -v, --gitbook [version]  specify GitBook version to use
    -d, --debug              enable verbose error
    -V, --version            Display running versions of gitbook and gitbook-cli
    -h, --help               output usage information

  Commands:
    ls                        List versions installed locally
    current                   Display currently activated version
    ls-remote                 List remote versions available for install
    fetch [version]           Download and install a <version>
    alias [folder] [version]  Set an alias named <version> pointing to <folder>
    uninstall [version]       Uninstall a version
    update [tag]              Update to the latest version of GitBook
    help                      List commands for GitBook
    *                         run a command with a specific gitbook version
没有。
去试试:
 gitbook epub --help
info: 24 plugins are installed 
info: 19 explicitly listed 
info: loading plugin "anchors"… OK 
。。。
结果不是输出help,而是直接编译了。。。
ebook-convert — calibre 4.20.0 documentation
 xxx@xxx  ~  which gitbook
/usr/local/bin/gitbook
 xxx@xx  ~  open /usr/local/bin/
打开看到是
gitbook是个软链接
以及内部是个js
  ~  ll /usr/local/bin/gitbook
lrwxr-xr-x  1 xxx  admin    46B  3 17 09:21 /usr/local/bin/gitbook -> ../lib/node_modules/gitbook-cli/bin/gitbook.js
和:
~  ll /usr/local/lib/node_modules/gitbook-cli
total 24
-rw-r--r--   1 xxx  admin   2.0K  7 11  2017 README.md
-rw-r--r--   1 xxx  admin   580B  7 11  2017 appveyor.yml
drwxr-xr-x   3 xxx  admin    96B  3 17 09:21 bin
drwxr-xr-x   8 xxx  admin   256B  3 17 09:21 lib
drwxr-xr-x  21 xxx  admin   672B  3 17 09:21 node_modules
-rw-r--r--   1 xxx  admin   1.9K  3 17 09:21 package.json
drwxr-xr-x   6 xxx  admin   192B  3 17 09:21 test
另外去尝试看看js,能否加上参数
用VSCode打开了:
/usr/local/lib/node_modules/gitbook-cli
但是里面找不到
ebook-convert
ebook
去找epub,也找不到。
本来想去看看:
 ll ~/.gitbook
total 0
drwxr-xr-x  3 xxx  1748468295    96B  3 17 09:22 versions
是否有什么配置的。
结果发现是个文件夹:
  cat ~/.gitbook/versions
cat: /Users/xxx/.gitbook/versions: Is a directory
~  cat ~/.gitbook/versions/3.2.3/AUTHORS.md
AUTHORS.md     LICENSE        appveyor.yml   book.js        lib/           package.json   testing/
CHANGES.md     README.md      bin/           docs/          node_modules/  preview.png
所以也去打开看看
open ~/.gitbook/versions/3.2.3
用VSCode打开
是可以找到的
ebook-convert
/Users/xxx/.gitbook/versions/3.2.3/lib/output/ebook/getConvertOptions.js
也看到调试期间log对应源码了:
    return Promise()
    .then(function() {
        var coverPath = getCoverPath(output);
        var options = {
            '--cover':                      coverPath,
            '--title':                      config.getValue('title'),
            '--comments':                   config.getValue('description'),
            '--isbn':                       config.getValue('isbn'),
            '--authors':                    config.getValue('author'),
            '--language':                   book.getLanguage() || config.getValue('language'),
            '--book-producer':              'GitBook',
            '--publisher':                  'GitBook',
            '--chapter':                    'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter \')]',
            '--level1-toc':                 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-1 \')]',
            '--level2-toc':                 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-2 \')]',
            '--level3-toc':                 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-3 \')]',
            '--max-levels':                 '1',
            '--no-chapters-in-toc':         true,
            '--breadth-first':              true,
            '--dont-split-on-page-breaks':  format === 'epub'? true : undefined
        };
感觉可以去加上参数了。
找找加到哪里。
/Users/xxx/.gitbook/versions/3.2.3/lib/output/ebook/getConvertOptions.js
    return Promise()
    .then(function() {
        var coverPath = getCoverPath(output);
        var options = {
。。。
            '--dont-split-on-page-breaks':  format === 'epub'? true : undefined
        };


        if (format === 'epub') {
            options["--flow-size"] = '512' // default 260KB, change to 512KB to allow bigger content
        }
去运行试试效果
去调试:
make epub
看到输出中有:
debug: calling hook "page" 
debug: calling hook "finish:before" 
debug: Conversion options changed from defaults:
  publisher: u'GitBook'
  authors: u'Crifan Li <xxx>'
debug:   flow_size: 512.0
  language: u'zh-hans'
说明参数加对地方了
debug:  Looking for large trees in baidu_ocr.html...
debug:  No large trees found
就没有报错了。
然后再回去
make deploy
结果:也就正常了:
【总结】
此处自己的gitbook中去make deploy,内部调用了gitbook命令去生成epub文件,结果期间报错:
        Looking for large trees in baidu_ocr.html...
        Found large tree #0
Python function terminated unexpectedly: Could not find reasonable point at which to split: baidu_ocr.html Sub-tree size: 302 KB
原因:此处要生成的baidu_ocr.html的大小是302KB,超过了默认的260KB的split size
注:260KB的split的size是Adobe的pdf的默认配置。
解决办法:给ebook-convert添加参数增加此值,比如增大到512KB
ebook-convert book.mobi book.epub --flow-size 512
特殊:
此处用的是gitbook,其内部调用到ebook-convert,没有办法直接传入此ebook-convert的参数
所以只能找到gitbook的源码
gitbook安装目录中的lib/output/ebook/getConvertOptions.js
此处是:
/Users/xxx/.gitbook/versions/3.2.3/lib/output/ebook/getConvertOptions.js
给getConvertOptions中添加:
        if (format === 'epub') {
            options["--flow-size"] = '512' // default 260KB, change to 512KB to allow bigger content
        }
如图:
即可。
之后gitbook即可用到此参数
其中(加了debug后)输出log中会看到
debug:   flow_size: 512.0
后续:
debug:  Looking for large trees in baidu_ocr.html...
debug:  No large trees found
就不会报超过大小限制的错了。

转载请注明:在路上 » 【已解决】crifan的gitbook的模板make deploy出错:Could not find reasonable point at which to split Sub-tree size KB

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.174 seconds, using 22.16MB memory