mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
...
This commit is contained in:
parent
2a15d7fa57
commit
812cf96bc5
@ -109,10 +109,11 @@ def parse_cnt(cnt):
|
|||||||
yield ''.join(parse_fmt_type(cnt))
|
yield ''.join(parse_fmt_type(cnt))
|
||||||
else:
|
else:
|
||||||
for cnt_ in cnt[k]:
|
for cnt_ in cnt[k]:
|
||||||
yield from parse_types(cnt_)
|
yield ''.join(parse_types(cnt_))
|
||||||
if isinstance(cnt[k], dict):
|
if isinstance(cnt[k], dict):
|
||||||
yield from parse_types(cnt[k])
|
yield ''.join(parse_types(cnt[k]))
|
||||||
if cnt.get('text') and 'formats' not in cnt:
|
if cnt.get('text') and 'formats' not in cnt and 'content' not in cnt:
|
||||||
|
if isinstance(cnt['text'], str):
|
||||||
yield cnt['text']
|
yield cnt['text']
|
||||||
|
|
||||||
def parse_types(x):
|
def parse_types(x):
|
||||||
@ -141,9 +142,6 @@ def parse_types(x):
|
|||||||
elif typename == 'RuleBlock':
|
elif typename == 'RuleBlock':
|
||||||
yield '<hr/>'
|
yield '<hr/>'
|
||||||
|
|
||||||
elif typename in {'ImageBlock', 'VideoBlock', 'InteractiveBlock'}:
|
|
||||||
yield "".join(parse_types(x['media']))
|
|
||||||
|
|
||||||
elif typename == 'Image':
|
elif typename == 'Image':
|
||||||
yield "".join(parse_image(x))
|
yield "".join(parse_image(x))
|
||||||
|
|
||||||
@ -161,24 +159,16 @@ def parse_types(x):
|
|||||||
elif typename == 'ListItemBlock':
|
elif typename == 'ListItemBlock':
|
||||||
yield f'<li>{"".join(parse_cnt(x))}</li>'
|
yield f'<li>{"".join(parse_cnt(x))}</li>'
|
||||||
|
|
||||||
elif typename == 'CapsuleBlock':
|
elif typename == 'TextInline':
|
||||||
if x['capsuleContent'].get('body'):
|
|
||||||
yield "".join(parse_cnt(x['capsuleContent']['body']))
|
|
||||||
elif typename == 'Capsule':
|
|
||||||
yield "".join(parse_cnt(x['body']))
|
|
||||||
|
|
||||||
elif typename in {
|
|
||||||
'TextInline', 'TextOnlyDocumentBlock', 'DocumentBlock',
|
|
||||||
'SummaryBlock', 'VisualStackBlock'
|
|
||||||
}:
|
|
||||||
yield "".join(parse_cnt(x))
|
yield "".join(parse_cnt(x))
|
||||||
|
|
||||||
elif typename and typename not in {'RelatedLinksBlock', 'Dropzone'}:
|
elif typename in {'DetailBlock', 'TextRunKV'}:
|
||||||
if x.get('media'):
|
|
||||||
yield "".join(parse_types(x['media']))
|
|
||||||
elif "".join(parse_cnt(x)).strip():
|
|
||||||
yield f'<p><i>{"".join(parse_cnt(x))}</i></p>'
|
yield f'<p><i>{"".join(parse_cnt(x))}</i></p>'
|
||||||
|
|
||||||
|
elif typename and typename not in {'RelatedLinksBlock', 'Dropzone'}:
|
||||||
|
if "".join(parse_cnt(x)).strip():
|
||||||
|
yield "".join(parse_cnt(x))
|
||||||
|
|
||||||
def article_parse(data):
|
def article_parse(data):
|
||||||
yield "<html><body>"
|
yield "<html><body>"
|
||||||
for d in data:
|
for d in data:
|
||||||
|
@ -9,7 +9,7 @@ from xml.sax.saxutils import escape, quoteattr
|
|||||||
|
|
||||||
from calibre.utils.iso8601 import parse_iso8601
|
from calibre.utils.iso8601 import parse_iso8601
|
||||||
|
|
||||||
module_version = 7 # needed for live updates
|
module_version = 8 # needed for live updates
|
||||||
pprint
|
pprint
|
||||||
|
|
||||||
|
|
||||||
@ -111,10 +111,11 @@ def parse_cnt(cnt):
|
|||||||
yield ''.join(parse_fmt_type(cnt))
|
yield ''.join(parse_fmt_type(cnt))
|
||||||
else:
|
else:
|
||||||
for cnt_ in cnt[k]:
|
for cnt_ in cnt[k]:
|
||||||
yield from parse_types(cnt_)
|
yield ''.join(parse_types(cnt_))
|
||||||
if isinstance(cnt[k], dict):
|
if isinstance(cnt[k], dict):
|
||||||
yield from parse_types(cnt[k])
|
yield ''.join(parse_types(cnt[k]))
|
||||||
if cnt.get('text') and 'formats' not in cnt:
|
if cnt.get('text') and 'formats' not in cnt and 'content' not in cnt:
|
||||||
|
if isinstance(cnt['text'], str):
|
||||||
yield cnt['text']
|
yield cnt['text']
|
||||||
|
|
||||||
def parse_types(x):
|
def parse_types(x):
|
||||||
@ -143,9 +144,6 @@ def parse_types(x):
|
|||||||
elif typename == 'RuleBlock':
|
elif typename == 'RuleBlock':
|
||||||
yield '<hr/>'
|
yield '<hr/>'
|
||||||
|
|
||||||
elif typename in {'ImageBlock', 'VideoBlock', 'InteractiveBlock'}:
|
|
||||||
yield "".join(parse_types(x['media']))
|
|
||||||
|
|
||||||
elif typename == 'Image':
|
elif typename == 'Image':
|
||||||
yield "".join(parse_image(x))
|
yield "".join(parse_image(x))
|
||||||
|
|
||||||
@ -161,26 +159,18 @@ def parse_types(x):
|
|||||||
elif typename == 'ListBlock':
|
elif typename == 'ListBlock':
|
||||||
yield f'<ul>{"".join(parse_cnt(x))}</ul>'
|
yield f'<ul>{"".join(parse_cnt(x))}</ul>'
|
||||||
elif typename == 'ListItemBlock':
|
elif typename == 'ListItemBlock':
|
||||||
yield f'<li>{"".join(parse_cnt(x))}</li>'
|
yield f'\n<li>{"".join(parse_cnt(x))}</li>'
|
||||||
|
|
||||||
elif typename == 'CapsuleBlock':
|
elif typename == 'TextInline':
|
||||||
if x['capsuleContent'].get('body'):
|
|
||||||
yield "".join(parse_cnt(x['capsuleContent']['body']))
|
|
||||||
elif typename == 'Capsule':
|
|
||||||
yield "".join(parse_cnt(x['body']))
|
|
||||||
|
|
||||||
elif typename in {
|
|
||||||
'TextInline', 'TextOnlyDocumentBlock', 'DocumentBlock',
|
|
||||||
'SummaryBlock', 'VisualStackBlock'
|
|
||||||
}:
|
|
||||||
yield "".join(parse_cnt(x))
|
yield "".join(parse_cnt(x))
|
||||||
|
|
||||||
elif typename and typename not in {'RelatedLinksBlock', 'Dropzone'}:
|
elif typename in {'DetailBlock', 'TextRunKV'}:
|
||||||
if x.get('media'):
|
|
||||||
yield "".join(parse_types(x['media']))
|
|
||||||
elif "".join(parse_cnt(x)).strip():
|
|
||||||
yield f'<p><i>{"".join(parse_cnt(x))}</i></p>'
|
yield f'<p><i>{"".join(parse_cnt(x))}</i></p>'
|
||||||
|
|
||||||
|
elif typename and typename not in {'RelatedLinksBlock', 'Dropzone'}:
|
||||||
|
if "".join(parse_cnt(x)).strip():
|
||||||
|
yield "".join(parse_cnt(x))
|
||||||
|
|
||||||
def article_parse(data):
|
def article_parse(data):
|
||||||
yield "<html><body>"
|
yield "<html><body>"
|
||||||
for d in data:
|
for d in data:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user