Created
November 28, 2018 15:19
-
-
Save tk0miya/73022b32917bd1525bc74073dcdd1999 to your computer and use it in GitHub Desktop.
reST の gridtable で ambiguous multibytes character を使う
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reStructuredText のグリッドテーブルに一部の全角文字(◯などの記号やキリル文字など)を使うと Malformed table 扱いされてビルドできない。 | |
そこで、このコードでは docutils が処理する前の原稿をハックし、Ambiguous な文字にパディングを入れ込むようにした。 | |
かなりの dirty hack ではあるが、単純なテーブルが動くことは確認できた。 | |
詳しくはこちらのスライド参照。 | |
https://speakerdeck.com/anzawatta/sphinxfalseteburudequan-jiao-ji-hao-woshi-itai-sphinxcon-jp-2018-53c329a6-e71a-4200-9374-2568f0c172b5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pad_double_width_for_ambigious(c): | |
import unicodedata | |
from docutils.parsers.rst.tableparser import TableParser | |
if unicodedata.east_asian_width(c) in 'A': | |
return c + TableParser.double_width_pad_char | |
else: | |
return c | |
def on_source_read(app, docname, text): | |
padded = ''.join(pad_double_width_for_ambigious(c) for c in text[0]) | |
text[0] = padded | |
def setup(app): | |
app.connect('source-read', on_source_read) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment