berniey / html5print Goto Github PK
View Code? Open in Web Editor NEWHTML5, CSS, Javascript Pretty Print
License: Other
HTML5, CSS, Javascript Pretty Print
License: Other
Error SyntaxError: Unexpected token (COLON, u':') at 1:33 between LexToken(STRING,u'"@context"',1,22) and LexToken(STRING,u'"http://schema.org"',1,35)
on valid JSON-LD markup in HTML.
#!/usr/bin/env python
# coding: utf8
from html5print import HTMLBeautifier
html = '''<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "name",
"url": "http://www.example.com/"
}
</script>
</body>
</html>'''
print HTMLBeautifier.beautify(html)
The result:
python prettify-json-ld-error.py
Traceback (most recent call last):
File "D:\\prettify-json-ld-error.py", line 21, in <module>
print HTMLBeautifier.beautify(html)
File "D:\python\lib\html5print\html5print.py", line 111, in beautify
html = JSBeautifier.beautifyTextInHTML(html, indent, encoding)
File "D:\python\lib\html5print\jsprint.py", line 127, in beautifyTextInHTML
cls.beautify, (indent,), indent)
File "D:\python\lib\html5print\utils.py", line 197, in _findAndReplace
lines = [thisIndent + l for l in bfunc(*params).splitlines()]
File "D:\python\lib\html5print\jsprint.py", line 93, in beautify
tree = parser.parse(decodeText(js))
File "D:\python\lib\slimit\parser.py", line 93, in parse
return self.parser.parse(text, lexer=self.lexer, debug=debug)
File "D:\python\lib\ply\yacc.py", line 265, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "D:\python\lib\ply\yacc.py", line 1047, in parseopt_notrack
tok = self.errorfunc(errtoken)
File "D:\python\lib\slimit\parser.py", line 116, in p_error
self._raise_syntax_error(token)
File "D:\python\lib\slimit\parser.py", line 89, in _raise_syntax_error
self.lexer.prev_token, self.lexer.token())
SyntaxError: Unexpected token (COLON, u':') at 1:20 between LexToken(STRING,u'"context"',1,11) and LexToken(STRING,u'"http://schema.org
"',1,22)
May be should ignore scripts what cannot be parsed or use JSON-LD parser?
I'm getting "TypeError: argument of type 'module' is not iterable" when trying to run this code.
http://pastebin.com/mvx4kYyL
I am install html5print but occur an error as below
"pip install html5print
Collecting html5print
Using cached html5print-0.1.1.tar.gz
Collecting beautifulsoup4>=4.3.2 (from html5print)
Using cached beautifulsoup4-4.4.1-py3-none-any.whl
Collecting chardet>=2.2.1 (from html5print)
Using cached chardet-2.3.0.tar.gz
Collecting html5lib>=0.999 (from html5print)
Using cached html5lib-0.9999999.tar.gz
Collecting requests>=2.3.5 (from html5print)
Using cached requests-2.9.1-py2.py3-none-any.whl
Collecting slimit>=0.8.1 (from html5print)
Using cached slimit-0.8.1.zip
Collecting tinycss2>=0.4 (from html5print)
Using cached tinycss2-0.5.tar.gz
Collecting ply==3.4 (from html5print)
Using cached ply-3.4.tar.gz
Requirement already satisfied (use --upgrade to upgrade): six in ./v3env/lib/python3.4/site-packages (from html5lib>=0.999->html5print)
Collecting webencodings>=0.4 (from tinycss2>=0.4->html5print)
Using cached webencodings-0.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-dha2bzr1/webencodings/setup.py", line 8, in
).read().strip()).group(1)
File "/opt/projects/v3env/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1663: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dha2bzr1/webencodings/
"
Please tell me how to fix? Thanks
How to use this lib as standalone? Without pip install or etc.
The string sys.version
should not be used to determine the current Python version as there is no guarantee the version number is at the beginning of the string. Instead, the tuple sys.version_info
should be used (which you do in some cases but not everywhere).
from html5print import HTMLBeautifier
Traceback (most recent call last):
File "", line 1, in
File "/home/XXXXX/.local/lib/python3.9/site-packages/html5print/init.py", line 20, in
from .jsprint import JSBeautifier
File "/home/XXXXX/.local/lib/python3.9/site-packages/html5print/jsprint.py", line 22, in
import slimit
File "/home/XXXXX/.local/lib/python3.9/site-packages/slimit/init.py", line 27, in
from minifier import minify
ModuleNotFoundError: No module named 'minifier'
Addon error: Traceback (most recent call last):
File "recordTraffic.py", line 134, in response
outFile.write(JSBeautifier.beautify(flow.response.content.decode(charSet), 2))
File "C:\bin\Python-3.10.4\lib\site-packages\html5print\jsprint.py", line 93, in beautify
tree = parser.parse(decodeText(js))
File "C:\bin\Python-3.10.4\lib\site-packages\slimit\parser.py", line 93, in parse
return self.parser.parse(text, lexer=self.lexer, debug=debug)
File "C:\bin\Python-3.10.4\lib\site-packages\ply\yacc.py", line 265, in parse
return self.parseopt_notrack(input,lexer,debug,tracking,tokenfunc)
File "C:\bin\Python-3.10.4\lib\site-packages\ply\yacc.py", line 971, in parseopt_notrack
p.callable(pslice)
File "C:\bin\Python-3.10.4\lib\site-packages\slimit\parser.py", line 1101, in p_case_block
p[0] = p[2:-1]
File "C:\bin\Python-3.10.4\lib\site-packages\ply\yacc.py", line 198, in __getitem__
if n >= 0: return self.slice[n].value
TypeError: '>=' not supported between instances of 'slice' and 'int'
I am using html5print to pretty print JS code in an MITMproxy addon
Hello sir.
I am trying html5print in django. It' seem good, but how can make html5print auto detect input language then return pretty code.
thanks man.
I have the following markup <p>This sentence end with a <a href="#">link</a>.</p>
. HTMLBeautifier.beautify() creates
<p>
This sentence end with a
<a href="#">
link
</a>
.
</p>
Which adds an additional space after the link.
As we tried in a simple HTML5 file and then we press Ctrl + P for print preview, the footer of the page cant be stuck to the bottom of the last page. in my print.
we have not decided on the number of pages in a single print but I need to stick my footer to the bottom of the last page doesn't matter how many pages are there in the print.
Framework: HTML5
How can i make unwrap long line of code (show on one line - scrollable).
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.