Can I use a Markdown file in a GitHub page? - github

Since the GitHub wiki does not support directories, I want to put my md files into GitHub pages. However when I open them I found they are not interpreted at all. GitHub just gives me the raw file. See http://greenlaw110.github.com/Rythm/en/index.md. Any idea?

The documentation isn't particularly clear on this, but given that the Markdown rendering is done by Jekyll, I believe you need what they call "YAML front matter" for it to compile the page. So try putting this at the top of your file:
---
title: Document Center
---
That should be enough to trigger Jekyll. (And then you can get fancy and start using layouts, etc.)

Another reason (found by experience) why you might get a raw index.md file, is if you happen to also have a similarly-named index.html file. This blocks GH Pages.
Deleting index.html produces (on the site) a new index.html with parsed markdown. The original index.md is then no longer accessible.

Related

Github Jekyll theme hacker style does not apply to sublinks

I created a GitHub page with a hacker theme.
Then, I created another .md file (other than the index.md) and linked it to the index file.
The referenced .md (named as testlink.md) does not have the same style, unfortunately.
Here is the code: https://github.com/YesimSem/thecuriousanimal/tree/gh-pages
How may I ensure that all the .md files have that same style?
Thank you,
Updated Answer
Your link needs to be changed from .md to .html. Please see this pull request on your repository for the fix. The testlink.md is being rendered correctly but your link is going to the original Markdown file. It should be going to the HTML rendering of the Markdown file. See this URL for the correct page https://yesimsem.github.io/thecuriousanimal/testlink.html
Original Answer
You need to add Jekyll Front Matter to your new page (i.e. testlink.md) and specify the a Jekyll layout. In your situation, your new page needs the same layout as the index.md from the GitHub Jekyll Hacker theme. See the layout specified at the top of index.md.

Jekyll site attempting to download 'Posts' page instead of rendering it when link is clicked (deployed at Github)

Folks, help is needed and MUCH appreciated with a fuzzy behaviour of Jekyll site deployed to Github.
The site works perfectly when putting it up and using it in the local machine (through 'jekyll serve'). The surprise came up upon deployment to Github, the HTML 'posts.html' page created to show the post list does not get rendered at all. The rest of the site is up and running fine, but once the link is clicked to reach the mentioned page the browser is trying to DOWNLOAD the file, instead of rendering.
If you need to have a peek at the code:
https://github.com/zekdeluca/zekdeluca.github.io
And the site can be seen at:
http://zekdeluca.github.io/
Thanks in advance!
It has to do with the permalink and how the extension-less urls are working. If you add a trailing slash to your url it will work. If you are trying to do it without the trailing slash, I was under the impression that what you did would work on GH.
Something like permalink: /my-page/ will work and it creates a folder called my-page with an index.html file in it. The url will show as /my-page/ without the index.html - pretty except the trailing slash.
If you do permalink: /my-page it should be making a file my-page.html, but in your case it seemed to have made just my-page with no extension, which is then being served as a file by github and it doesn't seem to know what it is so it is downloading it instead of serving it.
There seems to be a lot of conflicting info on this, I think the behavior has changed recently, and maybe the version GH is using is able to output a file with no extension? I did not think that was the case.
more reading:
http://overengineer.net/pretty-extensionless-urls-in-github-pages-using-jekyll/
Jekyll extension-less permalinks with markdown

Is it possible to make relative link to image in a markdown file in a gist?

I've got a gist which contains a markdown file and an image.
Is there a way to do a relative link to this image?
Something like ![My image](image.png) instead of ![My image](https://gist.github.com/user/605560c2961cb3025038/raw/b75d2...6e8/img.png)
Here is an example
As of now, relative image links are working for me, in both a repository and a wiki. I'm using syntax like this:
![Kiku](images/Kiku.jpg)
Here's an example:
https://github.com/mark-anders/relative-image-url
According to http://blog.rodneyrehm.de/archives/35-Including-Data-From-Github.html, the problem in using
https://gist.github.com/user/605560c2961cb3025038/raw/b75d2...6e8/img.png
is that the b75d2...6e8 part varies per file (a quick experimentation confirms it is the git blob id). However you can drop that part resulting in a URL pointing to the latest version:
https://gist.github.com/user/605560c2961cb3025038/raw/img.png
or to take a working example:
https://gist.githubusercontent.com/cben/46d9536baacb7c5d196c/raw/dodgetocat_v2.png
Relative path?
This also works as relative path raw/dodgetocat_v2.png!
However (as of late 2017) github can render the same gist from 2 URLs:
When viewed from https://gist.github.com/cben/46d9536baacb7c5d196c/ (with trailing slash), the relative path is appended, resolves to https://gist.github.com/cben/46d9536baacb7c5d196c/raw/dodgetocat_v2.png — works :-)
When viewed from https://gist.github.com/cben/46d9536baacb7c5d196c (no trailing slash), the relative path replaces the last part of the URL, resolves to https://gist.github.com/cben/raw/dodgetocat_v2.png — broken :-(
[UPDATED Dec 2017. Previous problems of raw files served as Content-Type: application/octet-stream and rewriting src attributes of images to camo.githubusercontent.com no longer happen, at least not for images from same gist.]
Alas, we can't just use the first URL and trust it to always work.
Currently neither form returns a redirect, nor serves a rel=canonical link. I wouldn't bet on Github to never change this!
All internal gist links (e.g. from user's page https://gist.github.com/cben/) omit the trailing slash :-(
Gists in Google search results omit the trailing slash :-(
(You could use relative path 46d9536baacb7c5d196c/raw/dodgetocat_v2.png that would only work without trailing slash, but that's also questionable idea, and less worth it — not really more flexible than full URL.)
Using a proxy?
Both can be worked around with a proxy fixing the Content-Type, e.g. Rawgit or Bl.ocks.org (not by Github, don't abuse them). Unfortunately Rawgit doesn't render Markdown, only serves files as-is, and Bl.ocks.org does render markdown but the URL structure is such that relative links won't work. This means you can either reference full external URL in Markdown, or relative in HTML :-(
See https://gist.github.com/cben/46d9536baacb7c5d196c/ forked off your gist,
and its index.html viewed via:
http://rawgit.com/cben/46d9536baacb7c5d196c/raw/index.html
http://rawgit.com/cben/46d9536baacb7c5d196c/raw/
http://bl.ocks.org/cben/raw/46d9536baacb7c5d196c
http://bl.ocks.org/cben/46d9536baacb7c5d196c
Yes, the relative link is working for me. I am using pancake.io to host my pages.
http://pancake.io/2c8aa8/topics/cpp/cpp.md
The images on that page are in the cpp folder.
The markdown code used for the first image is
![C++ Var Types](basic_cpp_var_types.png)
The markdown code (actually html) used for the second image is
<div style='float: center'>
<img style='width: 600px' src="prefixpostfixincrement.png"></img>
</div>
NOTE: I missed the gist part. Try the html way if gist doesn't support the markdown relative image path syntax.
tested just now...
i was unable to use relative urls on the github wiki.
i had to add the image to the wiki repo, then browser the repo and have github show it to me (so i could grab the url). then use the full url in the markdown. but luckily, the urls are simple to predict: https://github.com/*username*/*reponame*/wiki/*imagename.png*
i submitted this isse to the github support.
No, the relative URL to an image from markdown doesn’t work, so you’ll have to stick with the long, static URL:
https://gist.github.com/mattborn/c346c8689a5eaf86e823
However, relative URLs to some files work:
http://bl.ocks.org/mattborn/c346c8689a5eaf86e823
After scratching my head around this for good 15 minutes I realized:
Relative paths to images do work, but when you're writing a markdown file directly from the github web app, the images don't show up in preview. Once you commit the file the images are visible as expected

Embedding images inside a GitHub wiki (gollum) repository?

The Github wikis are backed by a separate git repository then the main project repository.
This post by the Github team makes it sound like you should be able to link to images stored in the wiki repository inside the wiki markup.
Images and Folders
You can now reference images hosted inside the Git repository.
I've checked out my wiki's repository and pushed a resource folder and an image into it. My question is, how do I go about using this image?
Is this even possible or have I misunderstood something?
For viewers wishing to view images on a github wiki I've found the following method to work:
Go to the "Git Access" tab inside the wiki page of your repository and retrieve the SSH path which should be some thing like: git#github.com:USER/REPO.wiki.git where USER is your account name and REPO is the repository name.
On your local machine use whichever Git command line tool you wish to cd into your local directory of choice and get the repository via
git clone git#github.com:USER/REPO.wiki.git
Now within this repository create an image directory, I'll call it "images" and put whatever images you want into the directory
And then push your wiki git directory to github
You will not be able to physically see the images in say the "Pages" tab, but if you simply reference the images in a local link you should be able to see them. Example with Markdown below:
![Alt attribute text Here](images/YOURIMAGE.ext)
You may also embed the image as a link itself by wrapping it further like so:
[![Alt attribute text Here](images/YOURIMAGE.ext)](http://Yoursite.com)
You can also add subdirectories within your local copy to help organize the wiki since the "pages" tab simply lists them out. Keep in mind, however, that even when the new directory is pushed the "pages" tab doesn't list the directory.
To use relative paths do:
[[foo.jpg]]
For more info, see the demo wiki's page on images.
None of answers seem to work when adding an image in readme.md. I've got a solution though:
If the URL of the image is:
https://github.com/Username/Repository-Name/blob/master/Directory-Inside-Repository/image.png
Replacing blob with raw gives you the URL of the raw image:
https://github.com/Username/Repository-Name/raw/master/Directory-Inside-Repository/image.png
Now, you'd embed the image using normal markdown:
![Image Alt](https://github.com/Username/Repository-Name/raw/master/Directory-Inside-Repository/image.png)
UPDATE: As of now, GitHub also serves raw images from a different sub-domain raw.github.com. So, you can also use:
https://raw.github.com/Username/Repository-Name/master/Directory-Inside-Repository/image.png
EXAMPLE: https://raw.github.com/Automattic/liveblog/master/screenshot-1.png
Relative path work for me like this:
home page of the wiki:
![text](wiki/images/someimage.png)
sub page of the wiki:
![text](images/someimage.png)
Note that when doing a preview the image will not show, I had save it.
If you want to quickly upload an image with drag/drop, you can perform the following (albeit hackish):
Create a dummy issue; drag & drop your image there; copy/paste the uploaded markdown image code to your wiki;
After you create the issue once, you can use it any number of times to do this.
Hope this helps anyone looking for a quick fix, without needing to have the image reside in the repo.
Here is a practical way to do it:
Go to any issue on github
In the comment section you can attach files, just drag/drop, select or paste your image
Copy the code/link displayed in the textarea
Paste it in the wiki
Profit !
You don't even have to create or modify any issue compared to #tiby solution !
Figured it out.
The url is formatted as follows
https://raw.github.com/wiki/username/project/pathtoimage/imagename.extension
pathtoimage is optional
James' URL format did not work for me, perhaps it has been changed. I have used:
https://github.com/username/project/wiki/pathtoimage/image.extension
Where pathtoimage is optional.
Finally got the images into repository using the method described by nerdwin and got them to display in the wiki using ![test](test.jpg)
The following markdown will reference an image in your GitHub repo from within your corresponding GitHub wiki
![My Alt Text](../blob/master/Path/ToAsset/In/Repo.png?raw=true)
The above example assumes that you have the following file structure in your repo
Path
ToAssets
In
Repo.png
For a real world example, if I wanted to reference this image in github from the corresponding wiki, I'd use this markdown
![Azure App Settings](../blob/master/TrelloWorld/TrelloWorld.Server/Assets/Azure_AppSettings.png?raw=true)
Caveats
Case matters
If you are on the special Home page of the wiki, you do not need to go up a level with the ../ In my example above, the correct link would be
For Home Page:
![Azure App Settings](blob/master/TrelloWorld/TrelloWorld.Server/Assets/Azure_AppSettings.png?raw=true)
Use the relative path
the Wiki is located at [repositoryname]/wiki
The files in the repository are located at [repositoryname]/raw/master/[file path in repository]
So just use the relative path: ../raw/master/[file path in repository]
I put both images and PDFs in my wikis. I clone the wiki and add an images and a files directory, then use the following markdown to embed image links and add file links:
Images:
[[/images/path/to/image.ext|ALT TEXT]]
The leading slash isn't necessary if your wiki pages are all at the root level, but I use subdirectories and an absolute path resolves correctly and keeps things simple.
Files:
[link text](files/path/to/file.ext "ALT TEXT")
Note, no leading slash for the wiki files path to resolve correctly as a link in this format.
I documented this with more detail in a GitHub gist
Since Feb. 2022, you can simply drag and drop, select or paste the file.
That will upload the image to your Wiki pages, and store it in https://user-images.githubusercontent.com
To embed an external image thumbnail, use the following,
![Image](<external link to the image>)
The comment from #Drew Noakes to the original question did it for me:
The syntax for the image I wanted to be displayed:
[[/images/imageName.png]]
This image was only displayed when renaming:
wikiPage.md --> wikiPage.wiki
The following folder structure was used in the wiki repository:
repository.wiki
|--wikiPage.wiki
|--images
|--imageName.png
BUT:
The syntax in .wiki differs from .md files.
Many of the answers didn't work for me, here's what finally worked:
![](../raw/master/Images/ImportantImage.png)
Using the "Markdown" editor mode and a sub-page such as:
https://github.com/project/repo/wiki/MyPage

GitHub relative link in Markdown file

Is there a way to create a URL anchor, <a>, link from within a Markdown file, to another file within the same repository and branch (aka a link relative to the current branch)?
For example, in the master branch I have a README.md file, which I would like do something like:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib documentation
see documentation [here](myLib/README.md)
This would allow me to link from one .md to another within the same branch and not have to worry about which branch I'm in (avoid having to do an absolute URL that includes the github.com branch name).
Here is a working example of what I mean:
GOTO http://github.com/rynop/testRel, link does not work.
GOTO http://github.com/rynop/testRel/blob/master/README.md, link works.
This is expected because at this point the starting URL is in the branch. Now how do I get it to pick up the current branch in the README.md at the root of the repository?
Update: I opened an issue against GitHub for this feature request.
Update 30th, January 2013, 16 months later:
GitHub Blog Post Relative links in markup files:
Starting today, GitHub supports relative links in markup files.
Now you can link directly between different documentation files, whether you view the documentation on GitHub itself, or locally, using a different markup renderer.
You want examples of link definitions and how they work? Here's some Markdown for you.
Instead of an absolute link:
[a link](https://github.com/user/repo/blob/branch/other_file.md)
…you can use a relative link:
[a relative link](other_file.md)
[a relative link](path%20with%20spaces/other_file.md)
and we'll make sure it gets linked to user/repo/blob/branch/other_file.md.
If you were using a workaround like [a workaround link](repo/blob/master/other_file.md), you'll have to update your documentation to use the new syntax.
This also means your documentation can now easily stand on its own, without always pointing to GitHub.
Marcono1234 adds in the comments
Also useful: When the link starts with a /, it is relative to the root of the repository (regardless of whether the markdown file is nested in subdirectories)
Update December 20th, 2011:
The GitHub markup issue 84 is currently closed by technoweenie, with the comment:
We tried adding a <base> tag for this, but it causes problems with other relative links on the site.
October 12th, 2011:
If you look at the raw source of the README.md of Markdown itself(!), relative paths don't seem to be supported.
You will find references like:
[r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
[r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
As noted in InvisibleWolf's answer, if the target link is a directory and it has space, then you need to use %20 for each space.
For example, you have a repo like the following:
project/
text.md
subpro/
subtext.md
subsubpro/
subsubtext.md
subsubpro2/
subsubtext2.md
The relative link to subtext.md in text.md might look like this:
[this subtext](subpro/subtext.md)
The relative link to subsubtext.md in text.md might look like this:
[this subsubtext](subpro/subsubpro/subsubtext.md)
The relative link to subtext.md in subsubtext.md might look like this:
[this subtext](../subtext.md)
The relative link to subsubtext2.md in subsubtext.md might look like this:
[this subsubtext2](../subsubpro2/subsubtext2.md)
The relative link to text.md in subsubtext.md might look like this:
[this text](../../text.md)
GitHub could make this a lot better with minimal work. Here is a work-around.
I think you want something more like
[Your Title](your-project-name/tree/master/your-subfolder)
or to point to the README itself
[README](your-project-name/blob/master/your-subfolder/README.md)
As of January 31, 2013 Github markdown supports relative links to files.
[a relative link](markdown_file.md)
However, there are a few deficiencies that have been discussed in this comment thread.
As an alternative, you can use Gitdown to construct full URLs to the repository and even make them branch aware, e.g.
{"gitdown": "gitinfo", "name": "url"} // https://github.com/gajus/gitdown
{"gitdown": "gitinfo", "name": "branch"} // master
Gitdown is a GitHub markdown preprocessor. It streamlines common tasks associated with maintaining a documentation page for a GitHub repository, e.g. generating table of contents, including variables, generating URLs and getting information about the repository itself at the time of processing the input. Gitdown seamlessly integrates with your building scripts.
I am the author of the Gitdown library.
Just wanted to add this because none of the above solutions worked if target link is directory with spaces in it's name. If target link is a directory and it has space then even escaping space with \ doesn't render the link on Github. Only solution worked for me is using %20 for each space.
e.g.: if directory structure is this
Top_dir
|-----README.md
|-----Cur_dir1
|----Dir A
|----README.md
|----Dir B
|----README.md
To make link to Dir A in README.md present in Top_dir you can do this:
[Dir 1](Cur_dir1/Dir%20A)
You can link to file, but not to folders, and keep in mind that, Github will add /blob/master/ before your relative link(and folders lacks that part so they cannot be linked, neither with HTML <a> tags or Markdown link).
So, if we have a file in myrepo/src/Test.java, it will have a url like:
https://github.com/WesternGun/myrepo/blob/master/src/Test.java
And to link it in the readme file, we can use:
[This is a link](src/Test.java)
or: This is a link.
(I guess, master represents the master branch and it differs when the file is in another branch.)
You can use relative URLs from the root of your repo with <a href="">. Assuming your repo is named testRel, put the following in testRel/README.md:
# My Project
is really really cool. My Project has a subdir named myLib, see below.
## myLib docs
see documentation:
* myLib/
* myLib/README.md
This question is pretty old, but it still seems important, as it isn't easy to put relative references from readme.md to wiki pages on Github.
I played around a little bit and this relative link seems to work pretty well:
[Your wiki page](../../wiki/your-wiki-page)
The two ../ will remove /blob/master/ and use your base as a starting point. I haven't tried this on other repositories than Github, though (there may be compatibility issues).
In .md file when you want to create a link to any related files which is related to same project folder or URL based links:
Existing file link:
In .md file add showing name in [] box then open () in this box add / after that it will auto fetch all existing folders name form which you choose your folder then add '/' it will show inner file or 'folders`. This means it will auto fetch the paths and at the end, your URL is created.
Example:
[Enter Showing Name](/users/4000266/heysushil)
This line show like this:
Enter Showing Name
Add URLs on .md file
Follow the same process only change the () box path with URL like this:
[HeySushil - YouTube](https://youtube.com/heysushil)
This looks like HeySushil - YouTube
Note: Remember no need to add force manually after adding / on () box it will auto fetch all existing folders and files.
I am not sure if I see this option here. You can just create a /folder in your repository and use it directly:
[a relative link](/folder/myrelativefile.md)
No blob or tree or repository name is needed, and it works like a charm.
If you want a relative link to your wiki page on GitHub, use this:
Read here: [Some other wiki page](path/to/some-other-wiki-page)
If you want a link to a file in the repository, let us say, to reference some header file, and the wiki page is at the root of the wiki, use this:
Read here: [myheader.h](../tree/master/path/to/myheader.h)
The rationale for the last is to skip the "/wiki" path with "../", and go to the master branch in the repository tree without specifying the repository name, that may change in the future.
The behaviour in Github directory links in markdown files could create some headaches.
All files have an url are starting with blob,
blob/<branch>/<path>/<fileName>
whereas directories have an url starting with tree:
tree/<branch>/<path>
So no relative link to a directory should work. It points to an url that starts with a blob. Magically Github changes some relative path automatically to the tree path. Unfortunately not urls containing ".."
I investigate some time to examine the strange behaviour with Github directory links on https://github.com/fluentcodes/GitSamples-GIT/tree/github-readme-links.
Just follow the format below.
[TEXT TO SHOW](actual URL to navigate)
Here is what I found for relative links in github's .md files:
Relative links without ../ (aka. link to file in the same level, or in sub dir), seems always work.
Relative links that contains ../ works only when you are already in a page whose url contains substring /blob/.
Otherwise need to use full url that contains /blob/, to link.
Actually except top level /README.md, when view any other files, their url already contains /blob/.
Thus probably you can always use relative links that contains ../ in files, except /README.md.
But /README.md is in top level, thus it shouldn't need a relative link that contains ../.
So, you should never need a full path link (that contains github domain) to link to files in the same github repo.
Example (links among multiple language doc)
In /README.md, can use relative links without ../.
[中文](doc/cn/README.md) |
[日本語](doc/jp/README.md)
In /doc/cn/README.md, since when we view it, the url already contains /blob/, thus could use relative links with ../.
[English](../../README.md) |
[日本語](../jp/README.md)
(BTW, the example come from this git-merge-flow repo.)
What I found to work for relative folders:
[link text](subfolder/subsubfolder/relevantfolder/)
where relevant folder is the folder you are trying to link to. The backslash is needed after the folder name. I tried including the project name and tree/main in the path and the other things suggested in previous answers, that lead to a nonexistent page error. The subfolder is a folder within the overall repo project folder.
Thus, file links would be in the form of:
[link text](subfolder/subsubfolder/relevantfolder/index.html)
If the desired file is not in any folder or subfolder the link is simply:
[link text](README.md)
for example the README file is not in any subfolders, so that could be the exact relative link you use for the README file.
You can also insert your links (relative or absolute) at the bottom to reduce clutter in text.
It can also be a good option for repetitive links.
This is [my linked text].
[my linked text]: relative/path/in/repo/to/file.txt "Optional title for mouse hover"
This is my linked text.