|
4 | 4 |
|
5 | 5 | import sys
|
6 | 6 | import mistune
|
| 7 | +import mistune.renderers |
7 | 8 |
|
8 | 9 | print(sys.argv[1])
|
9 | 10 |
|
10 | 11 | with open(sys.argv[1], "r") as source_file:
|
11 | 12 | source = source_file.read()
|
12 | 13 |
|
13 |
| -html = mistune.Markdown() |
| 14 | +html = mistune.create_markdown() |
14 | 15 |
|
15 | 16 | print()
|
16 | 17 | print("HTML")
|
|
19 | 20 | print(html(source))
|
20 | 21 | print("</blockquote>")
|
21 | 22 |
|
22 |
| -class AdafruitBBCodeRenderer: |
23 |
| - def __init__(self, **kwargs): |
24 |
| - self.options = kwargs |
25 |
| - |
| 23 | +class AdafruitBBCodeRenderer(mistune.renderers.BaseRenderer): |
26 | 24 | def placeholder(self):
|
27 | 25 | return ''
|
28 | 26 |
|
29 | 27 | def paragraph(self, text):
|
30 | 28 | return text + "\n\n"
|
31 | 29 |
|
| 30 | + def block_text(self, text): |
| 31 | + return text |
| 32 | + |
32 | 33 | def text(self, text):
|
33 | 34 | return text
|
34 | 35 |
|
35 | 36 | def link(self, link, title, text):
|
36 |
| - return "[url={}]{}[/url]".format(link, text) |
| 37 | + return "[url={}]{}[/url]".format(link, title) |
37 | 38 |
|
38 | 39 | def autolink(self, link, is_email):
|
39 | 40 | if not is_email:
|
40 | 41 | return "[url={}]{}[/url]".format(link, link)
|
41 | 42 | return link
|
42 | 43 |
|
43 |
| - def header(self, text, level, raw): |
| 44 | + def heading(self, text, level): |
44 | 45 | return "[b][size=150]{}[/size][/b]\n".format(text)
|
45 | 46 |
|
46 | 47 | def codespan(self, text):
|
47 | 48 | return "[color=#E74C3C][size=95]{}[/size][/color]".format(text)
|
48 | 49 |
|
49 |
| - def list_item(self, text): |
| 50 | + def list_item(self, text, level): |
50 | 51 | return "[*]{}[/*]\n".format(text.strip())
|
51 | 52 |
|
52 |
| - def list(self, body, ordered=True): |
| 53 | + def list(self, text, ordered, level, start=None): |
53 | 54 | ordered_indicator = "=" if ordered else ""
|
54 |
| - return "[list{}]\n{}[/list]".format(ordered_indicator, body) |
| 55 | + return "[list{}]\n{}[/list]".format(ordered_indicator, text) |
55 | 56 |
|
56 | 57 | def double_emphasis(self, text):
|
57 | 58 | return "[b]{}[/b]".format(text)
|
58 | 59 |
|
59 | 60 | def emphasis(self, text):
|
60 | 61 | return "[b]{}[/b]".format(text)
|
61 | 62 |
|
62 |
| -bbcode = mistune.Markdown(renderer=AdafruitBBCodeRenderer()) |
| 63 | + def strong(self, text): |
| 64 | + return "[i]{}[/i]".format(text) |
| 65 | + |
| 66 | +bbcode = mistune.create_markdown(renderer=AdafruitBBCodeRenderer()) |
63 | 67 |
|
64 | 68 | print()
|
65 | 69 | print("BBCode")
|
|
0 commit comments