def handle_heading(self): if self.tumd.cur_context_vars( ) != self.tumd.context_dict['paragraph'].variables: return line = self.tumd.line_data[0] count = 0 while line[count] == '#' and count < 5: count += 1 if count > 0: count += 1 if self.html.need_to_close_paragraph: pop([self.html]) self.html.add('</p>') self.html.need_to_close_paragraph = False line = self.tumd.expand_line(line) line = re.sub(r'^#*\s*', '', line) line = re.sub(r'\s*$', '', line) hstr = 'h' + str(count) if len(self.tumd.context) == 2: Article_Manager.heading_to_section([self, line, count]) self.html.add('<' + hstr + ' id="' + self.headings[-1][0] + '">' + self.headings[-1][1] + '</' + hstr + '>') else: line = '<' + hstr + '>' + line + '</' + hstr + '>' self.tumd.line_data = (line, self.tumd.line_data[1])
def write_sidenav(args): args[0].html.add('<nav id="sidenav">') push([args[0].html]) for heading in args[0].headings: sidenav_level = '' # for i in range(1, heading[2]): # sidenav_level += '<div class="sidenav-level"></div>' args[0].html.add(sidenav_level + '<a href="#' + heading[0] + '" style="padding-left:' + str(12 * (heading[2])) + 'px;">' + heading[1] + '</a>') pop([args[0].html]) args[0].html.add('</nav>') args[0].html.add('<div id="sidenav-activator"></div>') return ''
def add_li(html, line_data): global list_first_element line = line_data[0] blank_lines = line_data[1] > 1 if list_first_element: html.add('<li>' + line) push([html]) list_first_element = False return if blank_lines: pop([html]) html.add('</li>') html.add('<li>' + line) push([html]) else: html.add(line)
def print_subfolders(args): html = args[0] content = args[1] maindir = os.path.dirname(os.path.realpath(content.tumd.infile.name)) dirs = get_immediate_subdirectories(maindir) dirs.sort() articles = [] for directory in dirs: try: with open(maindir + '/' + directory + '/index.tumd', 'r') as file_reader: line = file_reader.readline().rstrip() if line == 'article': content_dict = get_tags(file_reader, line) content_dict['Directory'] = directory articles.append(content_dict) except: pass if len(articles) > 0: html.add('<h1 class="section-head">Articles</h1>') for article in articles: html.add('<div class="article-box">') push([html]) html.add('<h2 class="article-box-text"><a href="' + article['Directory'] + '">' + article['Title'] + '</a></h2><br>') html.add('<h4 class="article-box-text">by <a href="' + author_name(article['Author']) + '">' + article['Author'] + '</a></h4><br>') html.add('<span style="font-size: 1.25em">' + article['Tagline'] + '</span>') html.add('<a href="' + article['Directory'] + '" class="article-box-link"></a>') pop([html]) html.add('</div>') return ''
def close_aside(html): html.check_and_close_paragraph() pop([html]) html.add('</div>')
def write_end_of_article(self): self.html.check_and_close_paragraph() pop([self.html]) self.html.add('</div>')
def close_spoiler(html): html.check_and_close_paragraph() html.add('</div>') pop([html]) html.add('</div>')
def close_ul(html): pop([html]) html.add('</li>') pop([html]) html.add('</ul>')
def close_ol(html): pop([html]) html.add('</li>') pop([html]) html.add('</ol>')
def close_style(html): pop([html]) html.add('</style>')