def narrative_as_html(self): # Demote headings. narrative = markdown(self.narrative) narrative = re.sub(r"(</?[Hh])(\d)(>)", lambda m : m.group(1) + str(int(m.group(2))+2) + m.group(3), narrative) return narrative
def load_announcement(template_path, testing): # Load the Markdown template for the current blast. templ = get_template(template_path) # Get the text-only body content, which also includes some email metadata. # Replace Markdown-style [text][href] links with the text plus bracketed href. ctx = { "format": "text", "utm": "" } body_text = templ.render(ctx).strip() body_text = re.sub(r"\[(.*?)\]\((.*?)\)", r"\1 at \2", body_text) # The top of the text content contains metadata in YAML format, # with "id" and "subject" required and active: true or rundate set to today's date in ISO format. meta_info, body_text = body_text.split("----------", 1) body_text = body_text.strip() meta_info = yaml.load(meta_info) # Under what cases do we use this announcement? if meta_info.get("active"): pass # active is set to something truthy elif meta_info.get("rundate") == launch_time.date().isoformat(): pass # rundate matches date this job was started elif "rundate" in meta_info and testing: pass # when testing ignore the actual date set else: # the announcement file is inactive/stale return None # Get the HTML body content. ctx = { "format": "html", "utm": "", } body_html = templ.render(ctx).strip() body_html = markdown(body_html) # Store everything in meta_info. meta_info["body_text"] = body_text meta_info["body_html"] = body_html return meta_info
def as_html(self): return markdown(self.content)
def summary_as_html(self): return markdown(self.summary)
def as_html(self): from website.templatetags.govtrack_utils import markdown return markdown(self.text)