From d97068e8314ce7f5f6b4ca3767dd57251251dd8f Mon Sep 17 00:00:00 2001
From: pvogt09 <50047961+pvogt09@users.noreply.github.com>
Date: Mon, 3 Aug 2020 21:30:10 +0200
Subject: [PATCH 1/2] adds cdnurl option for specifying base address of images
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
---
README.md | 1 +
readme2tex/__main__.py | 4 +++-
readme2tex/render.py | 7 ++++---
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 8a5ef4a..926e413 100644
--- a/README.md
+++ b/README.md
@@ -155,6 +155,7 @@ 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`.
* `--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
formulas even if they are already cached.
diff --git a/readme2tex/__main__.py b/readme2tex/__main__.py
index 96a2909..88e9f67 100644
--- a/readme2tex/__main__.py
+++ b/readme2tex/__main__.py
@@ -131,6 +131,7 @@
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.")
args = parser.parse_args()
if args.input:
@@ -159,7 +160,8 @@
args.valign,
args.rerender,
args.pngtrick,
- args.bustcache)
+ args.bustcache,
+ args.cdnurl)
else:
# Move ourselves to the root of the current repository
diff --git a/readme2tex/render.py b/readme2tex/render.py
index 4055b21..973510b 100644
--- a/readme2tex/render.py
+++ b/readme2tex/render.py
@@ -127,7 +127,8 @@ def render(
use_valign=False,
rerender=False,
pngtrick=False,
- bustcache=False):
+ bustcache=False,
+ cdnurl='https://cdn.jsdelivr.net/gh'):
# look for $.$ or $$.$$
if htmlize:
nocdn = True
@@ -309,7 +310,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}/{branch}/{svgdir}/{name}.svg"
if pngtrick:
svg_url = svg_url[:-4] + '.png'
@@ -325,7 +326,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, user=user, project=project, branch=branch, svgdir=svgdir, name=name)
tail = []
if bustcache:
tail.append('%x' % random.randint(0, 1e12))
From 4b9eaf295d3da2b3fdd3d9a07776d3d084fb1c0a Mon Sep 17 00:00:00 2001
From: pvogt09 <50047961+pvogt09@users.noreply.github.com>
Date: Tue, 4 Aug 2020 19:12:46 +0200
Subject: [PATCH 2/2] adds cdnrefsep option for specifying separator between
project and ref
Signed-off-by: pvogt09 <50047961+pvogt09@users.noreply.github.com>
---
README.md | 1 +
readme2tex/__main__.py | 4 +++-
readme2tex/render.py | 7 ++++---
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 926e413..fc73c19 100644
--- a/README.md
+++ b/README.md
@@ -156,6 +156,7 @@ In addition, you can specify other arguments to `render.py`, such as:
* `--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
formulas even if they are already cached.
diff --git a/readme2tex/__main__.py b/readme2tex/__main__.py
index 88e9f67..061ace3 100644
--- a/readme2tex/__main__.py
+++ b/readme2tex/__main__.py
@@ -132,6 +132,7 @@
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:
@@ -161,7 +162,8 @@
args.rerender,
args.pngtrick,
args.bustcache,
- args.cdnurl)
+ 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 973510b..62941bd 100644
--- a/readme2tex/render.py
+++ b/readme2tex/render.py
@@ -128,7 +128,8 @@ def render(
rerender=False,
pngtrick=False,
bustcache=False,
- cdnurl='https://cdn.jsdelivr.net/gh'):
+ cdnurl='https://cdn.jsdelivr.net/gh'.
+ cdnrefsep='@'):
# look for $.$ or $$.$$
if htmlize:
nocdn = True
@@ -310,7 +311,7 @@ def render(
if nocdn:
svg_url = "{svgdir}/{name}.svg"
else:
- svg_url = "{cdnurl}/{user}/{project}/{branch}/{svgdir}/{name}.svg"
+ svg_url = "{cdnurl}/{user}/{project}{cdnrefsep}{branch}/{svgdir}/{name}.svg"
if pngtrick:
svg_url = svg_url[:-4] + '.png'
@@ -326,7 +327,7 @@ def render(
scale = 1.65
height = float(attributes['height'][:-2]) * scale
width = float(attributes['width'][:-2]) * scale
- url = svg_url.format(cdnurl=cdnurl, 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))