Forked from Grip. Original README
Render local markdown files offline.
Grip-offline is a command-line server application written in Python that uses code taken from SublimeText plugin MarkdownPreview v2.4.2 to render local markdown files in your browser and allow you to follow their links. Changes you make to the Readme will be instantly reflected in the browser without requiring a page refresh.
The styles and rendering are a close apporximation to Github's renderer and will not be exactly the same so keep that it mind.
Also, this fork has been modified to work for simple offline rendering only. The other functionality has not been tested and may not work.
To install Grip-offline:
in terminal, go to the folder where you cloned Grip-offline then run
$ pip install .
To render the readme of a repository:
$ cd myrepo
$ grip
* Running on http://localhost:6419/
Now open a browser and visit http://localhost:6419.
You can also specify a port, used --theme="dark"
to render in dark mode and/or use -b
to automatically open a new browser tab for you.:
$ grip 80 -b --theme="dark"
* Running on http://localhost:80/
Or an explicit file:
$ grip AUTHORS.md
* Running on http://localhost:6419/
Alternatively, you could just run grip
and visit localhost:6419/AUTHORS.md
since grip supports relative URLs.
You can even bypass the server and export to a single HTML file, with all the styles and assets inlined:
$ grip --export
Exporting to README.html
Control the output name with the second argument:
$ grip README.md --export index.html
Exporting to index.html
If you're exporting a bunch of files, you can prevent styles from being inlining to save space with --no-inline
:
$ grip README.md --export --no-inline introduction.html
Exporting to introduction.html
Reading and writing from stdin and stdout is also supported, allowing you to use Grip with other programs:
$ cat README.md | grip -
* Running on http://localhost:6419/
$ grip AUTHORS.md --export - | bcat
$ cat README.md | grip --export - | less
This allows you to quickly test how things look by entering Markdown directly in your terminal:
$ grip -
Hello **world**!
^D
* Running on http://localhost:6419/
Note: ^D
means Ctrl+D
, which works on Linux and OS X. On Windows you'll have to use Ctrl+Z
.
Rendering as user-content like comments and issues is also supported, with an optional repository context for linking to issues:
$ grip --user-content --context=joeyespo/grip
* Running on http://localhost:6419/
For more details and additional options, see the help:
$ grip -h
To customize Grip, create ~/.grip/settings.py
, then add one or more of the following variables:
DEBUG
: Whether to use Flask's debugger when an error happens,False
by defaultDEBUG_GRIP
: Prints extended information when an error happens,False
by defaultCACHE_DIRECTORY
: The directory, relative to~/.grip
, to place cached assets (this gets run through the following filter:CACHE_DIRECTORY.format(version=__version__)
),'cache-{version}'
by defaultAUTOREFRESH
: Whether to automatically refresh the Readme content when the file changes,True
by defaultQUIET
: Do not print extended information,False
by default
GRIPHOME
: Specify an alternativesettings.py
location,~/.grip
by defaultGRIPURL
: The URL of the Grip server,/__/grip
by default
This file is a normal Python script, so you can add more advanced configuration.
For example, to read a setting from the environment and provide a default value when it's not set:
PORT = os.environ.get('GRIP_PORT', 8080)
You can access the API directly with Python, using it in your own projects:
from grip import serve
serve(port=8080)
* Running on http://localhost:8080/
Run main directly:
from grip import main
main(argv=['-b', '8080'])
* Running on http://localhost:8080/
Or access the underlying Flask application for even more flexibility:
from grip import create_app
grip_app = create_app(user_content=True)
# Use in your own app
Runs a local server and renders the Readme file located
at path
when visited in the browser.
serve(path=None, host=None, port=None, user_content=False, context=None, username=None, password=None, render_offline=False, render_wide=False, render_inline=False, api_url=None, title=None, autorefresh=True, browser=False, theme='light', grip_class=None)
path
: The filename to render, or the directory containing your Readme file, defaulting to the current working directoryhost
: The host to listen on, defaulting to the HOST configuration variableport
: The port to listen on, defaulting to the PORT configuration variableuser_content
: Whether to render a document as [user-content][] like user comments or issuescontext
: The project context to use whenuser_content
is true, which takes the form ofusername/project
username
: Not used. Set toNone
password
: Not used. Set toNone
render_offline
: use SublimeText MarkdownPreview renderer (will break if set to False!)render_wide
: Whether to render a wide page,False
by default (this has no effect when used withuser_content
)render_inline
: Whether to inline the styles within the HTML fileapi_url
: Not used. Set toNone
title
: The page title, derived frompath
by defaultautorefresh
: Automatically update the rendered content when the Readme file changes,True
by defaultbrowser
: Open a tab in the browser after the server starts.,False
by defaultgrip_class
: Use a custom Grip class
Writes the specified Readme file to an HTML file with styles and assets inlined.
export(path=None, user_content=False, context=None, username=None, password=None, render_offline=False, render_wide=False, render_inline=True, out_filename=None, api_url=None, title=None, quiet=None, theme='light', grip_class=None)
path
: The filename to render, or the directory containing your Readme file, defaulting to the current working directoryuser_content
: Whether to render a document as [user-content][] like user comments or issuescontext
: The project context to use whenuser_content
is true, which takes the form ofusername/project
username
: Not used. Set toNone
password
: Not used. Set toNone
render_offline
: use SublimeText MarkdownPreview renderer (will break if set to False!)render_wide
: Whether to render a wide page,False
by default (this has no effect when used withuser_content
)render_inline
: Whether to inline the styles within the HTML file (Must be set to True!)out_filename
: The filename to write to,<in_filename>.html
by defaultapi_url
: Not used. Set toNone
title
: The page title, derived frompath
by defaultquiet
: Do not print to the terminaltheme
: Theme to view markdown file (light mode or dark mode). Valid options ("light", "dark"). Default: "light".grip_class
: Use a custom Grip class