|
| 1 | +import sys |
| 2 | +import mistune |
| 3 | + |
| 4 | +print(sys.argv[1]) |
| 5 | + |
| 6 | +with open(sys.argv[1], "r") as source_file: |
| 7 | + source = source_file.read() |
| 8 | + |
| 9 | +html = mistune.Markdown() |
| 10 | + |
| 11 | +print() |
| 12 | +print("HTML") |
| 13 | +print("=====================================") |
| 14 | +print("From the <a href=\"\">GitHub release page</a>:\n<blockquote>") |
| 15 | +print(html(source)) |
| 16 | +print("</blockquote>") |
| 17 | + |
| 18 | +class AdafruitBBCodeRenderer: |
| 19 | + def __init__(self, **kwargs): |
| 20 | + self.options = kwargs |
| 21 | + |
| 22 | + def placeholder(self): |
| 23 | + return '' |
| 24 | + |
| 25 | + def paragraph(self, text): |
| 26 | + return text + "\n\n" |
| 27 | + |
| 28 | + def text(self, text): |
| 29 | + return text |
| 30 | + |
| 31 | + def link(self, link, title, text): |
| 32 | + return "[url={}]{}[/url]".format(link, text) |
| 33 | + |
| 34 | + def header(self, text, level, raw): |
| 35 | + return "[b][size=150]{}[/size][/b]\n".format(text) |
| 36 | + |
| 37 | + def codespan(self, text): |
| 38 | + return "[color=#E74C3C][size=95]{}[/size][/color]".format(text) |
| 39 | + |
| 40 | + def list_item(self, text): |
| 41 | + return "[*]{}[/*]\n".format(text.strip()) |
| 42 | + |
| 43 | + def list(self, body, ordered=True): |
| 44 | + ordered_indicator = "=" if ordered else "" |
| 45 | + return "[list{}]\n{}[/list]".format(ordered_indicator, body) |
| 46 | + |
| 47 | + def double_emphasis(self, text): |
| 48 | + return "[b]{}[/b]".format(text) |
| 49 | + |
| 50 | +bbcode = mistune.Markdown(renderer=AdafruitBBCodeRenderer()) |
| 51 | + |
| 52 | +print() |
| 53 | +print("BBCode") |
| 54 | +print("=====================================") |
| 55 | +print("From the [url=]GitHub release page[/url]:\n[quote]") |
| 56 | +print(bbcode(source)) |
| 57 | +print("[/quote]") |
0 commit comments