feat(docparser): enhance image resolution capabilities in markdown and HTML
- Updated regex patterns in MarkdownImageUtil to support alt text containing brackets and handle MIME types with hyphens. - Implemented new functions in ImageResolver for resolving HTML <img> tags with data URIs and bare base64 content, improving image handling in markdown. - Added comprehensive tests for various image scenarios, ensuring robust handling of data URIs and base64 images.
This commit is contained in:
@@ -177,13 +177,15 @@ class MarkdownImageUtil:
|
||||
def __init__(self):
|
||||
# Pattern to match base64 embedded images
|
||||
# Captures: (1) alt text, (2) image format, (3) base64 data
|
||||
# Alt text uses .*? (non-greedy) to allow literal ] (e.g. Windows paths).
|
||||
# MIME subtype uses [^;]+ to handle types with hyphens like x-emf.
|
||||
self.b64_pattern = re.compile(
|
||||
r"!\[([^\]]*)\]\(data:image/(\w+)\+?\w*;base64,([^\)]+)\)"
|
||||
r"!\[(.*?)\]\(data:image/([^;]+);base64,([^\)]+)\)"
|
||||
)
|
||||
# Pattern to match regular image syntax
|
||||
self.image_pattern = re.compile(r"!\[([^\]]*)\]\(([^)]+)\)")
|
||||
# Pattern to match regular image syntax (alt text allows ])
|
||||
self.image_pattern = re.compile(r"!\[(.*?)\]\(([^)]+)\)")
|
||||
# Pattern for replacing image paths
|
||||
self.replace_pattern = re.compile(r"!\[([^\]]*)\]\(([^)]+)\)")
|
||||
self.replace_pattern = re.compile(r"!\[(.*?)\]\(([^)]+)\)")
|
||||
|
||||
def extract_image(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user