原稿執筆日記

  • コード中の < や & が消えてしまう問題発生
  • CDATAで囲ったらダメかな?
HTMLParser.HTMLParseError: unknown declaration: 'CDATA[\n$x = ...

orz

  • &amp;にすればOK?→なんか表示されないしorz
>>> from HTMLParser import HTMLParser
>>> class Foo(HTMLParser):
...   def handle_data(self, data):
...     print repr(data)
... 
>>> Foo().feed("foo&amp;bar")
'foo'
'bar'

おお?区切られるということは別のハンドラが呼ばれてるってことか?

HTMLParser.handle_entityref(name)¶
This method is called to process a general entity reference of the form &name; where name is an general entity reference. It is intended to be overridden by a derived class; the base class implementation does nothing.

http://docs.python.org/library/htmlparser.html

あった!

>>> Foo.handle_entityref = lambda self, name: self.handle_data(name)
>>> Foo().feed("foo&amp;bar")
'foo'
'amp'
'bar'

OK、ということはコード中の&とかを実体参照に変えてhandle_entityrefで戻して出力すればいいわけね

  • ぎゃー空白が詰んでる
for($i = 0; $i<10; $i++){&shori();

あ、でもこれは僕がstripかけているのがいけないのか。空行を詰めるためにかけているstripがstrip()になってるのをstrip("\n")に変更。

ああーそででも

 }&yobu();

こうなっちまうわけか。空行を消すのは失策だなぁ。辞めてみたら空行だらけで見にくいかと思ったけど、むしろ見やすい気がするのでこれでいいや。


脚注の位置がずれる問題、これ画像のロードとのレースコンディションだな。$()ではドキュメントのロードを待つだけで、画像のロードはまたないか。そりゃそうか。


現時点でうまく入らなかったものはもう削除するしかあるまい。

C++の作者Bjarne Stroustrupも「構文に注意を向けがちだが、重要なのは構文ではなく意味論だ」と言っていますが(TODO:要出典。たぶんD&E)