@@ -39,10 +39,14 @@ def tex(lines, contact_lines, *args):
3939 python resume.py tex < resume.md
4040
4141"""
42+ import hashlib
4243import sys
4344import re
4445
4546
47+ GRAVATAR = "http://www.gravatar.com/avatar/{hash}?s=200"
48+
49+
4650class Processor (object ):
4751 handlers = {}
4852
@@ -81,15 +85,15 @@ def sub(pattern, repl, string, **kwargs):
8185
8286 return re .sub (pattern , r"\1\2%s\%d" % (repl , num_groups + 3 ), string ,
8387 flags = flags , ** kwargs )
84-
88+
8589 # pandoc doesn't seem to support markdown inside latex blocks, so we're
8690 # just going to hardcode the two most common link formats for now so people
8791 # can put links in their contact info
8892 def replace_links (line ):
8993 line = re .sub (r"<([^:]+@[^:]+?)>" , r"\href{mailto:\1}{\1}" , line )
9094 line = re .sub (r"<(http.+?)>" , r"\url{\1}" , line )
9195 return re .sub (r"\[([^\]]+)\]\(([^\)]+)\)" , r"\href{\2}{\1}" , line )
92-
96+
9397 contact_lines = "\n \n " .join (map (replace_links , contact_lines ))
9498
9599 # replacements to apply to the text in contact_lines, because it won't be
@@ -122,6 +126,15 @@ def html(lines, contact_lines, *args):
122126 lines = map (replace , lines )
123127 contact_lines = map (replace , contact_lines )
124128
129+ gravatar = None
130+ for line in contact_lines :
131+ if line .find ("@" ) > 0 :
132+ gravatar = GRAVATAR .format (
133+ hash = hashlib .md5 (line .lower ().strip ('<>' )).hexdigest ())
134+ break
135+ if gravatar is not None :
136+ contact_lines .insert (0 , "<img src='{}' />" .format (gravatar ))
137+
125138 lines .insert (0 , "<div id='container'><div id='contact'>%s</div>\n " %
126139 ("<p>" + "</p><p>" .join (contact_lines ) + "</p>" ))
127140 lines .insert (1 , "<div>" )
0 commit comments