Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Created November 28, 2018 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/73022b32917bd1525bc74073dcdd1999 to your computer and use it in GitHub Desktop.
Save tk0miya/73022b32917bd1525bc74073dcdd1999 to your computer and use it in GitHub Desktop.
reST の gridtable で ambiguous multibytes character を使う
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
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