Пример #1
0
    def get_best_face_markdown(self):
        if self.check_scholar_photo_valid():
            return DuMark.get_image('../' + self._get_local_scholar_photo_url,
                                    self.get_name())

        if 'face' in self._data:
            return DuMark.get_image(self._data['face'], self.get_name())
        else:
            return ''
Пример #2
0
    def compile(self, filename, write_to_file=False):
        """Generates HTML files with Markdown templates.

    Args:
      filename: input filename with predefined grammar rules.

    Returns:
      html: HTML contents of this file.
    """
        if filename in self.built_html:
            logging.info("Reusing HTML: %s" % filename)
            return self.built_html[filename]
        html = ''

        input_filename = os.path.join(Dir.templates, filename)
        output_filename = os.path.join(Dir.builds, filename)

        # Parses the HTML line by line.
        with open(input_filename, 'r', encoding='utf8') as f:
            lines = f.readlines()

        for line in lines:
            # Early pruning for non-special rules.
            if line.find('<!--') == -1 and line.find('{{') == -1:
                html += line
                continue

            # 0. Parses variable meta commands.
            ans = Regex.ASSIGN.search(line)
            if ans:
                lhs = ans.group(1)
                rhs = ans.group(2)
                self._assign_dict[lhs] = rhs
                continue

            # 1. Recursively parses the included file.
            ans = Regex.INCLUDE.search(line)
            if ans:
                include_filename = ans.group(1)
                logging.info('Including HTML: %s' % include_filename)
                include_content = self.compile(include_filename)
                html += include_content
                continue

            # 2. Parses, compresses, and writes the css file.
            ans = Regex.CSS.search(line)
            if ans:
                css_filename = ans.group(1)
                logging.info('Minimizing CSS: %s' % css_filename)
                self.compile_css(css_filename)
                css_filename = os.path.join(Dir.css,
                                            css_filename).replace('\\', '/')
                html += '<link rel="stylesheet" href="/%s" />' % css_filename
                continue

            # 3. Parses, compresses, and writes the js file.
            ans = Regex.JS.search(line)
            if ans:
                js_filename = ans.group(1)
                logging.info("~ Minimizing JS: %s" % js_filename)
                self.compile_js(js_filename)
                js_filename = os.path.join(Dir.js,
                                           js_filename).replace('\\', '/')
                html += '<script src="/%s"></script>' % js_filename
                continue

            # 4. Parses image file inline.
            ans = Regex.IMAGE.search(line)
            if ans:
                image_filename = os.path.join(Dir.images,
                                              ans.group(1)).replace('\\', '/')
                image_description = self.parse_variable(ans.group(2))
                line = DuMark.get_image('/' + image_filename,
                                        image_description)
                line = markdown(line)

            # 5. Parses publication file inline.
            ans = Regex.PUBLICATION.search(line)
            if ans:
                pub_filename = os.path.join(Dir.templates, ans.group(1))
                line = self.compile_publication(pub_filename)

            # 6. Parses art file inline.
            ans = Regex.ART.search(line)
            if ans:
                art_filename = os.path.join(Dir.templates, ans.group(1))
                line = self.compile_art(art_filename)

            # Processes variables.
            line = self.parse_variable(line)

            # Appends this line.
            html += line

        # Outputs the HTML file if required.
        if write_to_file:
            # Minimizes the HTML:
            if App.minimize_html:
                if App.debug_html:
                    print(html)
                html = htmlmin.minify(html,
                                      remove_comments=True,
                                      remove_all_empty_space=True)
            with open(output_filename, 'w', encoding='utf8') as f:
                f.write(html)

        self.built_html[filename] = html
        return html
Пример #3
0
 def get_teaser_markdown(self):
   """Returns teaser markdown."""
   return DuMark.get_image('/%s/%s.jpg' % (Dir.teasers, self.get_bib_id()),
                           '%s Teaser Image.' % self._data['title'])
Пример #4
0
 def get_face_raw_markdown(self):
     if 'face' in self._data:
         return DuMark.get_image(self._data['face'], self.get_name())
     else:
         return ''