コード例 #1
0
 def run(self):
     # ugly code is ugly! :P
     rv = [nodes.raw('', '<blockquote>\n', format='html')]
     rv.extend(LineBlock.run(self))
     if 'author' in self.options:
         author = nodes.raw(self.options['author'],
                            u'<span class="author">— ' +
                            self.options['author'] + '</span>',
                            format='html')
         rv.append(nodes.paragraph('', '', author))
         rv.append(nodes.raw('', '<div class="clear"></div>\n',
                             format='html'))
     rv.append(nodes.raw('', '</blockquote>\n', format='html'))
     return rv
コード例 #2
0
                with closing(urlopen(directives.uri(self.arguments[0]))) as fp:
                    html = BeautifulSoup(fp.read())
                try:
                    data['title'] = html.head.title.text
                except:
                    pass
            except Exception, err:
                raise self.error('Error in "%s" directive: %s' % (self.name,
                                                                  err))
        except Exception, err:
            raise self.error('Error in "%s" directive: %s' % (self.name, err))

        rv = []

        if data['type'] == 'photo':
            rv.append(nodes.raw('', '<div class="oembed oembed-photo">',
                                format='html'))
            rv.append(nodes.image(data['title'] or '', uri=data['url'],
                                  alt=data['title'] or '',
                                  width=str(data['width']),
                                  height=str(data['height'])))
            rv.append(nodes.raw('', '</div>', format='html'))
        elif data['type'] == 'rich':
            rv.append(nodes.raw('', data['html'], format='html',
                                classes=['oembed', 'oembed-rich']))
        elif data['type'] == 'video':
            rv.append(nodes.raw('', data['html'], format='html',
                                classes=['oembed', 'oembed-video']))
        elif data['type'] == 'link':
            uri = directives.uri(self.arguments[0])
            label = nodes.strong('Link: ', 'Link: ')
            link = nodes.reference(uri, data.get('title', uri), refuri=uri)