當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。