Пример #1
0
    def add_article(self, content, page, base_url):
        if not self.generate:
            return None
        self._base_urls[page.file.url] = base_url
        soup = BeautifulSoup(content, 'html.parser')
        url = page.url.split('.')[0]
        article = soup.find('article')
        if not article:
            article = self.html.new_tag('article')
            eld = soup.find('div', **{'role': 'main'})
            article.append(eld)
            article.div['class'] = article.div['role'] = None

        if not article:
            self.generate = False
            return None
        article = prep_combined(article, base_url, page.file.url)
        span = soup.new_tag('span')
        span['id'] = 'mkpdf-{}'.format(url)
        article.insert(0, span)
        if page.meta != None and 'pdf' in page.meta and page.meta[
                'pdf'] == False:
            # print(page.meta)
            return self.get_path_to_pdf(page.file.dest_path)
        self._articles[page.file.url] = article
        return self.get_path_to_pdf(page.file.dest_path)
Пример #2
0
    def add_article(self, content, page, base_url):
        if not self.generate:
            return None
        self._base_urls[page.file.url] = base_url
        soup = BeautifulSoup(content, 'html.parser')
        url = page.url[:-5] if page.url.endswith('.html') else page.url
        article = soup.find('article')
        if not article :
            article = self.html.new_tag('article')
            eld = soup.find('div', **{'role': 'main'})
            article.append(eld)
            article.div['class'] = article.div['role'] = None

        if not article:
            self.generate = False
            return None
        article = increment_headings(
            remove_header_links(
                prep_combined(
                    remove_material_header_icons(article),
                    base_url, page.file.url,
                ),
            ),
            self._page_nesting.get(page.file.url, 0),
        )
        span = soup.new_tag('span')
        span['id'] = 'mkpdf-{}'.format(url)
        article.insert(0, span)
        if page.meta != None and 'pdf' in page.meta and page.meta['pdf'] == False:
            # print(page.meta)
            return self.get_path_to_pdf(page.file.dest_path)
        self._articles[page.file.url] = article
        return self.get_path_to_pdf(page.file.dest_path)
Пример #3
0
 def _gen_toc_for_section(self, url, p):
     div = self.html.new_tag('div')
     menu = self.html.new_tag('div')
     h4 = self.html.new_tag('h4')
     urlid = url.split('.')[0]
     a = self.html.new_tag('a', href='#mkpdf-{}'.format(urlid))
     a.insert(0, p.title)
     h4.append(a)
     menu.append(h4)
     ul = self.html.new_tag('ul')
     for child in p.toc.items:
         a = self.html.new_tag('a', href=child.url)
         a.insert(0, child.title)
         li = self.html.new_tag('li')
         li.append(a)
         if child.title == p.title:
             li = self.html.new_tag('div')
         if child.children:
             sub = self._gen_children(url, child.children)
             li.append(sub)
         ul.append(li)
     if len(p.toc.items) > 0:
         menu.append(ul)
     div.append(menu)
     div = prep_combined(div, self._base_urls[url], url)
     return div.find('div')
Пример #4
0
 def _gen_toc_for_section(self, url, p):
     div = self.html.new_tag('div')
     menu = self.html.new_tag('div')
     h4 = self.html.new_tag('h4')
     a = self.html.new_tag('a', href='#')
     a.insert(0, p.title)
     h4.append(a)
     menu.append(h4)
     if self.config['toc_level'] > 1:
         ul = self.html.new_tag('ul')
         for child in p.toc.items:
             a = self.html.new_tag('a', href=child.url)
             a.insert(0, child.title)
             li = self.html.new_tag('li')
             li.append(a)
             if child.title == p.title:
                 li = self.html.new_tag('div')
             if child.children:
                 sub = self._gen_children(url, child.children)
                 li.append(sub)
             ul.append(li)
         if len(p.toc.items) > 0:
             menu.append(ul)
     div.append(menu)
     div = prep_combined(div, self._base_urls[url], url)
     return div.find('div')
Пример #5
0
 def _gen_toc_page(self, url, toc):
     div = self.html.new_tag('div')
     menu = self.html.new_tag('ul')
     for item in toc.items:
         li = self.html.new_tag('li')
         a = self.html.new_tag('a', href=item.url)
         a.append(item.title)
         li.append(a)
         menu.append(li)
         if item.children:
             child = self._gen_children(url, item.children)
             menu.append(child)
     div.append(menu)
     div = prep_combined(div, self._base_urls[url], url)
     return div.find('ul')