GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixed #33 - Implement new API for Plugins · 06linux/ebooklib@401c0db

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • ebooklib
    • epub.py
    • plugins
      • base.py
      • booktype.py
      • sourcecode.py
      • standard.py
  • samples/05_plugins_create
    • create.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎ebooklib/epub.py‎

Copy file name to clipboardExpand all lines: ebooklib/epub.py
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,15 @@ def __init__(self, name, book, options = None):
449449

450450
def process(self):
451451
# should cache this html parsing so we don't do it for every plugin
452+
for plg in self.options.get('plugins', []):
453+
if hasattr(plg, 'before_write'):
454+
plg.before_write(self.book)
455+
452456
for item in self.book.get_items():
453457
if isinstance(item, EpubHtml):
454458
for plg in self.options.get('plugins', []):
455-
if hasattr(plg, 'process_html'):
456-
plg.process_html(self.book, item)
459+
if hasattr(plg, 'html_before_write'):
460+
plg.html_before_write(self.book, item)
457461

458462
def _write_container(self):
459463
self.out.writestr(CONTAINER_PATH, CONTAINER_XML)
Collapse file

‎ebooklib/plugins/base.py‎

Copy file name to clipboardExpand all lines: ebooklib/plugins/base.py
+23-3Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,34 @@
1616

1717

1818
class BasePlugin(object):
19-
def before_processing(self, book):
19+
def before_write(self, book):
2020
"Processing before save"
2121
return True
2222

23-
def after_processing(self, book):
23+
def after_write(self, book):
2424
"Processing after save"
2525
return True
2626

27-
def process_html(self, book, chapter):
27+
def before_read(self, book):
28+
"Processing before save"
29+
return True
30+
31+
def after_read(self, book):
32+
"Processing after save"
33+
return True
34+
35+
def item_after_read(self, book, item):
36+
"Process general item after read."
37+
return True
38+
39+
def item_before_write(self, book, item):
40+
"Process general item before write."
41+
return True
42+
43+
def html_after_read(self, book, chapter):
44+
"Processing HTML before read."
45+
return True
46+
47+
def html_before_write(self, book, chapter):
2848
"Processing HTML before save."
2949
return True
Collapse file

‎ebooklib/plugins/booktype.py‎

Copy file name to clipboardExpand all lines: ebooklib/plugins/booktype.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BooktypeLinks(BasePlugin):
2323
def __init__(self, booktype_book):
2424
self.booktype_book = booktype_book
2525

26-
def process_html(self, book, chapter):
26+
def html_before_write(self, book, chapter):
2727
from lxml import etree
2828

2929
try:
@@ -80,7 +80,7 @@ class BooktypeFootnotes(BasePlugin):
8080
def __init__(self, booktype_book):
8181
self.booktype_book = booktype_book
8282

83-
def process_html(self, book, chapter):
83+
def html_before_write(self, book, chapter):
8484
from lxml import etree
8585

8686
from ebooklib import epub
Collapse file

‎ebooklib/plugins/sourcecode.py‎

Copy file name to clipboardExpand all lines: ebooklib/plugins/sourcecode.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SourceHighlighter(BasePlugin):
2121
def __init__(self):
2222
pass
2323

24-
def process_html(self, book, chapter):
24+
def html_before_write(self, book, chapter):
2525
from lxml import etree, html
2626

2727
from pygments import highlight
Collapse file

‎ebooklib/plugins/standard.py‎

Copy file name to clipboardExpand all lines: ebooklib/plugins/standard.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def leave_only(item, tag_list):
4141
class SyntaxPlugin(BasePlugin):
4242
NAME = 'Check HTML syntax'
4343

44-
def process_html(self, book, chapter):
44+
def html_before_write(self, book, chapter):
4545
from lxml import etree
4646

4747
try:
Collapse file

‎samples/05_plugins_create/create.py‎

Copy file name to clipboardExpand all lines: samples/05_plugins_create/create.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SamplePlugin(BasePlugin):
77
NAME = 'Sample Plugin'
88

99
# Very useless but example of what can be done
10-
def process_html(self, book, chapter):
10+
def html_before_write(self, book, chapter):
1111
from urlparse import urlparse, urljoin
1212

1313
from lxml import html, etree

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.