Example #1
0
 def _raw_file(self, name=None):
     """Build up a page for the Raw File view."""
     name = name if name else ''
     name = name.replace('|', '/')
     display_name = self._get_display_name(name)
     if 'path' not in self.page_options:
         body_txt = 'No directory to serve in the config file.'
     else:
         path = os.path.join(self.path, name)
         body = Doc()
         with body.tag('h1'):
             body.text('File: %s' % display_name)
         with body.tag('div'):
             body.attr(klass='navigation')
             body.asis(self._get_navigation_links(path))
         with body.tag('div'):
             body.attr(klass='files')
             if os.path.exists(path):
                 if os.path.isdir(path):
                     body.asis(self._get_dir_listing(path))
                 else:
                     body.asis(self._get_file(path))
         body_txt = body.getvalue()
     flash_messages = self.page_options.get('flash_messages', True)
     return HtmlPage(head=None,
                     body=body_txt,
                     flash_messages=flash_messages).render_template()
Example #2
0
def get_table_html(header, rows, row_names=None):
    def add_header(doc, header):
        with doc.tag('tr'):
            for value in header:
                doc.line('th', value)

    def add_row(doc, values, row_name=None):
        with doc.tag('tr'):
            if row_name is not None:
                doc.line('th', row_name)
            for value in values:
                doc.line('td', value)

    doc = Doc()
    if row_names is not None:
        header.insert(0, '')
    else:
        row_names = [None] * len(rows)
    with doc.tag('table', klass='table table-bordered table-responsive table-striped'):
        with doc.tag('thead', klass='thead-light'):
            add_header(doc, header)
        with doc.tag('tbody'):
            for row, row_name in zip(rows, row_names):
                add_row(doc, [round(val, 2) for val in row], row_name)
    return doc.getvalue()
Example #3
0
 def to_html(self):
     """Convert self data to its html stream."""
     doc = Doc()
     with doc.tag('div', id='Figure-' + str(self.number)):
         if self.style:
             doc.attr(style=self.style)
         else:
             doc.attr(klass='figure')
         with doc.tag(self.ctn_type):
             if self.cap_position is not None and self.cap_position.upper(
             ) == 'TOP':
                 self.put_caption(doc=doc, klass='figure-caption')
             if self.ctn_options:
                 doc.stag('img',
                          src=self.ctn,
                          klass='figure-content',
                          style=self.ctn_options,
                          alt='Figure-' + self.ctn)
             else:
                 doc.stag('img',
                          src=self.ctn,
                          klass='figure-content',
                          style='width:100%;',
                          alt='Figure-' + self.ctn)
             if self.cap_position is None or self.cap_position.upper(
             ) == 'BOTTOM':
                 self.put_caption(doc=doc, klass='figure-caption')
     return doc.getvalue()
Example #4
0
 def to_html(self):
     """Convert self data to its html stream."""
     doc = Doc()
     with doc.tag('div', id='video-' + str(self.number)):
         if self.style:
             doc.attr(style=self.style)
         else:
             doc.attr(klass='video')
         if self.cap_position is not None and self.cap_position.upper(
         ) == 'TOP':
             self.put_caption(doc=doc, klass='video-caption')
         with doc.tag('video', klass='video-content'):
             if self.controls:
                 doc.attr(controls='controls')
             if self.autoplay:
                 doc.attr(autoplay='autoplay')
             if self.ctn_options:
                 doc.attr(style=self.ctn_options)
             else:
                 doc.attr(style='width:100%;')
             doc.stag('source', src=self.ctn)
         if self.cap_position is None or self.cap_position.upper(
         ) == 'BOTTOM':
             self.put_caption(doc=doc, klass='video-caption')
     return doc.getvalue()
Example #5
0
    def create_body_section(articles: list, create_date: str):
        """
        create HTML Body Section

        Args:
            articles (list): Article Content
            create_date (str) Article Create Date
        Returns: HTML String
        """
        idx = 0
        nav_items = list()
        article_div = list()
        for div in articles:
            if len(div.items) <= 0:
                continue
            if div.title is None:
                div.title = 'Section %s' % str(idx)
            nav_items.append(
                CustomHtml.add_anchor(text=div.title, link=idx, on_click=True))
            article_div.append(
                CustomHtml.create_div(contents=div.items, link=idx, tab=True))
            idx += 1
        _nav_list = CustomHtml.add_unordered_list(items=nav_items)
        doc = Doc()
        with doc.tag('section'):
            doc.asis(CustomHtml.create_body_nav([_nav_list]))
            with doc.tag('article'):
                with doc.tag('i'):
                    doc.text('created on %s ' % create_date)
                for div in article_div:
                    doc.asis(div)
        return doc.getvalue()
Example #6
0
 def to_html(self):
     """Method for inserting box to the html doc."""
     doc = Doc()
     with doc.tag('div', klass='figure'):
         doc.attr(('id', 'Figure-' + str(self.number)))
         if self.style:
             doc.attr(style=self.style)
         elif Figure.theme.data.data['style'][0]:
             doc.attr(style=Figure.theme.data.data['style'][0])
         with doc.tag(self.ctn_type):
             if self.ctn_options:
                 doc.stag('img',
                          src=self.ctn,
                          klass='image',
                          style=self.ctn_options,
                          alt='Figure-' + self.ctn)
             elif Figure.theme.data.data['content'][0]:
                 doc.stag('img',
                          src=self.ctn,
                          klass='image',
                          style=Figure.theme.data.data['content'][0],
                          alt='Figure-' + self.ctn)
             else:
                 doc.stag('img',
                          src=self.ctn,
                          klass='image',
                          style='width:100%;',
                          alt='Figure-' + self.ctn)
             self.put_caption(doc=doc)
     return doc.getvalue()
Example #7
0
 def get_one_sentence_html(sentence, system_name):
     doc = Doc()
     with doc.tag('div', klass='row'):
         with doc.tag('div', klass='col-2'):
             doc.text(system_name)
         with doc.tag('div', klass='col'):
             doc.asis(sentence)
     return doc.getvalue()
Example #8
0
def get_plotly_html(plotly_figure):
    doc = Doc()
    plot_id = get_random_html_id()
    # Empty div to hold the plot
    with doc.tag('div', id=plot_id):
        # Embedded javascript code that uses plotly to fill the div
        with doc.tag('script'):
            doc.asis(f"var plotlyJson = '{plotly_figure.to_json()}'; var figure = JSON.parse(plotlyJson); var plotDiv = document.getElementById('{plot_id}'); Plotly.newPlot(plotDiv, figure.data, figure.layout, {{responsive: true}});")  # noqa: E501
    return doc.getvalue()
Example #9
0
def write_html_head(doc: yattag.Doc, title: str) -> None:
    """Produces the <head> tag and its contents."""
    with doc.tag("head"):
        with doc.tag("title"):
            doc.text(_("Where to map?") + title)
        doc.stag("meta", charset="UTF-8")
        doc.stag("link", rel="stylesheet", type="text/css", href="/osm/static/osm.css")
        with doc.tag("script", src="/osm/static/sorttable.js"):
            pass
        doc.stag("meta", name="viewport", content="width=device-width, initial-scale=1")
Example #10
0
 def get_one_sample_html(orig_sent, sys_sent, ref_sents, sort_key, print_func):
     orig_sent, sys_sent, *ref_sents = [html.escape(sent) for sent in [orig_sent, sys_sent, *ref_sents]]
     doc = Doc()
     with doc.tag('div', klass='mb-2 p-1'):
         # Sort key
         with doc.tag('div', klass='text-muted small'):
             doc.asis(print_func(sort_key(orig_sent, sys_sent, ref_sents)))
         with doc.tag('div', klass='ml-2'):
             orig_sent_bold, sys_sent_bold = make_differing_words_bold(orig_sent, sys_sent, make_text_bold_html)
             # Source
             with doc.tag('div'):
                 doc.asis(orig_sent_bold)
             # Prediction
             with doc.tag('div'):
                 doc.asis(sys_sent_bold)
             # References
             collapse_id = get_random_html_id()
             with doc.tag('div', klass='position-relative'):
                 with doc.tag('a', ('data-toggle', 'collapse'), ('href', f'#{collapse_id}'),
                              klass='stretched-link small'):
                     doc.text('References')
                 with doc.tag('div', klass='collapse', id=collapse_id):
                     for ref_sent in refs:
                         _, ref_sent_bold = make_differing_words_bold(orig_sent, ref_sent, make_text_bold_html)
                         with doc.tag('div', klass='text-muted'):
                             doc.asis(ref_sent_bold)
     return doc.getvalue()
Example #11
0
 def to_html(self):
     """Method for inserting box to the html doc."""
     doc = Doc()
     with doc.tag('div', klass='box'):
         if self.style:
             doc.attr(style=self.style)
         with doc.tag('div', klass='box content'):
             if self.ctn_options:
                 doc.attr(style=self.ctn_options)
             doc.asis(self.ctn)
         self.put_caption(doc=doc)
     return doc.getvalue()
Example #12
0
def get_plots_html(orig_sents, sys_sents, ref_sents):
    doc = Doc()
    features = {
            'Compression ratio': get_compression_ratio,
            'Levenshtein similarity': get_levenshtein_similarity,
    }
    with doc.tag('div', klass='row'):
        for feature_name, feature_extractor in features.items():
            with doc.tag('div', klass='col-auto shadow-sm p-0 m-2'):
                figure = get_plotly_histogram(orig_sents, sys_sents, ref_sents, feature_extractor, feature_name)
                doc.asis(get_plotly_html(figure))
    return doc.getvalue()
Example #13
0
 def to_html(self):
   """Method for inserting box to the html doc."""
   doc = Doc()
   with doc.tag('div',klass='box'):
     if self.style:
       doc.attr(style=self.style)
     with doc.tag('div',klass='box content'):
       if self.ctn_options:
         doc.attr(style=self.ctn_options)
       doc.asis(self.ctn)
     self.put_caption(doc=doc)
   return doc.getvalue()
Example #14
0
    def create_body_footer(text: str):
        """
        create HTML Body Footer

        Args:
            text (str): Footer Text
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('footer'):
            with doc.tag('i'):
                doc.text(text)
        return doc.getvalue()
Example #15
0
    def get_one_sample_html(orig_sent, sys_sents, ref_sents, system_names, sort_key, print_func):
        def get_one_sentence_html(sentence, system_name):
            doc = Doc()
            with doc.tag('div', klass='row'):
                with doc.tag('div', klass='col-2'):
                    doc.text(system_name)
                with doc.tag('div', klass='col'):
                    doc.asis(sentence)
            return doc.getvalue()

        doc = Doc()
        with doc.tag('div', klass='mb-2 p-1'):
            # Sort key
            with doc.tag('div', klass='text-muted small'):
                doc.asis(print_func(sort_key(orig_sent, sys_sents, ref_sents)))
            with doc.tag('div', klass='ml-2'):
                # Source
                with doc.tag('div'):
                    doc.asis(get_one_sentence_html(orig_sent, 'Original'))
                # Predictions
                    for sys_sent, system_name in zip(sys_sents, system_names):
                        _, sys_sent_bold = make_differing_words_bold(orig_sent, sys_sent, make_text_bold_html)
                        doc.asis(get_one_sentence_html(sys_sent_bold, system_name))
                # References
                collapse_id = get_random_html_id()
                with doc.tag('div', klass='position-relative'):
                    with doc.tag('a', ('data-toggle', 'collapse'), ('href', f'#{collapse_id}'),
                                 klass='stretched-link small'):
                        doc.text('References')
                    with doc.tag('div', klass='collapse', id=collapse_id):
                        for ref_sent in refs:
                            _, ref_sent_bold = make_differing_words_bold(orig_sent, ref_sent, make_text_bold_html)
                            with doc.tag('div', klass='text-muted'):
                                doc.asis(ref_sent_bold)
        return doc.getvalue()
Example #16
0
    def add_unordered_list(items: list):
        """
        add unordered list

        Args:
            items (list): list of section title to add to unordered list
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('ul'):
            for item in items:
                with doc.tag('li'):
                    doc.asis(item)
        return doc.getvalue()
Example #17
0
    def add_unordered_kay_value_pair_list(items: list):
        """
        add unordered list Key:Value pair list

        Args:
            items (list): list of key:value pairs to add to unordered list
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('ul'):
            for key, value in items:
                with doc.tag('li'):
                    doc.asis('%s: <b>%s</b>' % (key, value))
        return doc.getvalue()
Example #18
0
File: box.py Project: nunb/MaTiSSe
 def to_html(self):
     """Method for inserting box to the html doc."""
     doc = Doc()
     with doc.tag("div", klass="box"):
         if self.style:
             doc.attr(style=self.style)
         if self.cap_position == "TOP":
             self.put_caption(doc=doc)
         with doc.tag("div", klass="box content"):
             if self.ctn_options:
                 doc.attr(style=self.ctn_options)
             doc.asis(self.ctn)
         if self.cap_position is None or self.cap_position == "BOTTOM":
             self.put_caption(doc=doc)
     return doc.getvalue()
Example #19
0
 def _get_file(path):
     """Return the contents of a file as a preformatted text field."""
     doc = Doc()
     with doc.tag('pre'):
         with open(path, 'r') as fin:
             doc.asis(Markup.escape(fin.read()))
     return doc.getvalue()
Example #20
0
 def _get_dir_listing(self, path):
     """Build an HTML list of the directory contents."""
     all_fnames = [f for f in os.listdir(path) if not f.startswith('.')]
     suffixes = self.page_options.get('suffix_whitelist', '').split(',')
     fnames = []
     for fname in all_fnames:
         for suffix in suffixes:
             if fname.endswith(suffix):
                 fnames.append(fname)
                 break
             elif os.path.isdir(os.path.join(path, fname)):
                 fnames.append(fname + '/')
                 break
     fnames.sort()
     base = self._get_safe_base_path(path)
     links = []
     for name in fnames:
         doc = Doc()
         name = os.path.join(base, name)
         with doc.tag('a'):
             doc.attr(
                 href=url_for('RawFile:get', name=name.replace('/', '|')))
             doc.text(name)
         links.append(doc.getvalue())
     return list_to_html_list(links)
Example #21
0
 def _get_top_dir_link():
     """Get a link to the Top Directory of the Raw File view."""
     doc = Doc()
     with doc.tag('a'):
         doc.attr(href=url_for('RawFile:index'))
         doc.text('Top Dir')
     return doc.getvalue()
Example #22
0
    def add_table_image_group(header: list,
                              data: list,
                              src: str,
                              alt: str,
                              *,
                              width=None,
                              height=None):
        """
        add a block of image with table (table on the left, image on the right)

        Args:
            header (list(str)):  table header
            data: list(list(string)), 2D nested list with table content
            src (str): image path
            alt (str): image attribute
            width (int): width of image
            height (int): height of image
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('div'):
            doc.asis(CustomHtml.add_table(header=header, data=data))
            doc.asis(
                CustomHtml.add_image(src=src,
                                     alt=alt,
                                     width=width,
                                     height=height))
        return doc.getvalue()
Example #23
0
def generateHTMLOutput(content, skills, file):
    skill_list = ""
    skills.sort(key=lambda x: x['weight'], reverse=True)

    for skill in skills: 
        skill_list += '<li>' + getElement(token=skill) + '</li>'

    doc, tag, text = Doc().tagtext()
    with tag('html'):
        with tag('head'):
            with doc.tag('style', type='text/css'):
                doc.asis(css)
        with tag('body'):
            with tag('h1'):
                text(file)
            with tag('p', id = 'main'):
                doc.asis(content)
            with tag('div', id='skills'):
                with tag('ul'):
                    doc.asis(skill_list)

    result = doc.getvalue()
    
    tmp=tempfile.NamedTemporaryFile(delete=False)
    path=tmp.name+'.html'

    f=open(path, 'w')
    f.write(result)
    f.close()

    webbrowser.open('file://' + path)
Example #24
0
    def add_basic_nested_info(data: list):
        """
        add basic nested info

        Args:
             data (list): list of tuple / list of (list of tuple))
                multi-level rendering, e.g. to display `model_info`
        Returns: HTML String
        """
        def add_paragraph(x, itemize_level='&nbsp&nbsp- '):
            doc = Doc()
            for key, item in x:
                if (type(item) is list) or (type(item) is tuple):
                    doc.asis('%s%s:<br>' % (itemize_level, key))
                    new_indent = '&nbsp&nbsp' + itemize_level
                    doc.asis(add_paragraph(item, new_indent))
                else:
                    doc.asis('%s%s: <b>%s</b><br>' %
                             (itemize_level, key, item))

            return doc.getvalue()

        outter_doc = Doc()
        with outter_doc.tag('p'):
            outter_doc.asis(add_paragraph(data))
        return outter_doc.getvalue()
Example #25
0
File: note.py Project: nunb/MaTiSSe
 def to_html(self):
   """Method for inserting box to the html doc."""
   doc = Doc()
   with doc.tag('div',klass='note'):
     if self.style:
       doc.attr(style=self.style)
     elif Note.theme.data.data['style'][0]:
       doc.attr(style=Note.theme.data.data['style'][0])
     self.put_caption(doc=doc)
     with doc.tag('div',klass='note content'):
       if self.ctn_options:
         doc.attr(style=self.ctn_options)
       elif Note.theme.data.data['content'][0]:
         doc.attr(style=Note.theme.data.data['content'][0])
       doc.asis(seditor.md_convert(self.ctn))
   return doc.getvalue()
Example #26
0
  def to_html(self, match, toc_depth=None, max_time=None, current=None):
    """Convert logo metadata to html stream.

    Parameters
    ----------
    match: re.match object
    max_time: str
      max time for presentation

    Returns
    -------
    str:
      html stream
    """
    if 'toc' in self.name:
      return self.toc_to_html(match=match, current=current, depth=int(toc_depth))
    if 'logo' in self.name:
      return self.logo_to_html(match)
    elif 'timer' in self.name:
      return self.timer_to_html(match=match, max_time=max_time)
    elif 'custom' in self.name:
      return self.custom_to_html(match)
    else:
      doc = Doc()
      with doc.tag('span', klass='metadata'):
        style = None
        if match.group('style'):
          style = str(match.group('style'))
        if style:
          doc.attr(style=style)
        if isinstance(self.value, list):
          doc.asis(', '.join(self.value))
        else:
          doc.asis(str(self.value))
    return doc.getvalue()
Example #27
0
def generate_html(log='', n=None):
    doc, tag, text = Doc().tagtext()
    with tag('html'):
        with tag('body'):
            doc.stag('img', src='img.png')
            doc.stag('img', src='lc_50.png')
            doc.stag('br')
            doc.stag('img', src='lc_sc_train.png')
            doc.stag('img', src='data_accum.png')
            doc.stag('br')
            doc.stag('img', src='img_loss.png')
            doc.stag('img', src='loss_100.png')
            doc.stag('br')
            for img in sorted(glob.glob('./*_weight.png'),
                              key=os.path.getmtime):
                doc.stag('img', src=img)
            doc.stag('br')
            with doc.tag('textarea'):
                doc.attr(rows='20')
                doc.attr(cols='240')
                for l in log:
                    text(l)
            doc.stag('br')
            if n:
                text('Number of node removals since last game: {}'.format(n))
                doc.stag('br')
            text('Last update:' + str(dt.now()))

    return doc.getvalue()
Example #28
0
    def custom_to_html(self, match):
        """Convert custom metadata to html stream.

    Parameters
    ----------
    match: re.match object

    Returns
    -------
    str:
      html stream
    """
        doc = Doc()
        with doc.tag('span', klass='metadata'):
            style = None
            if match.group('style'):
                style = str(match.group('style'))
            if style:
                doc.attr(style=style)
                value = re.search(r'value\:(?P<value>.*?)\;', style)
                if value:
                    doc.asis(
                        re.search(r'value\:(?P<value>.*?)\;',
                                  style).group('value'))
        return doc.getvalue()
Example #29
0
    def to_html(self, metadata, style=None):
        """Method for producing and html string of selected metadata.

    Parameters
    ----------
    metadata : str
      metadata key
    style : str, optional
      css style of metadata tag

    Returns
    -------
    str
      html string containing the metadata

    >>> source = '---metadata authors = ["S. Zaghi","J. Doe"] ---endmetadata'
    >>> meta = Metadata(source)
    >>> meta.to_html(metadata='authors')
    '<span class="metadata">S. Zaghi and J. Doe</span>'
    """
        doc = Doc()
        if metadata == 'logo':
            self.put_logo(doc=doc, style=style)
        else:
            with doc.tag('span', klass='metadata'):
                if style:
                    doc.attr(style=style)
                doc.asis(self.get_value(metadata))
        return doc.getvalue()
Example #30
0
def generate_html(log='', n=None):
    doc, tag, text = Doc().tagtext()
    with tag('html'):
        with tag('body'):
            doc.stag('img', src='img.png')
            doc.stag('img', src='lc_50.png')
            doc.stag('br')
            doc.stag('img', src='img_loss.png')
            doc.stag('img', src='loss_100.png')
            doc.stag('br')
            doc.stag('img', src='conv1_weight.png')
            doc.stag('img', src='conv2_weight.png')
            doc.stag('img', src='fc1_weight.png')
            doc.stag('img', src='fc_v_weight.png')
            doc.stag('img', src='fc_var_weight.png')
            doc.stag('br')
            with doc.tag('textarea'):
                doc.attr(rows='20')
                doc.attr(cols='240')
                for l in log:
                    text(l)
            doc.stag('br')
            if n:
                text('Number of node removals since last game: {}'.format(n))
                doc.stag('br')
            text('Last update:' + str(dt.now()))

    return doc.getvalue()
Example #31
0
    def add_table_with_dict(data: dict):
        """
        add table

        Args:
            data (dict): list of key:value pairs to add to table row
        Returns: HTML String
        """
        doc = Doc()
        with doc.tag('table'):
            doc.attr(klass='standard_table')
            for key, items in data.items():
                with doc.tag('tr'):
                    doc.asis('<td>%s</td>' % key)
                    doc.asis('<td><b>%s</b></td>' % str(items))
        return doc.getvalue()
Example #32
0
  def to_html(self, metadata, style=None):
    """Method for producing and html string of selected metadata.

    Parameters
    ----------
    metadata : str
      metadata key
    style : str, optional
      css style of metadata tag

    Returns
    -------
    str
      html string containing the metadata

    >>> source = '---metadata authors = ["S. Zaghi","J. Doe"] ---endmetadata'
    >>> meta = Metadata(source)
    >>> meta.to_html(metadata='authors')
    '<span class="metadata">S. Zaghi and J. Doe</span>'
    """
    doc = Doc()
    if metadata == 'logo':
      self.put_logo(doc=doc,style=style)
    else:
      with doc.tag('span',klass='metadata'):
        if style:
          doc.attr(style=style)
        doc.asis(self.get_value(metadata))
    return doc.getvalue()
Example #33
0
 def to_html(self):
   """Convert self data to its html stream."""
   if self.number > 0:
     doc = Doc()
     with doc.tag('div', klass='columns'):
       for col, column in enumerate(self.columns):
         with doc.tag('div', klass='column'):
           doc.attr(('column-number', str(col + 1)))
           style = 'display:block;float:left;'
           if column[1]:
             style += column[1]
           else:
             style += 'width:' + str(int(100.0 / self.number)) + '%;'
           doc.attr(style=style)
           doc.asis(markdown2html(source=column[0]))
     return doc.getvalue()
   return ''
Example #34
0
File: note.py Project: nunb/MaTiSSe
 def to_html(self):
     """Convert self data to its html stream."""
     doc = Doc()
     with doc.tag("div", id="note-" + str(self.number)):
         if self.style:
             doc.attr(style=self.style)
         else:
             doc.attr(klass="note")
         if self.cap_position is None or self.cap_position.upper() == "TOP":
             self.put_caption(doc=doc, klass="note-caption")
         with doc.tag("div", klass="note-content"):
             if self.ctn_options:
                 doc.attr(style=self.ctn_options)
             doc.asis(markdown2html(self.ctn, no_p=True))
         if self.cap_position is not None and self.cap_position.upper() == "BOTTOM":
             self.put_caption(doc=doc, klass="note-caption")
     return doc.getvalue()
Example #35
0
 def to_html(self):
   """Convert self data to its html stream."""
   doc = Doc()
   with doc.tag('div', id='table-' + str(self.number)):
     if self.style:
       doc.attr(style=self.style)
     else:
       doc.attr(klass='table')
     if self.cap_position is None or self.cap_position.upper() == 'TOP':
       self.put_caption(doc=doc, klass='table-caption')
     with doc.tag('div', klass='table-content'):
       if self.ctn_options:
         doc.attr(style=self.ctn_options)
       doc.asis(markdown2html(self.ctn, no_p=True))
     if self.cap_position is not None and self.cap_position.upper() == 'BOTTOM':
       self.put_caption(doc=doc, klass='table-caption')
   return doc.getvalue()
Example #36
0
 def to_html(self):
   """Convert self data to its html stream."""
   if self.number > 0:
     doc = Doc()
     with doc.tag('div', klass='columns'):
       for col, column in enumerate(self.columns):
         with doc.tag('div', klass='column'):
           doc.attr(('column-number', str(col + 1)))
           style = 'display:block;float:left;'
           if column[1]:
             style += column[1]
           else:
             style += 'width:' + str(int(100.0 / self.number)) + '%;'
           doc.attr(style=style)
           doc.asis(markdown2html(source=column[0]))
     return doc.getvalue()
   return ''
Example #37
0
  def to_html(self, config):
    """Generate a html stream of the whole presentation.

    Parameters
    ----------
    config : MatisseConfig
      MaTiSSe configuration
    """
    doc, tag, text = Doc().tagtext()
    doc.asis('<!DOCTYPE html>')
    with tag('html'):
      # doc.attr(title=self.metadata['title'].value)
      self.__put_html_tag_head(doc=doc, tag=tag, text=text, config=config)
      with tag('body', onload="resetCountdown(" + str(self.metadata['max_time'].value) + ");"):
        doc.attr(klass='impress-not-supported')
        with tag('div', id='impress'):
          # numbering: [local_chap, local_sec, local_subsec, local_slide]
          current = [0, 0, 0, 0]
          for chapter in self.chapters:
            current[0] += 1
            current[1] = 0
            current[2] = 0
            current[3] = 0
            self.metadata['chaptertitle'].update_value(value=chapter.title)
            self.metadata['chapternumber'].update_value(value=chapter.number)
            for section in chapter.sections:
              current[1] += 1
              current[2] = 0
              current[3] = 0
              self.metadata['sectiontitle'].update_value(value=section.title)
              self.metadata['sectionnumber'].update_value(value=section.number)
              for subsection in section.subsections:
                current[2] += 1
                current[3] = 0
                self.metadata['subsectiontitle'].update_value(value=subsection.title)
                self.metadata['subsectionnumber'].update_value(value=subsection.number)
                for slide in subsection.slides:
                  current[3] += 1
                  self.metadata['slidetitle'].update_value(value=slide.title)
                  self.metadata['slidenumber'].update_value(value=slide.number)
                  with doc.tag('div'):
                    chapter.put_html_attributes(doc=doc)
                    section.put_html_attributes(doc=doc)
                    subsection.put_html_attributes(doc=doc)
                    slide.put_html_attributes(doc=doc)
                    self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='header', current=current, overtheme=slide.overtheme)
                    # with doc.tag('div'):
                      # doc.attr(style='clear: both;')
                    self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='L', current=current, overtheme=slide.overtheme)
                    slide.to_html(doc=doc, parser=self.parser, metadata=self.metadata, theme=self.theme, current=current)
                    self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='R', current=current, overtheme=slide.overtheme)
                    # with doc.tag('div'):
                      # doc.attr(style='clear: both;')
                    self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='footer', current=current, overtheme=slide.overtheme)
        self.__put_html_tags_scripts(doc=doc, tag=tag, config=config)
    # source = re.sub(r"<li>(?P<item>.*)</li>", r"<li><span>\g<item></span></li>", source)
    html = indent(doc.getvalue())
    return html
Example #38
0
  def timer_to_html(self, match, max_time):
    """Convert custom metadata to html stream.

    Parameters
    ----------
    match: re.match object
    max_time: str

    Returns
    -------
    str:
      html stream
    """
    doc = Doc()
    with doc.tag('span', klass='timercontainer'):
      style = None
      if match.group('style'):
        style = str(match.group('style'))
      if style:
        doc.attr(style=style)
      with doc.tag('div', klass='countDown'):
        with doc.tag('div'):
          doc.attr(klass='timer')
        if style:
          if 'controls' in style:
            with doc.tag('div', klass='timercontrols'):
              with doc.tag('input', type='button'):
                doc.attr(klass='btn reset', onclick='resetCountdown(' + str(max_time) + ');', value=' &#10227; ', title='reset')
              with doc.tag('input', type='button'):
                doc.attr(klass='btn stop', onclick='stopCountdown();', value=' &#9724; ', title='pause')
              with doc.tag('input', type='button'):
                doc.attr(klass='btn start', onclick='startCountdown();', value=' &#9654; ', title='start')
    return doc.getvalue().replace('amp;', '')
Example #39
0
 def to_html(self):
   """Convert self data to its html stream."""
   doc = Doc()
   with doc.tag('div', id='Figure-' + str(self.number)):
     if self.style:
       doc.attr(style=self.style)
     else:
       doc.attr(klass='figure')
     with doc.tag(self.ctn_type):
       if self.cap_position is not None and self.cap_position.upper() == 'TOP':
         self.put_caption(doc=doc, klass='figure-caption')
       if self.ctn_options:
         doc.stag('img', src=self.ctn, klass='figure-content', style=self.ctn_options, alt='Figure-' + self.ctn)
       else:
         doc.stag('img', src=self.ctn, klass='figure-content', style='width:100%;', alt='Figure-' + self.ctn)
       if self.cap_position is None or self.cap_position.upper() == 'BOTTOM':
         self.put_caption(doc=doc, klass='figure-caption')
   return doc.getvalue()
Example #40
0
 def to_html(self):
   """Method for inserting box to the html doc."""
   doc = Doc()
   with doc.tag('div',klass='figure'):
     doc.attr(('id','Figure-'+str(self.number)))
     if self.style:
       doc.attr(style=self.style)
     elif Figure.theme.data.data['style'][0]:
       doc.attr(style=Figure.theme.data.data['style'][0])
     with doc.tag(self.ctn_type):
       if self.ctn_options:
         doc.stag('img',src=self.ctn,klass='image',style=self.ctn_options,alt='Figure-'+self.ctn)
       elif Figure.theme.data.data['content'][0]:
         doc.stag('img',src=self.ctn,klass='image',style=Figure.theme.data.data['content'][0],alt='Figure-'+self.ctn)
       else:
         doc.stag('img',src=self.ctn,klass='image',style='width:100%;',alt='Figure-'+self.ctn)
       self.put_caption(doc=doc)
   return doc.getvalue()
Example #41
0
 def to_html(self):
   """Convert self data to its html stream."""
   doc = Doc()
   with doc.tag('div', id='video-' + str(self.number)):
     if self.style:
       doc.attr(style=self.style)
     else:
       doc.attr(klass='video')
     if self.cap_position is not None and self.cap_position.upper() == 'TOP':
       self.put_caption(doc=doc, klass='video-caption')
     with doc.tag('video', klass='video-content', controls=''):
       if self.ctn_options:
         doc.attr(style=self.ctn_options)
       else:
         doc.attr(style='width:100%;')
       doc.stag('source', src=self.ctn)
     if self.cap_position is None or self.cap_position.upper() == 'BOTTOM':
       self.put_caption(doc=doc, klass='video-caption')
   return doc.getvalue()
Example #42
0
 def to_html(self):
   """Method for inserting columns to the html doc."""
   if self.number > 0:
     doc = Doc()
     with doc.tag('div',klass='columns'):
       for col,column in enumerate(self.columns):
         with doc.tag('div',klass='column'):
           doc.attr(('column-number',str(col+1)))
           style = 'display:block;float:left;'
           if column[1]:
             style += column[1]
           else:
             style += 'width:'+str(int(100.0/self.number))+'%;'
           doc.attr(style=style)
           content = box_parse(column[0])
           content = figure_parse(content)
           content = table_parse(content)
           content = note_parse(content)
           doc.asis(seditor.md_convert(content))
     return doc.getvalue()
   return ''
Example #43
0
 def to_html(self):
     """Method for inserting columns to the html doc."""
     if self.number > 0:
         doc = Doc()
         with doc.tag("div", klass="columns"):
             for col, column in enumerate(self.columns):
                 with doc.tag("div", klass="column"):
                     doc.attr(("column-number", str(col + 1)))
                     style = "display:block;float:left;"
                     if column[1]:
                         style += column[1]
                     else:
                         style += "width:" + str(int(100.0 / self.number)) + "%;"
                     doc.attr(style=style)
                     content = box_parse(column[0])
                     content = figure_parse(content)
                     content = table_parse(content)
                     content = note_parse(content)
                     doc.asis(seditor.md_convert(content))
         return doc.getvalue()
     return ""
Example #44
0
  def to_html(self,position,theme):
    """Method for converting slide content into html format.

    Parameters
    ----------
    position : SlidePosition object
      current slide position
    doc : yattag.Doc object
      the main html doc
    theme : Theme object
      the base theme
    """
    doc = Doc()
    with doc.tag('div'):
      self.put_attributes(doc=doc)
      # get slide positioning data
      actual_theme = None
      if self.overtheme:
        actual_theme = self.overtheme.slide
      else:
        actual_theme = theme
      position.set_position(theme=theme,overtheme=actual_theme)
      if self.title != '$overview':
        doc.attr(('class','step slide'))
        doc.attr(('data-x',str(position.position[0])))
        doc.attr(('data-y',str(position.position[1])))
        doc.attr(('data-z',str(position.position[2])))
        doc.attr(('data-scale',str(position.scale)))
        doc.attr(('data-rotate-x',str(position.rotation[0])))
        doc.attr(('data-rotate-y',str(position.rotation[1])))
        doc.attr(('data-rotate-z',str(position.rotation[2])))
        # inserting elements
        for header in actual_theme.loop_over_headers():
          header.to_html(doc=doc,metadata=self.data)
        for sidebar in actual_theme.loop_over_sidebars():
          if sidebar.position == 'L':
            sidebar.to_html(doc=doc,metadata=self.data)
        if self.number == 2:
          self.raw_body_parse()
        actual_theme.content.to_html(doc=doc,content='\n'+self.raw_body_parse())
        for sidebar in actual_theme.loop_over_sidebars():
          if sidebar.position == 'R':
            sidebar.to_html(doc=doc,metadata=self.data)
        for footer in actual_theme.loop_over_footers():
          footer.to_html(doc=doc,metadata=self.data)
      else:
        doc.attr(('class','step overview'))
        doc.attr(('style',''))
        doc.attr(('data-x','0'))
        doc.attr(('data-y','0'))
        doc.attr(('data-z','0'))
        doc.attr(('data-scale',str(position.scale)))
    return doc.getvalue()
Example #45
0
 def to_html(self):
     """Convert self data to its html stream."""
     doc = Doc()
     with doc.tag("div", id="video-" + str(self.number)):
         if self.style:
             doc.attr(style=self.style)
         else:
             doc.attr(klass="video")
         if self.cap_position is not None and self.cap_position.upper() == "TOP":
             self.put_caption(doc=doc, klass="video-caption")
         with doc.tag("video", klass="video-content"):
             if self.controls:
                 doc.attr(controls="controls")
             if self.autoplay:
                 doc.attr(autoplay="autoplay")
             if self.ctn_options:
                 doc.attr(style=self.ctn_options)
             else:
                 doc.attr(style="width:100%;")
             doc.stag("source", src=self.ctn)
         if self.cap_position is None or self.cap_position.upper() == "BOTTOM":
             self.put_caption(doc=doc, klass="video-caption")
     return doc.getvalue()
Example #46
0
  def metadata_to_html(self,metadata,style=None):
    """Method for converting slide level metadata to html.

    Parameters
    ----------
    metadata : str
      metadata key
    style : str, optional
      css style of metadata tag

    Returns
    -------
    str
      html string containing the metadata
    """
    doc = Doc()
    with doc.tag('span',klass='metadata'):
      if style:
        doc.attr(style=style)
      doc.asis(self.data[metadata])
    return doc.getvalue()
Example #47
0
  def custom_to_html(self, match):
    """Convert custom metadata to html stream.

    Parameters
    ----------
    match: re.match object

    Returns
    -------
    str:
      html stream
    """
    doc = Doc()
    with doc.tag('span', klass='metadata'):
      style = None
      if match.group('style'):
        style = str(match.group('style'))
      if style:
        doc.attr(style=style)
        doc.asis(re.search(r'value\:(?P<value>.*?)\;', style).group('value'))
    return doc.getvalue()
Example #48
0
File: toc.py Project: nunb/MaTiSSe
  def parse(self, source, current=None):
    """Method for substituting $toc with its pretty printed version.

    Parameters
    ----------
    source : str
      string (as single stream) containing the source
    current: list, optional
      list containing current section, and subsection number used
      for highlighting current slide into the TOC
    """
    parsed_source = source
    for match in re.finditer(__retoc__, parsed_source):
      deep = match.group('deep')
      if deep:
        deep = int(deep)
      doc = Doc()
      with doc.tag('div', klass='toc'):
        doc.asis(self.pstr(html=True, current=current, deep=deep))
      parsed_source = re.sub(__retoc__, lambda x: doc.getvalue(), parsed_source, 1)
      doc = None
    return parsed_source
Example #49
0
  def toc_to_html(self, match, current=None, depth=1):
    """Convert TOC to a plain string.

    Parameters
    ----------
    match: re.match()
    current: [current_chapter, current_section, current_subsection, current_slide]
      eventual current chpater-section-subsection-slide number
    depth: int
      depth of TOC: 4 => up-to slides, 3 => up-to subsections, 2 => up-to sections, 1 => only chapters

    Returns
    -------
    str:
      plain string of TOC
    """
    def get_style(match):
      """Get TOC style if one.

      Parameters
      ----------
      match: re.match()

      Returns
      -------
      str:
        style
      """
      style = None
      if match.group('style'):
        style = str(match.group('style'))
      return style

    def get_actual_depth(style, depth):
      """Get the actual depth of TOC using the eventual provided depth or the one defined into the style.

      Parameters
      ----------
      style: str
      depth: int
        depth of TOC: 4 => up-to slides, 3 => up-to subsections, 2 => up-to sections, 1 => only chapters

      Returns
      -------
      int:
        actual depth
      """
      actual_depth = int(depth)
      if style is not None:
        if 'depth' in style.lower():
          match_depth = re.search(r'depth\:(?P<depth>[1-4])\;*', style)
          if match_depth.group('depth'):
            actual_depth = int(match_depth.group('depth'))
      return actual_depth

    style = get_style(match=match)
    actual_depth = get_actual_depth(style=style, depth=depth)
    doc = Doc()
    # numbering: [local_chap, local_sec, local_subsec, local_slide, global_slide]
    actual_current = [0, 0, 0, 0, 1]
    with doc.tag('div', klass='toc'):
      if style is not None:
        doc.attr(style=style)
      self.toc_put_chapters(doc=doc,
                            depth=actual_depth,
                            actual_current=actual_current,
                            current=current)
    return '\n' + doc.getvalue()