Python htmlmin.minify() Examples
The following are 7
code examples of htmlmin.minify().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
htmlmin
, or try the search function
.
Example #1
Source File: plugin.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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
Example #2
Source File: scrapers.py From openwebtext with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: tools.py From TorCMS with MIT License | 5 votes |
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
Example #4
Source File: __init__.py From markdown-fenced-code-tabs with MIT License | 5 votes |
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)
Example #5
Source File: plugin.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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
Example #6
Source File: build.py From SketchyScene with MIT License | 5 votes |
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))
Example #7
Source File: SubDomainizer.py From SubDomainizer with MIT License | 4 votes |
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']))