Skip to content

Commit 0cbdf9c

Browse files
committed
Fix argument parsing problems and add texify.sh
1 parent a7ff4b8 commit 0cbdf9c

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

readme2tex/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@
115115
parser.add_argument('--readme', nargs='?', type=str, help="The Markdown input file to render.")
116116
parser.add_argument('--engine', type=str, default="latex")
117117
parser.add_argument('--output', type=str, default="README_GH.md", help="The output file. Defaults to README_GH.md")
118-
parser.add_argument('--usepackage', type=list, action='append', default=['amsmath', 'amssymb'], help="Include a LaTeX package. Comes with amsmath and amssymb.")
119-
parser.add_argument('--svgdir', nargs=1, type=str, default='svgs', help="Name of the folder to save the output svgs into. Defaults to svgs.")
120-
parser.add_argument('--branch', nargs=1, type=str, help="[EXPERIMENTAL] Which branch to save the svgs into. Used by the git-hook system. Defaults to the current branch.")
121-
parser.add_argument('--username', nargs=1, type=str, help="Github username. Can be inferred.")
122-
parser.add_argument('--project', nargs=1, type=str, help="Github project. Can be inferred.")
118+
parser.add_argument('--usepackage', type=str, action='append', default=['amsmath', 'amssymb'], help="Include a LaTeX package. Comes with amsmath and amssymb.")
119+
parser.add_argument('--svgdir', type=str, default='svgs', help="Name of the folder to save the output svgs into. Defaults to svgs.")
120+
parser.add_argument('--branch', type=str, help="[EXPERIMENTAL] Which branch to save the svgs into. Used by the git-hook system. Defaults to the current branch.")
121+
parser.add_argument('--username', type=str, help="Github username. Can be inferred.")
122+
parser.add_argument('--project', type=str, help="Github project. Can be inferred.")
123123
parser.add_argument('--nocdn', action='store_true', help="Use local relative path rather than rawgit's CDN. Useful for debugging.")
124124
parser.add_argument('--htmlize', action='store_true', help="Output a md.html file for you to preview. Useful for debugging.")
125125
parser.add_argument('--valign', action='store_true', help="Use the valign attribute instead of the align=middle trick. Only works on Chrome.")
126126
parser.add_argument('--rerender', action='store_true', help="Even if equations have already been compiled, recompile them anyways.")
127127
parser.add_argument('--bustcache', action='store_true', help="Github has a latency before it will serve up the new asset. This option allows us to circumvent its caching.")
128128
parser.add_argument('--add-git-hook', action='store_true', help="Automatically generates a post-commit git hook with the rest of the arguments. In the future, git commit will automatically trigger readme2tex if the input file is changed.")
129-
parser.add_argument('--generate-script', nargs=1, help="Same as add-git-hook, but dumps it as a normal script")
129+
parser.add_argument('--generate-script', help="Same as add-git-hook, but dumps it as a normal script")
130130
parser.add_argument('input', nargs='?', type=str, help="Same as --readme")
131131

132132
args = parser.parse_args()

texify.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
bold=$(tput setaf bold)
4+
color=$(tput setaf 2)
5+
reset=$(tput sgr0)
6+
7+
branch=$(git rev-parse --abbrev-ref HEAD)
8+
9+
if [ "$branch" = "svgs" ]; then
10+
exit
11+
fi
12+
13+
# Check to see if READOTHER.md has been updated
14+
15+
changes=$(git diff --name-only HEAD^ | grep "READOTHER.md")
16+
readme=$(git diff --name-only HEAD^ | grep "README.md")
17+
18+
if [ -z "$changes" ]; then
19+
exit
20+
fi
21+
22+
if [ ! -z "$readme" ]; then
23+
exit
24+
fi
25+
26+
exec < /dev/tty
27+
28+
read -p "[readme2tex] ${color}READOTHER.md$reset has changed; would you like to update ${color}README.md$reset as well? This will run
29+
30+
> python -m readme2tex --output ${color}README.md$reset --readme ${color}READOTHER.md$reset --branch ${color}svgs$reset --svgdir 'svgs' --usepackage 'tikz' --usepackage 'xcolor'
31+
32+
Would you like to run this now? [Y/n]: " meh
33+
34+
if [ "$meh" = "" ]; then
35+
meh='Y'
36+
fi
37+
38+
case $meh in
39+
[Yy] ) ;;
40+
[Nn] ) exit;;
41+
* ) exit;;
42+
esac
43+
44+
tput setaf 3
45+
echo
46+
echo "Running readme2tex..."
47+
python -m readme2tex --output README.md --readme READOTHER.md --branch svgs --svgdir 'svgs' --usepackage 'tikz' --usepackage 'xcolor'
48+
echo $reset
49+
50+
if [ $? -eq 0 ]; then
51+
echo "Finished rendering."
52+
git add README.md
53+
echo
54+
read -p "Do you want to amend changes to ${color}README.md$reset now? [Y/n]: " amend
55+
if [ "$meh" = "" ]; then
56+
meh='Y'
57+
fi
58+
59+
case $meh in
60+
[Yy] ) ;;
61+
[Nn] ) exit;;
62+
* ) exit;;
63+
esac
64+
65+
echo
66+
echo "Amending commit...$color"
67+
git commit --amend --no-edit
68+
echo $reset
69+
echo "You should run '${bold}git push origin :${reset}' to push all branches simultaneously."
70+
echo
71+
else
72+
echo "$(tput setaf 1)Encountered error while translating READOTHER.md${reset}"
73+
exit 1
74+
fi

0 commit comments

Comments
 (0)