Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
 def as_html(self):
     return markdown(self.content)
Ejemplo n.º 5
0
 def summary_as_html(self):
     return markdown(self.summary)
Ejemplo n.º 6
0
 def as_html(self):
     from website.templatetags.govtrack_utils import markdown
     return markdown(self.text)
Ejemplo n.º 7
0
 def as_html(self):
     return markdown(self.content)
Ejemplo n.º 8
0
 def summary_as_html(self):
     return markdown(self.summary)