.format() to f-string from previous PR

This commit is contained in:
Kovid Goyal 2025-01-28 23:52:11 +05:30
parent 9c5e88c332
commit 0b4a3a8661
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -80,7 +80,7 @@ def remove_kindlegen_markup(parts, aid_anchor_suffix, linked_aids):
aid = None aid = None
replacement = '' replacement = ''
if aid in linked_aids: if aid in linked_aids:
replacement = ' id="{}"'.format(aid + '-' + aid_anchor_suffix) replacement = f' id="{aid + "-" + aid_anchor_suffix}"'
tag = within_tag_aid_position_pattern.sub(replacement, tag, 1) tag = within_tag_aid_position_pattern.sub(replacement, tag, 1)
srcpieces[j] = tag srcpieces[j] = tag
part = ''.join(srcpieces) part = ''.join(srcpieces)
@ -150,7 +150,7 @@ def update_flow_links(mobi8_reader, resource_map, log):
num = int(m.group(1), 32) num = int(m.group(1), 32)
href = resource_map[num-1] href = resource_map[num-1]
if href: if href:
replacement = '"{}"'.format('../'+ href) replacement = f'"{"../"+ href}"'
tag = img_index_pattern.sub(replacement, tag, 1) tag = img_index_pattern.sub(replacement, tag, 1)
else: else:
log.warn(f'Referenced image {num} was not recognized ' log.warn(f'Referenced image {num} was not recognized '
@ -168,7 +168,7 @@ def update_flow_links(mobi8_reader, resource_map, log):
num = int(m.group(1), 32) num = int(m.group(1), 32)
href = resource_map[num-1] href = resource_map[num-1]
if href: if href:
replacement = '"{}"'.format('../'+ href) replacement = f'"{"../"+ href}"'
tag = url_img_index_pattern.sub(replacement, tag, 1) tag = url_img_index_pattern.sub(replacement, tag, 1)
else: else:
log.warn(f'Referenced image {num} was not recognized as a ' log.warn(f'Referenced image {num} was not recognized as a '
@ -182,9 +182,9 @@ def update_flow_links(mobi8_reader, resource_map, log):
log.warn(f'Referenced font {num} was not recognized as a ' log.warn(f'Referenced font {num} was not recognized as a '
f'valid font in {tag}') f'valid font in {tag}')
else: else:
replacement = '"{}"'.format('../'+ href) replacement = f'"{"../"+ href}"'
if href.endswith('.failed'): if href.endswith('.failed'):
replacement = '"{}"'.format('failed-'+href) replacement = f'"{"failed-"+href}"'
tag = font_index_pattern.sub(replacement, tag, 1) tag = font_index_pattern.sub(replacement, tag, 1)
# process links to other css pieces # process links to other css pieces
@ -280,7 +280,7 @@ def insert_images_into_markup(parts, resource_map, log):
except IndexError: except IndexError:
href = '' href = ''
if href: if href:
replacement = '"{}"'.format('../' + href) replacement = f'"{"../" + href}"'
tag = img_index_pattern.sub(replacement, tag, 1) tag = img_index_pattern.sub(replacement, tag, 1)
else: else:
log.warn(f'Referenced image {num} was not recognized as ' log.warn(f'Referenced image {num} was not recognized as '