Comments (9)
Based on my experiments, the following pre-commit hook solves the issue (in an improvised manner). It essentially re-creates the link to the svg files as local files on your github. This is assuming you have a folder named "svgs" on your master branch. It also removes centering, which is a personal preference.
Lastly, it removes svgs in your svgs/ folder that are not being used in your README.md. This ensures only necessary files are present on your repository.
To use this file, essentially copy its contents to a file named "pre-commit" within your local repository's /.git/hooks directory.
Hope this helps!
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
b=$(find README.md 2>/dev/null)
c=$(find svgs/ 2>/dev/null)
if [ ${#b} -gt 0 ] && [ ${#c} -gt 0 ]
then
# to remove centering of images, this is a personal preference
sed -i "s| align=\"center\"||g" README.md
# these help to remove the faulty links
sed -i "s|img src=.*/svgs|img src=\"/svgs|g" README.md
sed -i "s|\?invert\_in\_darkmode||g" README.md
# find all used svgs
svgs=$(cat README.md | grep -oP "/svgs.*.svg" | sed "s|/svgs/||g")
# find svgs to delete
del=$(find svgs/*.svg | grep -v "$svgs")
# if more than 0, delete unused svgs
if [ ${#del} -gt 0 ]
then
rm $del
fi
git add .
fi
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)
# Redirect output to stderr.
exec 1>&2
# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi
# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --
from readme2tex.
Hello @JARVIS-AI,
Yes, the rawgit service is ending or has ended (https://rawgit.com/), so this creates an issue with the images not being displayed.
As a work around, I edit the links after running readme2tex on my README.md, such that the SVGs are displayed locally on GitHub without the rawgit link.
While waiting for an internal bug fix, I could recommend that we use a pre-commit hook which can edit the links for us. I will test it out and post a version here.
from readme2tex.
Thanks for a temp script or fix thanks
Hope the new version be out with full fix
I will test the shell script and give the result
from readme2tex.
This is still an issue. One workaround is to use the following, with the latest version of this package:
python3 -m readme2tex --branch master --nocdn --readme INPUT.md --output README.md
from readme2tex.
sed -i "s|img src=.*/svgs|img src=\"/svgs|g" README.md sed -i "s|\?invert\_in\_darkmode||g" README.md # find all used svgs svgs=$(cat README.md | grep -oP "/svgs.*.svg" | sed "s|/svgs/||g")
I found that the following regular expressions worked better, when combined with --nocdn
. Fixes a problem when having multiple images on the same line.
sed -i "s|img src=\"\([^/]\)|img src=\"/\1|g" README.md
sed -i "s|\?invert\_in\_darkmode||g" README.md
# find all used svgs
svgs=$(cat README.md | grep -oP "/svgs.*?.svg" | sed "s|/svgs/||g")
from readme2tex.
Here is an example of my URL in rawgit
Here is broken
The above link give me this error : Invalid upstream response (403)
from readme2tex.
One question :
Can the readme2tex make the svgs url locally
For e.g :
when I render the file
The url of svg being like this :
If this can be done we don't need any online services and I think it will work on github too
from readme2tex.
For ‘’nocdn’’
Yes it worked for times
Needed to be updated for another cdn or self services server for better work any where not just locally or offline
from readme2tex.
Also you probably don't want to do
git add .
but instead
git add svgs/ README.md
from readme2tex.
Related Issues (20)
- Exception for latex in code snippets
- UnicodeDecodeError
- No such file or directory: 'dvisvgm' HOT 1
- Recording has been archived in README
- How can use readme2tex over multiple files?
- [Feature suggestion] turn this into a github action HOT 4
- Support for persistent newcommand definitions HOT 1
- Support for unicode
- '$' in code blocks
- gfill is NoneType HOT 1
- Remotes that are ssh instead of http
- Possible to run without being in a git repo? HOT 4
- New line in math block
- [Possible bug report] - Proceeding tab HOT 2
- 503: invalid upstream response
- Dark theme issues HOT 2
- Inline equations will insert newlines HOT 1
- 403 Forbidden...? HOT 1
- Error executing subprocess.CalledProcessError dvisvgm HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from readme2tex.