mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port usage of BeautifulSoup Tag constructor
This commit is contained in:
parent
692230147c
commit
c89b656df4
@ -201,7 +201,7 @@ class KINDLE(USBMS):
|
||||
return bookmarked_books
|
||||
|
||||
def generate_annotation_html(self, bookmark):
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||
# Returns <div class="user_annotations"> ... </div>
|
||||
last_read_location = bookmark.last_read_location
|
||||
timestamp = datetime.datetime.utcfromtimestamp(bookmark.timestamp)
|
||||
@ -209,11 +209,11 @@ class KINDLE(USBMS):
|
||||
|
||||
ka_soup = BeautifulSoup()
|
||||
dtc = 0
|
||||
divTag = Tag(ka_soup,'div')
|
||||
divTag = ka_soup.new_tag('div')
|
||||
divTag['class'] = 'user_annotations'
|
||||
|
||||
# Add the last-read location
|
||||
spanTag = Tag(ka_soup, 'span')
|
||||
spanTag = ka_soup.new_tag('span')
|
||||
spanTag['style'] = 'font-weight:bold'
|
||||
if bookmark.book_format == 'pdf':
|
||||
spanTag.insert(0,BeautifulSoup(
|
||||
@ -230,7 +230,7 @@ class KINDLE(USBMS):
|
||||
|
||||
divTag.insert(dtc, spanTag)
|
||||
dtc += 1
|
||||
divTag.insert(dtc, Tag(ka_soup,'br'))
|
||||
divTag.insert(dtc, ka_soup.new_tag('br'))
|
||||
dtc += 1
|
||||
|
||||
if bookmark.user_notes:
|
||||
@ -268,7 +268,6 @@ class KINDLE(USBMS):
|
||||
return ka_soup
|
||||
|
||||
def add_annotation_to_library(self, db, db_id, annotation):
|
||||
from calibre.ebooks.BeautifulSoup import Tag
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
|
||||
bm = annotation
|
||||
@ -288,7 +287,7 @@ class KINDLE(USBMS):
|
||||
if set(mi.tags).intersection(ignore_tags):
|
||||
return
|
||||
if mi.comments:
|
||||
hrTag = Tag(user_notes_soup,'hr')
|
||||
hrTag = user_notes_soup.new_tag('hr')
|
||||
hrTag['class'] = 'annotations_divider'
|
||||
user_notes_soup.insert(0, hrTag)
|
||||
|
||||
|
@ -1194,7 +1194,7 @@ class KOBO(USBMS):
|
||||
|
||||
def generate_annotation_html(self, bookmark):
|
||||
import calendar
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
||||
# Returns <div class="user_annotations"> ... </div>
|
||||
# last_read_location = bookmark.last_read_location
|
||||
# timestamp = bookmark.timestamp
|
||||
@ -1218,11 +1218,11 @@ class KOBO(USBMS):
|
||||
# debug_print("Percent read: ", percent_read)
|
||||
ka_soup = BeautifulSoup()
|
||||
dtc = 0
|
||||
divTag = Tag(ka_soup,'div')
|
||||
divTag = ka_soup.new_tag('div')
|
||||
divTag['class'] = 'user_annotations'
|
||||
|
||||
# Add the last-read location
|
||||
spanTag = Tag(ka_soup, 'span')
|
||||
spanTag = ka_soup.new_tag('span')
|
||||
spanTag['style'] = 'font-weight:normal'
|
||||
if bookmark.book_format == 'epub':
|
||||
spanTag.insert(0,BeautifulSoup(
|
||||
@ -1239,7 +1239,7 @@ class KOBO(USBMS):
|
||||
|
||||
divTag.insert(dtc, spanTag)
|
||||
dtc += 1
|
||||
divTag.insert(dtc, Tag(ka_soup,'br'))
|
||||
divTag.insert(dtc, ka_soup.new_tag('br'))
|
||||
dtc += 1
|
||||
|
||||
if bookmark.user_notes:
|
||||
@ -1301,7 +1301,6 @@ class KOBO(USBMS):
|
||||
return ka_soup
|
||||
|
||||
def add_annotation_to_library(self, db, db_id, annotation):
|
||||
from calibre.ebooks.BeautifulSoup import Tag
|
||||
bm = annotation
|
||||
ignore_tags = {'Catalog', 'Clippings'}
|
||||
|
||||
@ -1320,7 +1319,7 @@ class KOBO(USBMS):
|
||||
if set(mi.tags).intersection(ignore_tags):
|
||||
return
|
||||
if mi.comments:
|
||||
hrTag = Tag(user_notes_soup,'hr')
|
||||
hrTag = user_notes_soup.new_tag('hr')
|
||||
hrTag['class'] = 'annotations_divider'
|
||||
user_notes_soup.insert(0, hrTag)
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
|
||||
import re
|
||||
|
||||
from calibre.constants import preferred_encoding
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag, NavigableString, \
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, NavigableString, \
|
||||
CData, Comment, Declaration, ProcessingInstruction
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.utils.html2text import html2text
|
||||
@ -95,20 +95,20 @@ def comments_to_html(comments):
|
||||
|
||||
all_tokens = list(soup.contents)
|
||||
for token in all_tokens:
|
||||
if type(token) is NavigableString:
|
||||
if isinstance(token, NavigableString):
|
||||
if not open_pTag:
|
||||
pTag = Tag(result,'p')
|
||||
pTag = result.new_tag('p')
|
||||
open_pTag = True
|
||||
ptc = 0
|
||||
pTag.insert(ptc,prepare_string_for_xml(token))
|
||||
ptc += 1
|
||||
elif type(token) in (CData, Comment, Declaration,
|
||||
ProcessingInstruction):
|
||||
elif isinstance(token, (CData, Comment, Declaration,
|
||||
ProcessingInstruction)):
|
||||
continue
|
||||
elif token.name in ['br', 'b', 'i', 'em', 'strong', 'span', 'font', 'a',
|
||||
'hr']:
|
||||
if not open_pTag:
|
||||
pTag = Tag(result,'p')
|
||||
pTag = result.new_tag('p')
|
||||
open_pTag = True
|
||||
ptc = 0
|
||||
pTag.insert(ptc, token)
|
||||
|
Loading…
x
Reference in New Issue
Block a user