fork download
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from unicodedata import east_asian_width
  5.  
  6. text = u"""reStructuredText入門
  7. ******************
  8.  
  9. このセクションは、reStructuredText(reST)の考え方や文法についての短いイントロダクションです。Sphinxユーザがドキュ
  10. メントを作成するために十分な情報を提供します。reSTはシンプルに設計された、控えめなマークアップ言語ですので、理解するのにそれほど時間はか
  11. からないでしょう。
  12.  
  13. See also:
  14.  
  15. 本家 reStructuredTextユーザドキュメント
  16. このドキュメント中の参照リンクは、reSTのリファレンスの個々の要素の説明にリンクしています。
  17.  
  18.  
  19. 段落(パラグラフ)
  20. =========
  21.  
  22. 段落(>>:duref:`ref <paragraphs>`<<)はreSTドキュメントにおける、もっとも基本的な要素です。段落は1行以上の
  23. 空行で区切られた、シンプルなテキストの固まりです。 Pythonにおいてインデントが重要な意味を持つのと同様、reSTでもインデントは重要で
  24. す。同じ段落のすべての行は、インデントを同じ高さにそろえて、左揃えにしなければなりません。
  25. """
  26.  
  27. new_buff = ''
  28. for line in text.splitlines():
  29. line_width = 0
  30. for c in line:
  31. char_width = east_asian_width(c)
  32. if char_width in u'WFA':
  33. line_width += 2
  34. else:
  35. line_width += 1
  36.  
  37. if line_width > 60:
  38. new_buff += '\n' + c
  39. line_width = 1
  40. else:
  41. new_buff += c
  42. new_buff += '\n'
  43.  
  44. print new_buff
  45.  
Runtime error #stdin #stdout #stderr 0s 9024KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 44, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-17: ordinal not in range(128)