Git Product home page Git Product logo

Comments (9)

atreyasha avatar atreyasha commented on August 18, 2024 4

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.

atreyasha avatar atreyasha commented on August 18, 2024 3

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.

JARVIS-AI avatar JARVIS-AI commented on August 18, 2024 1

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.

tonyduan avatar tonyduan commented on August 18, 2024 1

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.

WorldSEnder avatar WorldSEnder commented on August 18, 2024 1
	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.

JARVIS-AI avatar JARVIS-AI commented on August 18, 2024

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)

from readme2tex.

JARVIS-AI avatar JARVIS-AI commented on August 18, 2024

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.

JARVIS-AI avatar JARVIS-AI commented on August 18, 2024

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.

WorldSEnder avatar WorldSEnder commented on August 18, 2024

Also you probably don't want to do

        git add .

but instead

        git add svgs/ README.md

from readme2tex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.