def test_basic_prop(): """tests that custom __getattr__ works""" toc = md2py(chikin) assert str(toc) == '' assert toc.depth == 1 assert len(toc.branches) == 1 assert isinstance(toc.h1, TreeOfContents)
def test_branches_limit(): """Tests that branches include only headings of higher depth""" toc = md2py(chikin) assert toc.h1.h2.string == 'Chapter 1 : Chikin Fly' assert list(map(str, toc.h1.h2.h3s)) == ['Waddling'] assert list(map(str, toc.h1[1].h3s)) == ['Plopping', 'I Scream']
def test_top_level2(): """tests parse for top level of markdown string with only h2s""" toc = md2py(iscream) assert toc.h1 is None assert str(toc.h2) == 'I Scream' assert len(list(toc.h2s)) == 2 assert toc.depth == 2
def test_top_level(): """tests parse for the top level of a markdown string""" toc = md2py(chikin) assert str(toc.h1) == 'Chikin Tales' assert len(list(toc.h2s)) == 0 assert len(list(toc.h3s)) == 0 assert toc.depth == 1
def getMdTitle(mdFileName: str) -> str: returnTitle = None mdFile = open(mdFileName, 'r') fileMd = markdown(mdFile.read()) try: toc = md2py.md2py(fileMd) print(toc) returnTitle = toc.h1 except TypeError: pass mdFile.close() return returnTitle
def calculate_link(match): link = match.group()[match.group().rfind('[') + 1:match.group().rfind(']') - 1] if '|' in link: title = link[link.find('|') + 1:] file = link[:link.find('|')] else: file = link title = None print(file) print(title) project_root = os.path.join(env.project_dir, "docs") # Absolute URL of the linker # abs_linker_url = os.path.dirname(os.path.join(self.base_docs_url, self.page_url)) # Find directory URL to target link # rel_link_url = '' # Walk through all files in docs directory to find a matching file abs_link_url = '' for root, dirs, files in os.walk(project_root): for name in files: # If we have a match, create the relative path from linker to the link if name == file: # Absolute path to the file we want to link to abs_link_url = os.path.dirname(os.path.join(root, name)) abs_link_url = os.path.join(abs_link_url, file) # Constructing relative path from the linker to the link rel_link_url = os.path.relpath(abs_link_url, project_root) if abs_link_url and os.path.exists(abs_link_url): md = open(abs_link_url, 'r').read() toc = md2py.md2py(md) if not title: title = str(toc.h1) return "<a href=\"" + "/" + rel_link_url[:rel_link_url.rfind( '.')] + "\">" + title + "</a>" else: return link
def test_indexing(): """test indices""" toc = md2py(chikin) assert list(toc.h1.h2s)[1] == toc.h1[1] assert str(toc.h1[1]) == 'Chapter 2 : Chikin Scream'
def test_get_tags(): """tests that tags are printed correctly""" toc = md2py(chikin) assert len(list(toc.h1s)) == 1 assert str(toc.h1) == repr(toc.h1) == toc.h1.string == 'Chikin Tales'