readme2tex icon indicating copy to clipboard operation
readme2tex copied to clipboard

Rawgit URL not work anymore

Open JARVIS-AI opened this issue 7 years ago • 9 comments

I don't know why but my math repo was working and I was making ready for my student and teachers in university but that day none of svgs worked

After that I found that rawgit is ended, Can you see it, maybe I'm wrong ?!!

If it's true can you change the URL for rawgit Thanks I change the source code for myself and it's worked How ever maybe I'm wrong about this.

Thanks for this handy tools Hail Mathematics for ever

JARVIS-AI avatar Oct 17 '18 18:10 JARVIS-AI

Here is an example of my URL in rawgit

Link

Here is broken

https://camo.githubusercontent.com/cc69c118046e253fdfae9fdbf48dda46c94378ae/68747470733a2f2f7261776769742e636f6d2f4a41525649532d41492f4d617468536f6c7665642f6d61737465722f737667732f38383734613135616361353234643562356234373632633564306531313861642e7376673f696e766572745f696e5f6461726b6d6f6465

The above link give me this error : Invalid upstream response (403)

JARVIS-AI avatar Oct 17 '18 18:10 JARVIS-AI

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

JARVIS-AI avatar Oct 17 '18 18:10 JARVIS-AI

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.

atreyasha avatar Oct 27 '18 04:10 atreyasha

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 --

atreyasha avatar Oct 27 '18 05:10 atreyasha

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

JARVIS-AI avatar Oct 28 '18 07:10 JARVIS-AI

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

tonyduan avatar Feb 20 '19 02:02 tonyduan


	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") 

WorldSEnder avatar May 23 '19 03:05 WorldSEnder

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

JARVIS-AI avatar Jun 03 '19 07:06 JARVIS-AI

Also you probably don't want to do


        git add .

but instead


        git add svgs/ README.md

WorldSEnder avatar Jun 03 '19 08:06 WorldSEnder