示例#1
0
def process_media(content):
    if not isinstance(content, contents.Article):
        return

    content_dir = content.settings['PATH']

    if hasattr(content, 'image'):
        width, height = check_img_src(content.image,
                                      content_dir,
                                      max_px=content.settings['IMG_MAX_PX'],
                                      max_mb=content.settings['IMG_MAX_MB'])
        content.image_width, content.image_height = width, height
        content.metadata.update(image_width=width, image_height=height)

    with modify_html(content) as html_tree:
        for iframe in html_tree.xpath('//iframe'):
            iframe_to_figure(iframe)

        for object_ in html_tree.xpath('//object'):
            object_to_figure(object_)

        for blockquote in html_tree.xpath('//blockquote'):
            tweet_to_figure(blockquote)

        for img in html_tree.xpath('//p[count(img) = 1]/img'):
            img_to_figure(img, content_dir)

        for img in html_tree.xpath('//img'):
            check_img_src(img.get('src'),
                          content_dir,
                          max_px=content.settings['IMG_MAX_PX'],
                          max_mb=content.settings['IMG_MAX_MB'])
示例#2
0
def process_code_blocks(content):
    if not isinstance(content, contents.Article):
        return

    with modify_html(content) as html_tree:
        for pre in html_tree.findall('.//div/pre'):
            pre.getparent().tag = 'pre'
            pre.tag = 'code'
示例#3
0
def enhance_headings(content):
    if not isinstance(content, contents.Article):
        return

    with modify_html(content) as html_tree:
        for query in ['.//h1[@id]', './/h2[@id]', './/h3[@id]', './/h4[@id]']:
            for heading in html_tree.findall(query):
                add_permalink(heading, TITLES[content.lang])
示例#4
0
def enhance_tables(content):
    if not isinstance(content, contents.Article):
        return

    with modify_html(content) as html_tree:
        for table in html_tree.findall('.//table'):
            div = etree.Element('div')
            div.set('class', 'table')
            wrap_element(table, div)
示例#5
0
def process_media(content):
    if not isinstance(content, contents.Article):
        return

    with modify_html(content) as html_tree:
        content_dir = content.settings['PATH']

        for iframe in html_tree.xpath('//iframe'):
            iframe_to_figure(iframe)

        for object_ in html_tree.xpath('//object'):
            object_to_figure(object_)

        for blockquote in html_tree.xpath('//blockquote'):
            tweet_to_figure(blockquote)

        for img in html_tree.xpath('//p[count(img) = 1]/img'):
            img_to_figure(img, content_dir)

        for img in html_tree.xpath('//img'):
            check_img(img, content_dir, dict(
                max_px=content.settings['IMG_MAX_PX'],
                max_mb=content.settings['IMG_MAX_MB'],
            ))