boxnotes2html

Convert Box's proprietary Box Notes to HTML, Markdown, or plain text
Log | Files | Refs | README | LICENSE

commit 497f6310d349f4ae524710fb76ec087122b66bf1
parent c45e07d2a200c16612186d9c9760136e0563dc4e
Author: Alex Hayes <alex.hayes@rea-group.com>
Date:   Tue, 14 Jul 2020 12:31:12 +1000

Support ordered, unordered, checked and unchecked list items in Markdown docs.

squash! Support ordered, unordered, checked and unchecked list items in Markdown docs.

squash! Support ordered, unordered, checked and unchecked list items in Markdown docs.

Diffstat:
MREADME.md | 3++-
Mboxnotes2html/html.py | 10++++++----
Mboxnotes2html/markdown.py | 14++++++++++++--
3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md @@ -63,9 +63,10 @@ The HTML formatted by this tool is pretty ugly -- that may not be important for Functioning: * Text formatting (bold, underline, colors, size, etc) * Hyperlinks +* Ordered, unordered, checked and unchecked lists are supported in Markdown (using Github flavoured check/uncheck syntax). Caveats: -* Lists are a little wonky -- they are just stars with spcaes instead of HTML tags. A TBD if there is interest. +* HTML lists don't supported nesting * Tables are broken and will just be converted to plaintext. If you can figure out a clean way to do this, please submit a pull request. * Images are just a link to the image in Box, converting them would require API access. * Comments and annotations are not saved. diff --git a/boxnotes2html/html.py b/boxnotes2html/html.py @@ -34,13 +34,15 @@ def get_list_attribute(box_attribute): # UNUSED def get_list_info(box_attribute): if "list" in box_attribute[0]: if box_attribute[1].startswith("number"): - type = "ordered" + kind = "ordered" + elif box_attribute[1].startswith("uncheck"): + kind = "unchecked" elif box_attribute[1].startswith("check"): - type = "checkbox" + kind = "checked" else: - type = "unordered" + kind = "unordered" # TODO: regex. cant do more than 9 list levels - return type, int(box_attribute[1][-1]) + return kind, int(box_attribute[1][-1]) def convert_simple_element_to_html_tag(box_attribute): diff --git a/boxnotes2html/markdown.py b/boxnotes2html/markdown.py @@ -28,6 +28,16 @@ def convert_simple_element_to_markdown(box_attribute): start = "![" end = "]({})".format(html._decode_image(attribute_type).get("boxSharedLink")) elif attribute_type == "list": - _, level = html.get_list_info(box_attribute) - start = " " * (level - 1) + "* " + kind, level = html.get_list_info(box_attribute) + if kind == 'ordered': + formatter = '1. ' + elif kind == 'unordered': + formatter = '* ' + elif kind == 'unchecked': + formatter = '* [ ] ' + elif kind == 'checked': + formatter = '* [x] ' + else: + formatter = '* ' + start = " " * (level - 1) + formatter return start, end