Exemplo n.º 1
0
Arquivo: box.py Projeto: nunb/MaTiSSe
  def caption_txt(self):
    """Buildi caption text.

    Returns
    -------
    str
      caption text
    """
    if self.cap_type and self.cap:
      txt = self.cap_type + ' ' + str(self.number) + ': ' + markdown2html(source=self.cap, no_p=True)
    elif self.cap_type:
      txt = self.cap_type
    elif self.cap:
      txt = markdown2html(source=self.cap, no_p=True)
    return txt
Exemplo n.º 2
0
    def caption_txt(self):
        """Buildi caption text.

    Returns
    -------
    str
      caption text
    """
        if self.cap_type and self.cap:
            txt = self.cap_type + ' ' + str(
                self.number) + ': ' + markdown2html(source=self.cap, no_p=True)
        elif self.cap_type:
            txt = self.cap_type
        elif self.cap:
            txt = markdown2html(source=self.cap, no_p=True)
        return txt
Exemplo n.º 3
0
    def to_html(self, doc, parser, metadata, current):
        """Generate html from self.

    Parameters
    ----------
    doc: Doc
    parser: Parser
    metatadata: dict
      presentation metadata
    current: list
    """
        def _parse_env(Env, re_search, source):
            codeblocks = parser.tokenizer(source=source,
                                          re_search=parser.regexs['codeblock'])
            codes = parser.tokenizer(source=source,
                                     re_search=parser.regexs['code'],
                                     exclude=codeblocks)
            yamlblocks = parser.tokenizer(source=source,
                                          re_search=parser.regexs['yamlblock'],
                                          exclude=codeblocks + codes)
            envs = parser.tokenizer(source=source,
                                    re_search=re_search,
                                    exclude=codeblocks + yamlblocks + codes)
            if len(envs) > 0:
                parsed_source = source[:envs[0]['start']]
                for e, env in enumerate(envs[:-1]):
                    current = Env(source=env['match'].group())
                    parsed_source += current.to_html(
                    ) + source[env['end']:envs[e + 1]['start']]
                current = Env(source=envs[-1]['match'].group())
                parsed_source += current.to_html() + source[envs[-1]['end']:]
                return parsed_source
            return source

        html = self.contents
        for meta in metadata:
            html = metadata[meta].parse(parser=parser,
                                        source=html,
                                        toc_depth=metadata['toc_depth'].value,
                                        max_time=metadata['max_time'].value,
                                        current=current)
        html = _parse_env(Env=Box, re_search=Box.regexs['box'], source=html)
        html = _parse_env(Env=Note, re_search=Note.regexs['note'], source=html)
        html = _parse_env(Env=Figure,
                          re_search=Figure.regexs['figure'],
                          source=html)
        html = _parse_env(Env=Table,
                          re_search=Table.regexs['table'],
                          source=html)
        html = _parse_env(Env=Video,
                          re_search=Video.regexs['video'],
                          source=html)
        html = _parse_env(Env=Columns,
                          re_search=Columns.regexs['columns'],
                          source=html)
        with doc.tag('div', klass='slide-content'):
            doc.asis(markdown2html(source=html))
        return
Exemplo n.º 4
0
  def to_html(self, doc, parser, metadata, theme, current):
    """Generate html from self.

    Parameters
    ----------
    doc: Doc
    parser: Parser
    metatadata: dict
      presentation metadata
    theme: Theme()
      presentation theme
    current: list
    """
    def _parse_env(Env, re_search, source):
      codeblocks = parser.tokenizer(source=source, re_search=parser.regexs['codeblock'])
      codes = parser.tokenizer(source=source, re_search=parser.regexs['code'], exclude=codeblocks)
      yamlblocks = parser.tokenizer(source=source, re_search=parser.regexs['yamlblock'], exclude=codeblocks + codes)
      envs = parser.tokenizer(source=source, re_search=re_search, exclude=codeblocks + yamlblocks + codes)
      if len(envs) > 0:
        parsed_source = source[:envs[0]['start']]
        for e, env in enumerate(envs[:-1]):
          current = Env(source=env['match'].group())
          parsed_source += current.to_html() + source[env['end']:envs[e + 1]['start']]
        if Env is Video:
          if self.overtheme.custom:
            current = Env(source=envs[-1]['match'].group(), theme=self.overtheme)
          else:
            current = Env(source=envs[-1]['match'].group(), theme=theme)
        else:
          current = Env(source=envs[-1]['match'].group())
        parsed_source += current.to_html() + source[envs[-1]['end']:]
        return parsed_source
      return source

    html = self.contents
    for meta in metadata:
      html = metadata[meta].parse(parser=parser, source=html, toc_depth=metadata['toc_depth'].value, max_time=metadata['max_time'].value, current=current)
    html = _parse_env(Env=Box, re_search=Box.regexs['box'], source=html)
    html = _parse_env(Env=Note, re_search=Note.regexs['note'], source=html)
    html = _parse_env(Env=Figure, re_search=Figure.regexs['figure'], source=html)
    html = _parse_env(Env=Table, re_search=Table.regexs['table'], source=html)
    html = _parse_env(Env=Video, re_search=Video.regexs['video'], source=html)
    html = _parse_env(Env=Columns, re_search=Columns.regexs['columns'], source=html)
    with doc.tag('div', klass='slide-content'):
      doc.asis(markdown2html(source=html))
    return
Exemplo n.º 5
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 ''
Exemplo n.º 6
0
Arquivo: note.py Projeto: 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()
Exemplo n.º 7
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()
Exemplo n.º 8
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()
Exemplo n.º 9
0
    def get_content(self, source):
        """Get box caption data.

    Parameters
    ----------
    source : str
      string (as single stream) containing the source
    """
        if self.ctn_type == 'figure' or self.ctn_type == 'video':
            match = re.search(Box.regexs['content_fig'], source)
        else:
            match = re.search(Box.regexs['content'], source)
        if match:
            ctn_type = match.group('ctn_type')
            if ctn_type:
                self.ctn_type = ctn_type.strip()
            ctn_options = match.group('ctn_options')
            if ctn_options:
                self.ctn_options = ctn_options.strip()
            self.ctn = match.group('ctn')
            if self.ctn:
                self.ctn = self.ctn.strip()
                self.ctn = markdown2html(source=self.ctn, no_p=True)
        return
Exemplo n.º 10
0
Arquivo: box.py Projeto: nunb/MaTiSSe
  def get_content(self, source):
    """Get box caption data.

    Parameters
    ----------
    source : str
      string (as single stream) containing the source
    """
    if self.ctn_type == 'figure' or self.ctn_type == 'video':
      match = re.search(Box.regexs['content_fig'], source)
    else:
      match = re.search(Box.regexs['content'], source)
    if match:
      ctn_type = match.group('ctn_type')
      if ctn_type:
        self.ctn_type = ctn_type.strip()
      ctn_options = match.group('ctn_options')
      if ctn_options:
        self.ctn_options = ctn_options.strip()
      self.ctn = match.group('ctn')
      if self.ctn:
        self.ctn = self.ctn.strip()
        self.ctn = markdown2html(source=self.ctn, no_p=True)
    return