|
| 1 | +# githubwiki |
| 2 | + |
| 3 | +> A library to fetch and format Github wiki content |
| 4 | +
|
| 5 | +## Install |
| 6 | + |
| 7 | +``` bash |
| 8 | +bower install githubwiki |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Minimal usage: |
| 14 | + |
| 15 | +```html |
| 16 | +<!doctype html> |
| 17 | +<html> |
| 18 | + <head> |
| 19 | + <meta charset="utf-8"/> |
| 20 | + <title>GithubWiki</title> |
| 21 | + <script src="node_modules/jquery/dist/jquery.min.js"></script> |
| 22 | + <script src="bower_components/marked/lib/marked.js"></script> |
| 23 | + <script src="bower_components/github-wiki/js/githubwiki.js"></script> |
| 24 | + </head> |
| 25 | + <body> |
| 26 | + <div id="content"></div> |
| 27 | + <script> |
| 28 | + githubwiki.setWiki('SchoolIdolTomodachi', 'frgl'); |
| 29 | + githubwiki.get("Home.md", function(text) { |
| 30 | + document.getElementById('test').innerHTML = text; |
| 31 | + }); |
| 32 | + </script> |
| 33 | + </body> |
| 34 | +</html> |
| 35 | +``` |
| 36 | + |
| 37 | +You can also set custom renderer for the internal wiki links (the *[[link]]* or *[[link|title]]* syntaxes) like this: |
| 38 | + |
| 39 | +```js |
| 40 | +function linkRenderer(link) { |
| 41 | +gh_name = githubname(link) + '.md'; |
| 42 | +return '<a href="' + module.wikiurl + gh_name + '">' + link + '</a>'; |
| 43 | +}; |
| 44 | + |
| 45 | +function linkRendererTitle(title, link) { |
| 46 | + gh_name = githubname(link) + '.md'; |
| 47 | + return '<a href="' + module.wikiurl + gh_name + '">' + title + '</a>'; |
| 48 | +}; |
| 49 | + |
| 50 | +githubwiki.setMarkedOptions({ |
| 51 | + internalLink: linkRenderer, |
| 52 | + internalLinkTitle: linkRendererTitle |
| 53 | +}); |
| 54 | +``` |
| 55 | +(You can check the marked documentation available here: https://github.com/Engil/marked (internalLink and internalLinkTitle are options excusive to a custom fork we used in order to parse internal wiki links) |
| 56 | + |
| 57 | +## Methods documentation |
| 58 | + |
| 59 | +```js |
| 60 | +// Method to escape a wiki page name in a Github fashion. |
| 61 | +// Wiki pages filenames are based on the page title, so in order to access them we need to do a little bit of escaping. |
| 62 | +githubWiki.getGithubName("Bla bla bla"); |
| 63 | +// Will return "Bla-bla-bla |
| 64 | + |
| 65 | +// Method to set the wiki we are going to work on. |
| 66 | +// Wiki repositories raw files are basically available through an URL like this |
| 67 | +// https://raw.githubusercontent.com/wiki/Username/Project/ |
| 68 | +githubWiki.setWiki("Username", "Project"); |
| 69 | + |
| 70 | +// Method to get a wiki page |
| 71 | +githubWiki.get("Page", callback); |
| 72 | +// Will call the function passed in argument with the wikipage content already parsed by marked. |
0 commit comments