Navigation Menu

Skip to content

Commit

Permalink
FixImagePaths Macro no longer tramples img attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamzap committed Jul 27, 2011
1 parent 2863ab5 commit e5d2649
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/landslide/macro.py
Expand Up @@ -93,7 +93,6 @@ class EmbedImagesMacro(Macro):
algorithm.
"""
def process(self, content, source=None):
print source
classes = []

if not self.embed:
Expand Down Expand Up @@ -131,11 +130,14 @@ def process(self, content, source=None):
return content, classes
base_path = utils.get_path_url(source, self.options.get('relative'))
base_url = os.path.split(base_path)[0]
fn = lambda p: r'<img src="%s" />' % os.path.join(base_url, p.group(1))

sub_regex = r'<img.*?src="(?!http://)(.*?)".*/?>'
images = re.findall(r'<img.*?src="(?!http://)(.*?)".*/?>', content,
re.DOTALL | re.UNICODE)

content = re.sub(sub_regex, fn, content, re.UNICODE)
for image in images:
full_path = os.path.join(base_url, image)

content = content.replace(image, full_path)

return content, classes

Expand Down

0 comments on commit e5d2649

Please sign in to comment.