コード例 #1
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test_unordered_list_elements(self):
        test = ("- first item\n"
                "second item\n")

        with self.assertRaises(markdown.FormatError) as err:
            markdown.convert(test)

        self.assertEqual(str(err.exception),
                         'Invalid line "second item" in an unordered list')
コード例 #2
0
def show(id):
    blog = ExecuteGetContent('SELECT * FROM blogs WHERE id = %s' % id)
    if not blog:
        return 'このアイテムはみつかりませんでした。'
    else:
        content = markdown.convert(blog[2])
        return template('admin/show.html', blog=blog, content=content)
コード例 #3
0
    def process_one(self, input_filename, markdown=None, templates=None, version="??"):
        if markdown is None:
            markdown = self.markdown
            markdown.reset()
        if templates is None:
            templates = self.templates
        output = []
        filter = self.filter_line
        with codecs.open(input_filename, "r", "utf-8") as f:
            lines = [l for l in unicode(f.read()).splitlines() if not filter(l)]
            if lines:
                md = self.parse_metadata(lines)
            output.append(markdown.convert(u"\n".join(lines)))
            del lines[::]

        root, _ = os.path.splitext(os.path.basename(input_filename))
        output_filename = os.path.join(self.output_dir, root + ".html")
        md.setdefault(u"stylesheets", self.stylesheet_root)
        md.setdefault(u"canonical", root + ".html")
        md.setdefault(u"version", version)
        for k, v in md.items():
            if isinstance(v, (list, tuple)) and len(v) == 1:
                md[k] = v[0]

        full_title = md.get("title", u"Puppet " + root)
        if not full_title.lower().startswith(u"puppet"):
            full_title = u"Puppet %s" % (full_title,)
        md.setdefault(u"full_title", full_title)
        output.insert(0, templates.interpolate(md[u"layout"], u"header", md))
        output.append(templates.interpolate(md[u"layout"], u"footer", md))
        with codecs.open(output_filename, "w", "utf-8") as f:
            f.write(u"\n".join(output))
            if root.startswith("lang_"):
                root = root[5:]
            SQLOutput()(root, output_filename)
コード例 #4
0
ファイル: tests.py プロジェクト: ultmaster/python-markdown2
 def test_markdown(self):
     import os
     dirname = os.path.dirname(__file__)
     for (path, dirs,
          files) in os.walk(os.path.join(dirname, 'markdowntest-cases')):
         for file in files:
             if file.endswith('.text'):
                 try:
                     s = open(os.path.join(path, file)).read()
                     out = convert(s).split('\n')
                     ans = open(os.path.join(path, file[:-5] +
                                             '.html')).readlines()
                     for i in range(len(out)):
                         if i < len(
                                 ans) and out[i].strip() != ans[i].strip():
                             print(file, file=sys.stderr)
                             print('out and ans diffs at line %d:' % i,
                                   file=sys.stderr)
                             print('out (len %d): %s' %
                                   (len(out[i]), out[i]),
                                   file=sys.stderr)
                             print('ans (len %d): %s' %
                                   (len(ans[i]), ans[i]),
                                   file=sys.stderr)
                             raise ValueError()
                 except ValueError:
                     pass
                 except Exception as e:
                     print(file, file=sys.stderr)
コード例 #5
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test_header(self):
        test = ("# Header 1\n"
                "\n"
                "   #### Header2  poipoi")

        result = markdown.convert(test)

        expected = ("<h1>Header 1</h1>\n"
                    "<h4>Header2  poipoi</h4>")

        self.assertEqual(result, expected)
コード例 #6
0
 def _render_markdown(self, content):
     """Render markdown for the provided content.
         :content string: Some markdown.
         :returns: HTML as a string.
     """
     html = markdown.convert(content)
     try:
         html = self._convert_http_to_https(html)
     except Exception:
         # Leave the readme unparsed.
         pass
     return html
コード例 #7
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test_unordered_list(self):
        test = ("- first item\n"
                "-  second item\n")

        result = markdown.convert(test)

        expected = ("<ul>\n"
                    "<li>first item</li>\n"
                    "<li>second item</li>\n"
                    "</ul>")

        self.assertEqual(result, expected)
コード例 #8
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test_paragraph(self):
        test = ("Some line\n"
                " second line\n"
                "Last line\n")

        result = markdown.convert(test)

        expected = ("<p>Some line\n"
                    "second line\n"
                    "Last line</p>")

        self.assertEqual(result, expected)
コード例 #9
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test_ordered_list(self):
        test = ("1. first item\n"
                "2.  second item\n"
                "10. third item\n")

        result = markdown.convert(test)

        expected = ("<ol>\n"
                    "<li>first item</li>\n"
                    "<li>second item</li>\n"
                    "<li>third item</li>\n"
                    "</ol>")

        self.assertEqual(result, expected)
コード例 #10
0
ファイル: test.py プロジェクト: pior/test_markdown_parser
    def test(self):
        test = ["# title title  ",
                "",
                "   ### header3",
                "",
                "- unorderedlist1",
                "- unorderedlist2",
                "- unorderedlist3",
                "",
                "1. orderlist1",
                "2. orderlist2",
                "",
                "p1",
                "p1",
                "p1",
                "",
                "p2",
                "# poipoi",
                ""]

        result = markdown.convert('\n'.join(test))

        expected = ["<h1>title title</h1>",
                    "<h3>header3</h3>",
                    "<ul>",
                    "<li>unorderedlist1</li>",
                    "<li>unorderedlist2</li>",
                    "<li>unorderedlist3</li>",
                    "</ul>",
                    "<ol>",
                    "<li>orderlist1</li>",
                    "<li>orderlist2</li>",
                    "</ol>",
                    "<p>p1",
                    "p1",
                    "p1</p>",
                    "<p>p2",
                    "# poipoi</p>"]

        self.assertEqual(result.splitlines(), expected)
コード例 #11
0
 def textChange(self):
     raw = self.ui.txtInput.toPlainText()
     md = markdown.convert(raw)
     self.ui.txtOutput.setHtml(md)