当前位置: 首页>>代码示例>>Python>>正文


Python htmlmin.minify方法代码示例

本文整理汇总了Python中htmlmin.minify方法的典型用法代码示例。如果您正苦于以下问题:Python htmlmin.minify方法的具体用法?Python htmlmin.minify怎么用?Python htmlmin.minify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htmlmin的用法示例。


在下文中一共展示了htmlmin.minify方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_post_build

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def on_post_build(self, config):
        if self.config['minify_js']:
            jsfiles = self.config['js_files'] or []
            if not isinstance(jsfiles, list):
                jsfiles = [jsfiles]                                        
            for jsfile in jsfiles:
                # Minify
                input_filename = config['site_dir'] + '/' + jsfile
                if os.sep != '/':
                    input_filename = input_filename.replace(os.sep, '/')
                output_filename = input_filename.replace('.js','.min.js')
                minified = ''
                # Read original file and minify
                with open(input_filename) as inputfile:
                    minified = jsmin(inputfile.read())
                # Write minified output file
                with open(output_filename, 'w') as outputfile:
                    outputfile.write(minified)
                # Delete original file
                os.remove(input_filename)
        return config 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:23,代码来源:plugin.py

示例2: raw_scraper

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def raw_scraper(url, memoize):
    t1 = time.time()

    try:
        cleaner = Cleaner()
        cleaner.javascript = True
        cleaner.style = True
        article = newspaper.Article(url, fetch_images=False, memoize_articles=memoize)
        article.download()
        html = minify(article.html)
        html = cleaner.clean_html(html)
        article.parse()
    except:
        return None, None
    if article.text == "":
        return None, None

    metadata = {"url": url, "elapsed": time.time() - t1, "scraper": "raw"}
    return html, metadata 
开发者ID:jcpeterson,项目名称:openwebtext,代码行数:21,代码来源:scrapers.py

示例3: html_min

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def html_min(func):
    '''
    used as decorator to minify HTML string.
    Unused.
    '''

    def wrapper(*args):
        # return html_minify(func(*args))
        return minify(func(*args))

    return wrapper 
开发者ID:bukun,项目名称:TorCMS,代码行数:13,代码来源:tools.py

示例4: _generate_group_html_code

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def _generate_group_html_code(self, group):
        group_html = self.template.render(
            config=self.config,
            headers=group.get_headers(),
            contents=group.get_contents(),
            group_id=group.get_id()
        )

        if (sys.version_info > (3, 0)):
            return minify(group_html, remove_empty_space=True, remove_comments=True)
        else:
            return minify(group_html.decode("utf-8"), remove_empty_space=True, remove_comments=True) 
开发者ID:yacir,项目名称:markdown-fenced-code-tabs,代码行数:14,代码来源:__init__.py

示例5: on_post_page

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def on_post_page(self, output_content, page, config):
        if self.config['minify_html']:
            opts = self.config['htmlmin_opts'] or {}
            for key in opts:
                if key not in ['remove_comments','remove_empty_space','remove_all_empty_space','reduce_boolean_attributes','remove_optional_attribute_quotes','conver_charrefs','keep_pre','pre_tags','pre_attr']:
                    print("htmlmin option " + key + " not recognized")
            return minify(output_content, opts)
        else:
            return output_content 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:11,代码来源:plugin.py

示例6: build

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def build(file_name):
    print("---")
    s = read_content(file_name)
    # Build to separate folders
    # out_file = "%s.html" % file_name if file_name == 'index' else "%s/index.html" % file_name
    # Build to the root
    out_file = "%s.html" % file_name
    with open(out_file, 'w') as f:
        f.write('<!-- Automatically generated by build.py from MarkDown files -->\n')
        f.write('<!-- Augmentarium | UMIACS | University of Maryland, College Park -->\n')
        f.write(htmlmin.minify(s, remove_empty_space=True)) 
开发者ID:SketchyScene,项目名称:SketchyScene,代码行数:13,代码来源:build.py

示例7: IntJsExtract

# 需要导入模块: import htmlmin [as 别名]
# 或者: from htmlmin import minify [as 别名]
def IntJsExtract(self, url, heads):
        """

        Parameters
        ----------
        url : str
            URL of the page from which data needs to be extracted.
            Note: This is the url of the page given as user input.
        heads : dict
            Headers needed to make request, given URL. 

        Raises
        ----------
        UnicodeDecodeError 
            Raise an error if the endcoding found in the page is unkown.
        """

        if url.startswith('http://') or url.startswith('https://'):
            if isSSL:
                req = requests.get(url, headers=heads, verify=False, timeout=15)
            else:
                req = requests.get(url, headers=heads, timeout=15)
        else:
            if isSSL:
                req = requests.get(
                    'http://' + url, headers=heads, verify=False, timeout=15)
            else:
                req = requests.get('http://' + url, headers=heads, timeout=15)

        print(termcolor.colored("Searching for Inline Javascripts.....",
                                color='yellow', attrs=['bold']))

        try:
            html = unquote(req.content.decode('unicode-escape'))
            minhtml = htmlmin.minify(html, remove_empty_space=True)
            minhtml = minhtml.replace('\n', '')
            finallist.append(minhtml)
            print(termcolor.colored(
                "Successfully got all the Inline Scripts.", color='blue', attrs=['bold']))
        except UnicodeDecodeError:
            print(termcolor.colored("Decoding error...",
                                    color='red', attrs=['bold'])) 
开发者ID:nsonaniya2010,项目名称:SubDomainizer,代码行数:44,代码来源:SubDomainizer.py


注:本文中的htmlmin.minify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。