aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/tools/convert_release_notes.py
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
commit4fd287655a72b9aea14cdac715ad5b90ed082ed2 (patch)
tree65d393bc0e699dd12d05b29ba568e04cea666207 /circuitpython/tools/convert_release_notes.py
parent0150f70ce9c39e9e6dd878766c0620c85e47bed0 (diff)
add circuitpython code
Diffstat (limited to 'circuitpython/tools/convert_release_notes.py')
-rw-r--r--circuitpython/tools/convert_release_notes.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/circuitpython/tools/convert_release_notes.py b/circuitpython/tools/convert_release_notes.py
new file mode 100644
index 0000000..0ebccf9
--- /dev/null
+++ b/circuitpython/tools/convert_release_notes.py
@@ -0,0 +1,76 @@
+# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
+#
+# SPDX-License-Identifier: MIT
+
+import sys
+import mistune
+import mistune.renderers
+
+print(sys.argv[1])
+
+with open(sys.argv[1], "r") as source_file:
+ source = source_file.read()
+
+html = mistune.create_markdown()
+
+print()
+print("HTML")
+print("=====================================")
+print('<p><em>From the <a href="">GitHub release page</a>:</em></p>\n')
+print(html(source))
+
+
+class AdafruitBBCodeRenderer(mistune.renderers.BaseRenderer):
+ def placeholder(self):
+ return ""
+
+ def paragraph(self, text):
+ return text + "\n\n"
+
+ def block_text(self, text):
+ return text
+
+ def text(self, text):
+ return text
+
+ def link(self, link, title, text):
+ return "[url={}]{}[/url]".format(link, title)
+
+ def autolink(self, link, is_email):
+ if not is_email:
+ return "[url={}]{}[/url]".format(link, link)
+ return link
+
+ def heading(self, text, level):
+ return "[b][size=150]{}[/size][/b]\n".format(text)
+
+ def codespan(self, text):
+ return "[color=#E74C3C][size=95]{}[/size][/color]".format(text)
+
+ def list_item(self, text, level):
+ return "[*]{}[/*]\n".format(text.strip())
+
+ def list(self, text, ordered, level, start=None):
+ ordered_indicator = "=" if ordered else ""
+ return "[list{}]\n{}[/list]".format(ordered_indicator, text)
+
+ def double_emphasis(self, text):
+ return "[b]{}[/b]".format(text)
+
+ def emphasis(self, text):
+ return "[i]{}[/i]".format(text)
+
+ def strong(self, text):
+ return "[b]{}[/b]".format(text)
+
+ def finalize(self, data):
+ return "".join(data)
+
+
+bbcode = mistune.create_markdown(renderer=AdafruitBBCodeRenderer())
+
+print()
+print("BBCode")
+print("=====================================")
+print("[i]From the [url=]GitHub release page[/url]:[/i]\n")
+print(bbcode(source))