Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cdnurl option for specifying base address of images #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ In addition, you can specify other arguments to `render.py`, such as:
* `--username username` Your github username. This is optional, and `render.py` will try to infer this for you.
* `--project project` The current github project. This is also optional.
* `--nocdn` Ticking this will use relative paths for the output images. Defaults to False.
* `--cdnurl url` The CDN used for the images. Defaults to `https://cdn.jsdelivr.net/gh`.
* `--cdnrefsep sep` The separator used by the CDN to separate project and reference. Defaults to `@`.
* `--htmlize` Ticking this will output a `md.html` file so you can preview what the output looks like. Defaults to False.
* `--valign` Ticking this will use the `valign` trick (detailed below) instead. See the caveats section for tradeoffs.
* `--rerender` Ticking this will force a recompilation of all <img alt="$\text{\LaTeX}$" src="svgs/c068b57af6b6fa949824f73dcb828783.png?invert_in_darkmode" align=middle width="42.05817pt" height="22.407pt"/> formulas even if they are already cached.
Expand Down
6 changes: 5 additions & 1 deletion readme2tex/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@
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.")
parser.add_argument('--pngtrick', action='store_true', help="Convert output to png.")
parser.add_argument('input', nargs='?', type=str, help="Same as --readme")
parser.add_argument('--cdnurl', type=str, default='https://cdn.jsdelivr.net/gh', help="URL of the CDN to use. Defaults to https://cdn.jsdelivr.net/gh.")
parser.add_argument('--cdnrefsep', type=str, default='@', help="Separator between project and reference in CDN URL. Defaults to @.")

args = parser.parse_args()
if args.input:
Expand Down Expand Up @@ -159,7 +161,9 @@
args.valign,
args.rerender,
args.pngtrick,
args.bustcache)
args.bustcache,
args.cdnurl,
args.cdnrefsep)
else:

# Move ourselves to the root of the current repository
Expand Down
8 changes: 5 additions & 3 deletions readme2tex/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def render(
use_valign=False,
rerender=False,
pngtrick=False,
bustcache=False):
bustcache=False,
cdnurl='https://cdn.jsdelivr.net/gh'.
cdnrefsep='@'):
# look for $.$ or $$.$$
if htmlize:
nocdn = True
Expand Down Expand Up @@ -309,7 +311,7 @@ def render(
if nocdn:
svg_url = "{svgdir}/{name}.svg"
else:
svg_url = "https://cdn.jsdelivr.net/gh/{user}/{project}@{branch}/{svgdir}/{name}.svg"
svg_url = "{cdnurl}/{user}/{project}{cdnrefsep}{branch}/{svgdir}/{name}.svg"

if pngtrick:
svg_url = svg_url[:-4] + '.png'
Expand All @@ -325,7 +327,7 @@ def render(
scale = 1.65
height = float(attributes['height'][:-2]) * scale
width = float(attributes['width'][:-2]) * scale
url = svg_url.format(user=user, project=project, branch=branch, svgdir=svgdir, name=name)
url = svg_url.format(cdnurl=cdnurl, cdnrefsep=cdnrefsep, user=user, project=project, branch=branch, svgdir=svgdir, name=name)
tail = []
if bustcache:
tail.append('%x' % random.randint(0, 1e12))
Expand Down