markdown.py (2048B) - raw
1 """ 2 Tools for converting Box Notes to Markdown 3 """ 4 from . import html 5 6 7 def convert_simple_element_to_markdown(box_attribute: (str, str)) -> (str, str, bool): 8 """ 9 Return the starting and ending markdown that should appear around some text. 10 11 :param box_attribute: Tuple containing the attribute_type and attribute_value. 12 :return: A tuple containing the start, end and a boolean value that defines whether this particular start should 13 take precedence and be prefixed at the start of the line. 14 """ 15 attribute_type = box_attribute[0] 16 attribute_value = box_attribute[1] 17 start = "" 18 end = "" 19 # If True then it signifies that this value should appear at the start of the line. 20 prefix = None 21 22 if not attribute_type: 23 start = end = "" 24 elif attribute_type == "bold": 25 start = end = "**" 26 elif attribute_type == "italic": 27 start = end = "*" 28 elif attribute_type == "underline": 29 start = "<ins>" 30 end = "</ins>" 31 elif attribute_type == "strikethrough": 32 start = end = "~~" 33 elif "font-size" in attribute_type: 34 sizemap = {"small": "", "medium": "", "large": "## ", "verylarge": "# "} 35 size = attribute_type.split("-")[-1] 36 start = sizemap[size] 37 prefix = True 38 elif attribute_type.startswith("link-"): 39 start = "[" 40 end = "]({})".format(html._decode_link(attribute_type)) 41 elif attribute_type.startswith("image"): 42 start = "".format(html._decode_image(attribute_type).get("boxSharedLink")) 44 elif attribute_type == "list": 45 kind, level = html.get_list_info(box_attribute) 46 if kind == 'ordered': 47 formatter = '1. ' 48 elif kind == 'unordered': 49 formatter = '* ' 50 elif kind == 'unchecked': 51 formatter = '* [ ] ' 52 elif kind == 'checked': 53 formatter = '* [x] ' 54 else: 55 formatter = '* ' 56 start = " " * (level - 1) + formatter 57 return start, end, prefix