diff --git a/README.md b/README.md index 8a5ef4a..fc73c19 100644 --- a/README.md +++ b/README.md @@ -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 $\text{\LaTeX}$ formulas even if they are already cached. diff --git a/readme2tex/__main__.py b/readme2tex/__main__.py index 96a2909..061ace3 100644 --- a/readme2tex/__main__.py +++ b/readme2tex/__main__.py @@ -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: @@ -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 diff --git a/readme2tex/render.py b/readme2tex/render.py index 4055b21..62941bd 100644 --- a/readme2tex/render.py +++ b/readme2tex/render.py @@ -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 @@ -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' @@ -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))