X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e78e8fdbfdcf104a96f04d5e7ebf0ed2c3d95c93..ce1245e1fa3d59428e5f3c9bb78d77bcfe9e586c:/wxPython/docs/bin/docparser/restconvert.py diff --git a/wxPython/docs/bin/docparser/restconvert.py b/wxPython/docs/bin/docparser/restconvert.py new file mode 100644 index 0000000000..e3f98d99c9 --- /dev/null +++ b/wxPython/docs/bin/docparser/restconvert.py @@ -0,0 +1,32 @@ +import re + +conversion_table = { + "B" : "**", + "I" : "*", + "TT": "``", + "P" : "\n", + "BR": "\n", + } + +html_classlink_re = "(.*?)" + +def htmlToReST(html): + # \n is useless in the HTML docs, we'll use P tags to break paragraphs. + restText = html.replace("\n", "") + restText = restText.replace("*", "\\*") + if restText.find("
") == 0: + restText = restText[3:] + + link_regex = re.compile(html_classlink_re, re.DOTALL | re.MULTILINE | re.IGNORECASE) + restText = link_regex.sub("`\g<1>`", restText) + + + for htmltag in conversion_table: + + for tagname in [htmltag, htmltag.lower()]: + restText = restText.replace("<%s>" % tagname, conversion_table[htmltag]) + restText = restText.replace("%s>" % tagname, conversion_table[htmltag]) + + # we need to escape any remaining double-quotes + restText = restText.replace('"', '\\"') + return restText.strip() \ No newline at end of file