Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token in application/ld+json in HTML (slimit parser error) #9

Open
gzzz opened this issue Dec 31, 2016 · 0 comments

Comments

@gzzz
Copy link

gzzz commented Dec 31, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant