Skip to content

Commit

Permalink
Merge pull request #48 from nmtake/fix-table
Browse files Browse the repository at this point in the history
Fix broken table
  • Loading branch information
y-yu committed Aug 4, 2018
2 parents 33146ad + 40db6e5 commit ca70aeb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions python/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def filter(key, value, fmt, meta):
return RawInline('latex', value)
elif key == 'Code': # Code Attr String
value[1] = value[1].replace('\uFFFD', '?')
value[1] = value[1].replace('+CHARPIPE+', '|')
# \lstinline 内では LaTeX コマンドが使えないので \texttt を使う
if RE_SCRIPT.search(value[1]):
s = escape_tex(value[1])
Expand Down
20 changes: 20 additions & 0 deletions python/fix_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import re
import sys


for line in sys.stdin:
line = line.rstrip()
if re.search(r'[^-|]', line):
print(re.sub(r'<code>(.*?)</code>',
lambda m: '`%s`' % m.group(1).replace(r'\|', '+CHARPIPE+'),
line))
else:
ncols = len(re.findall(r'-+\|', line))
# http://pandoc.org/MANUAL.html#extension-pipe_tables
if ncols == 4: # Table B-1
print('|-|---|---|--|')
elif ncols == 2:
print('|-|---|')
else:
print(line)
17 changes: 12 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ if [[ ! -d "./target" ]]; then
mkdir target
fi

for f in ./book/second-edition/src/*.md
do
cp $f ./target/
echo $f
for f in book/second-edition/src/*.md; do
cp "$f" target/
echo "$f"
done

python3 python/fix_table.py < target/appendix-02-operators.md > target/tmp.md
mv target/tmp.md target/appendix-02-operators.md

for f in target/*.md; do
BASE=$(basename $f .md)
if [[ $BASE =~ appendix-(06|07)- ]]; then
FILTERS="--filter ./python/fix_headers.py --filter ./python/filter.py"
else
FILTERS="--filter ./python/filter.py"
fi
if [[ $BASE =~ appendix-02- ]]; then
COLUMNS="--columns=10"
fi
FILENAME="$BASE" pandoc -o "./target/$BASE.tex" -f markdown_github+footnotes+header_attributes-hard_line_breaks \
--pdf-engine=lualatex --top-level-division=chapter --listings $FILTERS $f
--pdf-engine=lualatex --top-level-division=chapter $COLUMNS --listings $FILTERS $f
done

python3 ./python/body.py < ./target/SUMMARY.md > body.tex

0 comments on commit ca70aeb

Please sign in to comment.