def add_line_wrappers(data_passed_from_pelican):
 if data_passed_from_pelican._content:
  full_content_of_page_or_post = data_passed_from_pelican._content
 else:
  return
 all_instances_of_pre_elements = re.findall('<pre>.*?</pre>', full_content_of_page_or_post, re.DOTALL)
 if (len(all_instances_of_pre_elements) > 0):
  updated_full_content_of_page_or_post = full_content_of_page_or_post
  for pre_element_to_parse in all_instances_of_pre_elements:
   replacement_text_with_beginning_of_each_line_wrapped_in_span = re.sub('(<pre.*?>|\\n(?!</pre>))', '\\1<span class="code-line">', pre_element_to_parse)
   replacement_text_with_full_line_wrapped_in_span = re.sub('((?<!</pre>)$|(?<!</pre>)\\n)', '</span>\\1', replacement_text_with_beginning_of_each_line_wrapped_in_span)
   updated_full_content_of_page_or_post = updated_full_content_of_page_or_post.replace(pre_element_to_parse, replacement_text_with_full_line_wrapped_in_span)
  data_passed_from_pelican._content = updated_full_content_of_page_or_post

def add_line_wrappers ( data_passed_from_pelican ) : if data_passed_from_pelican . _content : full_content_of_page_or_post = data_passed_from_pelican . _content else : return all_instances_of_pre_elements = re . findall ( '<pre>.*?</pre>' , full_content_of_page_or_post , re . DOTALL ) if ( len ( all_instances_of_pre_elements ) > 0 ) : updated_full_content_of_page_or_post = full_content_of_page_or_post for pre_element_to_parse in all_instances_of_pre_elements : replacement_text_with_beginning_of_each_line_wrapped_in_span = re . sub ( '(<pre.*?>|\\n(?!</pre>))' , '\\1<span class="code-line">' , pre_element_to_parse ) replacement_text_with_full_line_wrapped_in_span = re . sub ( '((?<!</pre>)$|(?<!</pre>)\\n)' , '</span>\\1' , replacement_text_with_beginning_of_each_line_wrapped_in_span ) updated_full_content_of_page_or_post = updated_full_content_of_page_or_post . replace ( pre_element_to_parse , replacement_text_with_full_line_wrapped_in_span ) data_passed_from_pelican . _content = updated_full_content_of_page_or_post
a function to read through each page and post as it comes through from pelican .