ingwinlu / pelican-toc

generates a table of contents for pelican articles and pages
GNU General Public License v2.0
14 stars 19 forks source link

Error when generating ToC - Windows #1

Closed fuzzmz closed 9 years ago

fuzzmz commented 9 years ago

Every time I try publishing an article containing a ToC I get an error. This is on Windows, running Python 2.7.4.

For example, when trying to publish the example article:

Title: Peeking at erlang/chicagoboss
###Intro
###Chicagoboss Magic
###Result

I get the following error:

DEBUG: Read file test.md -> Article
ERROR: Could not process .\test.md
  | 'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in range(128)
  |___
  | Traceback (most recent call last):
  |   File "d:\repos\pelican_blog\venv\lib\site-packages\pelican\generators.py", line 502, in generate_context
  |     context_sender=self)
  |   File "d:\repos\pelican_blog\venv\lib\site-packages\pelican\readers.py", line 492, in read_file
  |     context=context)
  |   File "d:\repos\pelican_blog\venv\lib\site-packages\pelican\contents.py", line 143, in __init__
  |     signals.content_object_init.send(self)
  |   File "d:\repos\pelican_blog\venv\lib\site-packages\blinker\base.py", line 267, in send
  |     for receiver in self.receivers_for(sender)]
  |   File "D:\repos\pelican_blog\pelican-plugins-custom\toc\toc.py", line 100, in generate_toc
  |     content.toc = BeautifulSoup(tree.toString()).decode(formatter="html")
  |   File "D:\repos\pelican_blog\pelican-plugins-custom\toc\toc.py", line 80, in toString
  |     ret = ret + child.toString()
  |   File "D:\repos\pelican_blog\pelican-plugins-custom\toc\toc.py", line 76, in toString
  |     ret = ret + "<li><a class='toc-href' href='#{0}' title='{1}'>{1}</a>".format(self.id, self.header)
  | UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in range(128)

If I use the following as an article then everything gets published correctly:

Title: Peeking at erlang/chicagoboss
###Intro
ingwinlu commented 9 years ago

hi @fuzzmz

can you try to add from __future__ import unicode_literals and see if thats enough. Else i will have to make you wait till next month for a fix.

issue here is the mix of formatting when using python2.

fuzzmz commented 9 years ago

Yes, that seems to have fixed it. Thanks!