Esempio n. 1
0
 def render_note(self, note):
     etitle = escape_html(note.title)
     self.output.write(f"<article><header><h3>{etitle}</h3></header>")
     self.output.write(f"<aside>(Page {note.page_number})</aside>")
     for paragraph in note.content.splitlines():
         eparagraph = escape_html(paragraph)
         self.output.write(f"<p>{eparagraph}</p>")
     self.output.write("<footer>End of section</footer></article>")
Esempio n. 2
0
 def start_document(self):
     title = {}
     if self.book is not None:
         title[_("Book")] = escape_html(self.book)
     if self.section:
         title[_("Section")] = escape_html(self.section)
     if self.tag:
         title[_("Tag")] = escape_html("# " + self.tag)
     html_title = " — ".join(t.strip() for t in title.values() if t.strip())
     self.output.write("<!doctype html>\n"
                       "<html>\n<head>\n"
                       '<meta charset="UTF-8">\n'
                       f"<title>{html_title}</title>\n"
                       "</head>\n<body>\n")
     self.output.write("<h1>" + _("Exported Annotations") + "</h1>\n")
     for label, value in title.items():
         self.output.write(f"<h2>{label}: {value}</h2>\n")
Esempio n. 3
0
 def start_document(self):
     etitle = escape_html(self.title)
     head = ("<!doctype html>"
             "<html><head>"
             f"<title>Notes — {etitle}</title>"
             "</head><body>"
             f"<h1>Notes for {etitle}</h1>")
     self.output.write(head)
Esempio n. 4
0
 def make_proper_html(cls, html_string, docx_file_path):
     parsed = HTMLParser(html_string)
     parsed.body.unwrap_tags(TAGS_TO_UNWRAP)
     parsed.strip_tags(TAGS_TO_REMOVE)
     html_string = parsed.body.html
     docx = DocxDocumentReader(docx_file_path)
     props = docx.core_properties
     doc_title = props.title.strip()
     if not doc_title or doc_title.lower() == "word document":
         doc_title = docx_file_path.stem.strip()
     doc_author = escape_html(props.author or "")
     return NEWLINE.join([
         "<!DOCTYPE html>",
         "<html>",
         "<head>",
         '<meta charset="utf-8"/>',
         f'<meta name="author" content="{doc_author}"/>',
         f"<title>{escape_html(doc_title)}</title>",
         "</head>",
         html_string,
         "</html>",
     ])
Esempio n. 5
0
 def start_section(self, title):
     etitle = escape_html(title)
     self.output.write(f"<section><h2>{etitle}</h2>")