Here are the examples of the python api django.utils.html taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
0
View Complete Implementation : fabfile.py
Copyright MIT License
Author : harvard-lil
Copyright MIT License
Author : harvard-lil
@task
def url_to_js_string(target_url="http://case.test:8000/maintenance/?no_toolbar", out_path="maintenance.html", new_domain="case.law"):
""" Save target URL and all astets as a single Javascript-endoded HTML string. """
import webpage2html
from urllib.parse import urljoin, urlparse
from mincss.processor import Processor
import re
from django.utils.html import escapejs
# prefill webpage2html with reduced css files from mincss, removing unused styles
p = Processor()
p.process_url(target_url)
p.process()
for astet in p.links:
href = urljoin(target_url, astet.href)
content = astet.after
content = re.sub(r'/\*.*?\*/', '', content, flags=re.S) # remove css comments
webpage2html.webpage2html_cache[href] = content
# use webpage2html to capture target_url as single string
data = webpage2html.generate(target_url)
data = data.replace("\n", "") # remove linebreaks
if new_domain:
# replace case.test:8000 with case.law
data = data.replace(urlparse(target_url).netloc, new_domain)
data = escapejs(data) # encode for storage in javascript
pathlib.Path(out_path).write_text(data)