Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

htmlpreview rewrites links that use htmlpreview #48

Open
timmmooney opened this issue Nov 22, 2016 · 2 comments
Open

htmlpreview rewrites links that use htmlpreview #48

timmmooney opened this issue Nov 22, 2016 · 2 comments

Comments

@timmmooney
Copy link

The following html preview:

http://htmlpreview.github.io/?https://github.com/epics-modules/softGlueZynq/blob/master/documentation/softGlueZynqDoc.html

contains a link (in the first paragraph, the word "autosave") that reads, in softGlueZynqDoc.html, as follows:

https://htmlpreview.github.io/?https://github.com/epics-modules/autosave/blob/R5-7-1/documentation/autoSaveRestore.html#configMenu

but if you click on it you get this:

https://htmlpreview.github.io/?https://github.com/epics-modules/softGlueZynq/blob/master/documentation/softGlueZynqDoc.html#configMenu

@mcarbonneaux
Copy link

mcarbonneaux commented Oct 10, 2022

i've the same problem!

for exemple with the page: https://htmlpreview.github.io/?https://raw.githubusercontent.com/FastCGI-Archives/fcgi2/master/doc/fastcgi-prog-guide/ap_guide.htm

they rewrite all the anchor as local page anchor (of ap_guide.htm) event if is relative href to the same git repository (for exemple ch1intro.htm)...

i think the problem are her:

if (href.indexOf('#') > 0) { //Check if it's an anchor

they not support relative link (local to the git repository) with anchor, because they rewrite it systematicly with the base page name.

is because if detect # they consider as an anchor, and rewrite the anchor systematicly by removing the href page name and keep only the anchor part:

if (href.indexOf('#') > 0) { //Check if it's an anchor
           a[i].href = '//' + location.hostname + location.pathname + location.search + '#' + a[i].hash.substring(1); //Then rewrite URL with support for empty anchor

they need to check if is relative url before rewrite anchor like this...

like that :

var pat = /^(?:[a-z+]+:)?(\/\/|\/)/i;
if (href.indexOf('#') > 0&&pat.text(href)) { //Check if it's an anchor and absolute url

this are absolute:

http://example.com
HTTP://EXAMPLE.COM
https://www.exmaple.com
ftp://example.com/file.txt
//cdn.example.com/lib.js
git+ssh://example.con/itemscheme
/myfolder/test.txt

this are relative.

test
relative/test
./test

@SergeyMosin
Copy link

Same here all links with fragment part (# + text) are broken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants