Esempio n. 1
0
 def test_basic_quote(self):
     expected_output = self.load_md("basic_quote")
     quotebox = md.MarkdownQuotebox()
     quotebox.add(md.MarkdownParagraph("The text of paragraph 1"))
     para = md.MarkdownParagraph()
     para.add("Some text before ")
     para.add(md.MarkdownStrong("the strong text"))
     quotebox.add(para)
     self.assertEqual(expected_output, str(quotebox))
Esempio n. 2
0
 def test_quoted_code_fence(self):
     expected_output = self.load_md("quoted_code_fence")
     qcf = md.MarkdownDocument()
     qcf.add(md.MarkdownParagraph("Outside quotes!"))
     quote = md.MarkdownQuotebox()
     code = md.MarkdownCodeBlock("int x = 5\nx++\n")
     quote.add(code)
     quote.add(md.MarkdownParagraph("Below the code fence"))
     qcf.add(quote)
     self.assertEqual(expected_output, str(qcf))
Esempio n. 3
0
 def test_nested_quotes(self):
     expected_output = self.load_md("nested_quote2")
     quotebox = md.MarkdownQuotebox()
     quotebox.add(md.MarkdownParagraph("Paragraph 1"))
     nested_quotebox = md.MarkdownQuotebox()
     nested_quotebox.add(md.MarkdownParagraph("Paragraph 2 (nested)"))
     quotebox.add(nested_quotebox)
     quotebox.add(md.MarkdownParagraph("Paragraph 3"))
     self.assertEqual(expected_output, str(quotebox))
     expected_output = self.load_md("nested_quote3")
     level_0 = md.MarkdownDocument()
     level_1 = md.MarkdownQuotebox()
     level_2 = md.MarkdownQuotebox()
     level_3 = md.MarkdownQuotebox()
     level_0.add(md.MarkdownParagraph("Outside quotes!"))
     level_1.add(md.MarkdownParagraph("First level"))
     level_2.add(md.MarkdownParagraph("Second level"))
     level_3.add(md.MarkdownParagraph("Third level"))
     level_0.add(level_1)
     level_1.add(level_2)
     level_2.add(level_3)
     level_1.add(md.MarkdownParagraph("Back on the first level"))
     level_0.add(
         md.MarkdownLink("Link at the end of the document",
                         "https://nowhere.com"))
     self.assertEqual(expected_output, str(level_0))
Esempio n. 4
0
 def test_list_whitespace(self):
     expected_output = self.load_md("list_whitespace")
     doc = md.MarkdownDocument()
     doc.add(md.MarkdownListItem("List item 1"))
     doc.add(md.MarkdownListItem("List item 2"))
     doc.add(md.MarkdownParagraph("proceeding paragraph"))
     self.assertEqual(expected_output, str(doc))
Esempio n. 5
0
 def test_paragraphs_with_inline(self):
     expected_output = self.load_md("paragraphs_with_inline")
     para = md.MarkdownParagraph()
     para.add("Starting text ")
     para.add(md.MarkdownStrong("followed by strong text "))
     para.add(md.MarkdownItalics("followed by italics "))
     para.add("followed by normal text.")
     self.assertEqual(expected_output, str(para))
Esempio n. 6
0
 def test_basic(self):
     expected_output = self.load_md("basic")
     doc = md.MarkdownDocument()
     doc.add(
         md.MarkdownParagraph("some words follow by more words after them"))
     self.assertEqual(expected_output, str(doc))
Esempio n. 7
0
 def test_paragraphs(self):
     expected_output = self.load_md("paragraphs")
     doc = md.MarkdownDocument()
     doc.add(md.MarkdownParagraph("This is paragraph number 1"))
     doc.add(md.MarkdownParagraph("This is paragraph number 2"))
     self.assertEqual(expected_output, str(doc))
Esempio n. 8
0
def convert_tag(tag):
    content_inside_this_tag = process_tag(tag)
    # tags that don't auto insert newline are processed first
    if tag.name == "a" and tag.has_attr("href"):
        return md.MarkdownLink(content_inside_this_tag, tag["href"])
    elif tag.name == "a":
        return content_inside_this_tag
    # these can be handled the same as far as I can tell
    elif tag.name == "code" or tag.name == "pre":
        return process_code(tag)
    elif tag.name == "strong":
        return process_strong(content_inside_this_tag)
    elif tag.name == "span":
        return content_inside_this_tag
    elif tag.name == "em":
        return process_italics(content_inside_this_tag)
    elif tag.name == "img":
        return process_img(tag)
    elif tag.name == "table":
        return process_table(tag)
    elif tag.name == "ul":
        temp = ITEM_SEPARATOR + content_inside_this_tag
        if len(temp) > 2 and temp[-2:] != "\n\n":
            temp += "\n"
        return temp
    elif tag.name == "br":
        return "\n\n"
    elif is_excluded_tag(tag):
        return ""

    # tags below here insert a newline if not already inserted by previous call to convert_tag
    if tag.name == "p":
        output = md.MarkdownParagraph(content_inside_this_tag)
    elif tag.name == "div":
        output = md.MarkdownParagraph(content_inside_this_tag)
    elif tag.name == "h2":
        output = md.MarkdownHeader(content_inside_this_tag, 2)
    elif tag.name == "h3":
        output = md.MarkdownHeader(content_inside_this_tag, 3)
    elif tag.name == "li":
        output = md.MarkdownListItem(content_inside_this_tag)
    elif tag.name == "blockquote":
        output = process_quote_box(tag, content_inside_this_tag)
    elif tag.name == "iframe":
        output = process_iframe(tag)
    elif tag.name == "video":
        if tag.has_attr("src"):
            output = str(md.MarkdownLink("Embedded Video",
                                         tag["src"])) + ITEM_SEPARATOR
        elif tag.children is not None and tag.find("source").has_attr("src"):
            output = str(
                md.MarkdownLink("Embedded Video",
                                tag.find("source")["src"])) + ITEM_SEPARATOR
        else:
            output = md.MarkdownParagraph(content_inside_this_tag)
    else:
        # default case should be fine for remaining tags
        output = content_inside_this_tag
    #if isinstance(output, md.MarkdownQuotebox) and len(output.items) == 3 and "Level 1 Cast when" in output.items[0]:
    #    print(output.items)
    return output