Пример #1
0
    def pre_process(self):
        # Do heading and toc stuff here
        if self.arguments.has_key('level'):
            self.localvars['level'] = self.arguments['level']
        else:
            self.localvars['level'] = '2'
        G.debug(''.join(['Level set to ', self.localvars['level']]))

        if self.arguments.has_key('primary'):
            self.localvars['title'] = self.arguments['primary']
        G.debug(''.join(['Title set to ', self.localvars['title']]))

        # Store title to TOC
        if u'label' in self.arguments:
            self.localvars['safe_title'] = self.arguments[u'label']
            self.globalvars['$Labels'][self.arguments[u'label']] = {
                'id': self.localvars['safe_title'],
                'caption': getkey(self.localvars, 'title', 'title missing'),
            }
        else:
            self.localvars['safe_title'] = safe_link(
                getkey(self.localvars, 'title', 'title missing'))
        counter_tick(self.globalvars['$Counters'],
                     ''.join(['toc', str(self.localvars['level'])]))
        tocitem = {
            'safe_title':
            self.localvars['safe_title'],
            'link':
            '#%s' % self.localvars['safe_title'],
            'title':
            self.localvars['title'],
            'level':
            self.localvars['level'],
            'numbering':
            varsub(''.join(['%numbering', self.localvars['level'], '%']),
                   [self.globalvars], [])
        }
        self.localvars['numbering'] = tocitem['numbering']

        if (int(self.localvars['level']) <= int(
                getkey(self.globalvars, 'toc_depth', 3))):
            self.globalvars['$TOC'].append(tocitem)
        if (int(self.localvars['level']) <= int(
                getkey(self.globalvars, 'alt_toc_depth', 3))):
            self.globalvars['$ALTTOC'].append(tocitem)

        return True
Пример #2
0
    def pre_process(self):
        # Do heading and toc stuff here
        if self.arguments.has_key('level'):
            self.localvars['level'] = self.arguments['level']
        else:
            self.localvars['level'] = '2'
        G.debug(''.join(['Level set to ',self.localvars['level']]))
        
        if self.arguments.has_key('primary'):
            self.localvars['title'] = self.arguments['primary']
        G.debug(''.join(['Title set to ',self.localvars['title']]))
        
        # Store title to TOC
        if u'label' in self.arguments:
            self.localvars['safe_title'] = self.arguments[u'label']
            self.globalvars['$Labels'][self.arguments[u'label']] = {
                'id':  self.localvars['safe_title'],
                'caption': getkey(self.localvars,'title','title missing'),
            }
        else:
            self.localvars['safe_title'] = safe_link(
                getkey(self.localvars,'title','title missing'))
        counter_tick(self.globalvars['$Counters'],
                     ''.join(['toc',str(self.localvars['level'])]))
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': self.localvars['title'],
                    'level': self.localvars['level'],
                    'numbering': varsub(
                        ''.join(['%numbering',
                                 self.localvars['level'],
                                 '%']),
                        [self.globalvars],
                        [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        if (int(self.localvars['level']) <= 
            int(getkey(self.globalvars, 'toc_depth', 3))):
            self.globalvars['$TOC'].append(tocitem)
        if (int(self.localvars['level']) <= 
            int(getkey(self.globalvars, 'alt_toc_depth', 3))):
            self.globalvars['$ALTTOC'].append(tocitem)
        

        return True
Пример #3
0
    def pre_process(self):
        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'') 
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars['$Figure'], 'mode',u'')
        if not filename:
            mode = 'inline'
        else:
            mode = 'normal'
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')
        self.localvars['safe_title'] = getkey(self.arguments, 
            'label', 'figure_'+safe_link(
                getkey(self.localvars,'title','untitled')))

        # Store title to TOC
        counter_tick(self.globalvars['$Counters'], 'figure')
                     
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': getkey(self.localvars, 'title', 'Untitled'),
                    'level': 1,
                    'section': '!!toc1!!',
                    'numbering': varsub('%numberingfigure%', [self.globalvars], [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOF'].append(tocitem)

        parts = filename.split('.')
        extension = parts[-1].lower()
        if self.arguments.get('format', False):
            self.localvars['format'] = self.arguments.get('format') 
        elif extension == 'png':
            self.localvars['format'] = 'image/png;base64'
        elif extension == 'jpg' or extension == 'jpeg':
            self.localvars['format'] = 'image/jpeg;base64'
        elif extension == 'gif':
            self.localvars['format'] = 'image/gif;base64'
        elif extension == 'svg':
            self.localvars['format'] = 'image/svg+xml;base64'
        else:
            G.warn('Unknown image format: '+extension)
            self.localvars['format'] = extension 

        indata = ''
        if not filename in getkey(self.globalvars,'$Base64Data',{}):
            # Caching
            # TODO This caching should be stored in css instead as well
            if mode == 'normal':
                try:
                    f = open(filename, 'r')
                    indata = f.read()
                except IOError:
                    G.error(''.join(['The image file "',filename,'" could not be opened.']))
            elif mode == 'inline':
                filename = self.localvars.get('safe_title')
                if not filename in getkey(self.globalvars,'$Base64Data',{}):
                    indata = self.content 
            if 'base64' in self.localvars.get('format'):
                data = base64.b64encode(indata)
            else:
                data = ''.join([s for s in indata.splitlines() if s])
            self.globalvars['$Base64Data'][filename] = data

        self.localvars['data'] = self.globalvars['$Base64Data'][filename]

        if not 'width' in self.arguments:
            self.localvars['width'] = self.globalvars['$Figure']['width']
Пример #4
0
    def pre_process(self):
        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'')
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars['$Figure'], 'mode',
                                            u'')
        if not filename:
            mode = 'inline'
        else:
            mode = 'normal'
        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')
        self.localvars['safe_title'] = getkey(
            self.arguments, 'label',
            'figure_' + safe_link(getkey(self.localvars, 'title', 'untitled')))

        # Store title to TOC
        counter_tick(self.globalvars['$Counters'], 'figure')

        tocitem = {
            'safe_title': self.localvars['safe_title'],
            'link': '#%s' % self.localvars['safe_title'],
            'title': getkey(self.localvars, 'title', 'Untitled'),
            'level': 1,
            'section': '!!toc1!!',
            'numbering': varsub('%numberingfigure%', [self.globalvars], [])
        }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOF'].append(tocitem)

        parts = filename.split('.')
        extension = parts[-1].lower()
        if self.arguments.get('format', False):
            self.localvars['format'] = self.arguments.get('format')
        elif extension == 'png':
            self.localvars['format'] = 'image/png;base64'
        elif extension == 'jpg' or extension == 'jpeg':
            self.localvars['format'] = 'image/jpeg;base64'
        elif extension == 'gif':
            self.localvars['format'] = 'image/gif;base64'
        elif extension == 'svg':
            self.localvars['format'] = 'image/svg+xml;base64'
        else:
            G.warn('Unknown image format: ' + extension)
            self.localvars['format'] = extension

        indata = ''
        if not filename in getkey(self.globalvars, '$Base64Data', {}):
            # Caching
            # TODO This caching should be stored in css instead as well
            if mode == 'normal':
                try:
                    f = open(filename, 'r')
                    indata = f.read()
                except IOError:
                    G.error(''.join([
                        'The image file "', filename, '" could not be opened.'
                    ]))
            elif mode == 'inline':
                filename = self.localvars.get('safe_title')
                if not filename in getkey(self.globalvars, '$Base64Data', {}):
                    indata = self.content
            if 'base64' in self.localvars.get('format'):
                data = base64.b64encode(indata)
            else:
                data = ''.join([s for s in indata.splitlines() if s])
            self.globalvars['$Base64Data'][filename] = data

        self.localvars['data'] = self.globalvars['$Base64Data'][filename]

        if not 'width' in self.arguments:
            self.localvars['width'] = self.globalvars['$Figure']['width']
Пример #5
0
    def pre_process(self):
        self.needs_rerun = not self.needs_rerun 

        self.arguments['caption'] = getkey(self.arguments, 'caption', u'')
        self.localvars['title'] = getkey(self.arguments, 'caption', 'Untitled')

        if not getkey(self.arguments, 'file'):
            self.arguments['file'] = getkey(self.arguments, 'primary', u'') 
        filename = getkey(self.arguments, 'file')
        if not getkey(self.arguments, 'mode'):
            self.arguments['mode'] = getkey(self.globalvars.get('$Table', {}), 'mode',u'')
        mode = self.arguments['mode']
        self.localvars['headers'] = self.arguments.get('headers', False) or self.globalvars.get('$Table', {}).get('headers', 'yes')

        # Store title to TOT (Table of Tables)
        self.localvars['safe_title'] = 'table_'+safe_link(
                getkey(self.localvars,'title','untitled'))
        counter_tick(self.globalvars['$Counters'], 'table')
                     
        tocitem = { 'safe_title': self.localvars['safe_title'],
                    'link': '#%s' % self.localvars['safe_title'],
                    'title': getkey(self.localvars, 'title', 'Untitled'),
                    'level': 1,
                    'section': '!!toc1!!',
                    'numbering': varsub('%numberingtable%', [self.globalvars], [])
                  }
        self.localvars['numbering'] = tocitem['numbering']

        self.globalvars['$TOT'].append(tocitem)

        data = ''
        # Caching
        # TODO This caching should be stored in css instead as well
        if mode == 'normal':
            try:
                f = open(filename, 'r')
                data = f.read()
            except IOError:
                G.error(''.join(['The image file "',filename,'" could not be opened.']))
        elif mode == 'inline':
            data = self.content 

        if not 'width' in self.arguments and 'width' in self.globalvars.get('$Table', []):
            self.localvars['width'] = self.globalvars.get('$Table', []).get('width')

        splitter = re.compile("[ ]{2,}")
        rows = []
        for (nr, line) in enumerate(data.splitlines()):
            if nr == 0:
                pass
            elif nr == 1 and self.localvars.get('headers', False) in ('1', 'yes'):
                headers = []
                for header in splitter.split(line):
                    headers.append({'text': header})
                self.localvars['$Headers'] = headers
            else:
                cells = []
                for cell in splitter.split(line):
                    cells.append({'text': cell})
                rows.append({'$Cells': cells})
        self.localvars['$Rows'] = rows