Giter Club home page Giter Club logo

flatdoc's Introduction

Flatdoc

Flatdoc is a small JavaScript file that fetches Markdown files and renders them as full pages. Essentially, it's the easiest way to make open source documentation from Readme files.

  • No server-side components
  • No build process needed
  • Deployable via GitHub Pages
  • Can fetch GitHub Readme files
  • Gorgeous default theme (and it's responsive)
  • Just create an HTML file and deploy!

Current version: v0.9.0

Build Status

Getting started

Create a file based on the template, which has a bare DOM, link to the scripts, and a link to a theme. It will look something like this (not exact). For GitHub projects, simply place this file in your GitHub pages branch and you're all good to go.

In short: just download this file and upload it somewhere.

The main JS and CSS files are also available in npm and bower.

Default theme template >

Blank template >

Via GitHub

To fetch a Github Repository's readme file, use the Flatdoc.github fetcher. This will fetch the Readme file of the repository's default branch.

Flatdoc.run({
  fetcher: Flatdoc.github('USER/REPO')
});

You may also fetch another file other than the Readme file, just specify it as the 2nd parameter.

Flatdoc.run({
  fetcher: Flatdoc.github('USER/REPO', 'Changelog.md')
});

After you've done this, you probably want to deploy it via GitHub Pages.

GitHub Pages guide >

Via a file

You may also fetch a file. In this example, this fetches the file Readme.md in the same folder as the HTML file.

Flatdoc.run({
  fetcher: Flatdoc.file('Readme.md')
});

You may actually supply any URL here. It will be fetched via AJAX. This is useful for local testing.

Flatdoc.run({
  fetcher: Flatdoc.file('http://yoursite.com/Readme.md')
});

How it works

Flatdoc is a hosted .js file (along with a theme and its assets) that you can add into any page hosted anywhere.

All client-side

There are no build scripts or 3rd-party services involved. Everything is done in the browser. Worried about performance? Oh, It's pretty fast.

Flatdoc utilizes the GitHub API to fetch your project's Readme files. You may also configure it to fetch any arbitrary URL via AJAX.

Lightning-fast parsing

Next, it uses marked, an extremely fast Markdown parser that has support for GitHub flavored Markdown.

Flatdoc then simply renders menu and content DOM elements to your HTML document. Flatdoc also comes with a default theme to style your page for you, or you may opt to create your own styles.

Markdown extras

Flatdoc offers a few harmless, unobtrusive extras that come in handy in building documentation sites.

Code highlighting

You can use Markdown code fences to make syntax-highlighted text. Simply surround your text with three backticks. This works in GitHub as well. See GitHub Syntax Highlighting for more info.

``` html
<strong>Hola, mundo</strong>
```

Blockquotes

Blockquotes show up as side figures. This is useful for providing side information or non-code examples.

Blockquotes are blocks that begin with >.

Smart quotes

Single quotes, double quotes, and double-hyphens are automatically replaced to their typographically-accurate equivalent. This, of course, does not apply to <code> and <pre> blocks to leave code alone.

"From a certain point onward there is no longer any turning back. That is the point that must be reached."
--Franz Kafka

Buttons

If your link text has a > at the end (for instance: Continue >), they show up as buttons.

View in GitHub >

Customizing

Basic

Theme options

For the default theme (theme-white), You can set theme options by adding classes to the <body> element. The available options are:

big-h3

Makes 3rd-level headings bigger.

<body class='big-h3'>

no-literate

Disables "literate" mode, where code appears on the right and content text appear on the left.

<body class='no-literate'>

large-brief

Makes the opening paragraph large.

<body class='large-brief'>

Adding more markup

You have full control over the HTML file, just add markup wherever you see fit. As long as you leave role='flatdoc-content' and role='flatdoc-menu' empty as they are, you'll be fine.

Here are some ideas to get you started.

  • Add a CSS file to make your own CSS adjustments.
  • Add a 'Tweet' button on top.
  • Add Google Analytics.
  • Use CSS to style the IDs in menus (#acknowledgements + p).

JavaScript hooks

Flatdoc emits the events flatdoc:loading and flatdoc:ready to help you make custom behavior when the document loads.

$(document).on('flatdoc:ready', function() {
  // I don't like this section to appear
  $("#acknowledgements").remove();
});

Full customization

You don't have to be restricted to the given theme. Flatdoc is just really one .js file that expects 2 HTML elements (for menu and content). Start with the blank template and customize as you see fit.

Get blank template >

Misc

Inspirations

The following projects have inspired Flatdoc.

  • Backbone.js - Jeremy's projects have always adopted this "one page documentation" approach which I really love.

  • Docco - Jeremy's Docco introduced me to the world of literate programming, and side-by-side documentation in general.

  • Stripe - Flatdoc took inspiration on the look of their API documentation.

  • DocumentUp - This service has the same idea but does a hosted readme parsing approach.

Attributions

Photo taken from Flickr, licensed under Creative Commons.

Acknowledgements

© 2013, 2014, Rico Sta. Cruz. Released under the MIT License.

Flatdoc is authored and maintained by Rico Sta. Cruz with help from its contributors.

flatdoc's People

Contributors

alexbevi avatar avendael avatar grmlin avatar huangyq23 avatar joeblau avatar jonschlinkert avatar juanbrujo avatar kkirsche avatar lchski avatar malthe avatar marksteve avatar oderwat avatar palday avatar rstacruz avatar uzitech avatar vahe avatar vijayakumarrg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flatdoc's Issues

Search engine indexing

Hi,

We're considering to use flatdoc for the documentation pages seats.io. What might keep us from doing so is search engine indexation: will e.g. Google know how to index a documentation page that is rendered by flatdoc? I guess not, because it's client-side JavaScript code.

Thanks,
Matti

Using image as h1

If you use an image in a h1 then it will no longer generate a link in the menu bar. You could fix this by using the alt text in an image. I think this is a common enough issue since people sometimes use logos at the top of their readme files.

Scroll agent behaviour

hey @rstacruz, I think this is related to #31.

I have a Flatdoc based site here: http://marcanguera.net/awesome-ruby.

The scroll agent has a weird behaviour. I already have a TOC in the Readme file, so I want to remove it from main content (no sense, I have this info into the menu). I'm doing this (weird behaviour increases):

$(document).on('flatdoc:ready', function() {
  $(".content h1 img").remove();
  $(".content ul:first").remove();
});

As you said in the other issue, this is by design, but if we change it to a different implementation, Flatdoc based sites would be even more amazing. Do you think it's possible to fix that? Maybe Planned?

Thanks.

Support for column and row span in flatdoc

Flatdoc is great and it is doing everything we need except markdown support for row and column spans. Is there an easy way to add that? I understand some of the parsers support col and row span.

MultiMarkdown

Would be great if this supported MultiMarkdown features, such as footnotes.

Local file fetch does not work in Chrome

Hi all,
trying template.html with local file Readme.md

<script> Flatdoc.run({ fetcher: Flatdoc.file('Readme.md') }); </script>

I am getting:

Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. file:///home/drasko/Readme.md
XMLHttpRequest cannot load file:///home/drasko/Readme.md. Origin null is not allowed by Access-Control-Allow-Origin. template.html:1
[Flatdoc] fetching Markdown data failed.
Object
flatdoc.js:16
Blocked a frame with origin "http://ghbtns.com" from accessing a frame with origin "null". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "file". Protocols must match.

SVG render width

My README has an SVG browser badge from Sauce Labs, following the docs. There was no width specified in the tag that inserted the SVG. When the window width is enough to show 2 columns (not the 3-column layout), It looks like the image is being drawn as if the width is 100% window width, so the right part of the SVG actually ends up getting cut off.

Why is this a client-side lib?

Am I missing something in not understanding why this isn't a static site generator instead? The client-side generation makes it pretty useless to me…

  • slow (rendering can be lightning fast, it won't beat no rendering at all)
  • no option to speed up serving with a CDN
  • harder to develop (every line of code must work cross-browser)
  • no JS = no doc at all
  • no true client-specific benefit I can see (yes there's no need to redeploy the doc site when your doc contents change, but for the vast majority of cases I imagine a simple deployment script makes this painless)

So… would you consider making it a build-time CLI tool/Grunt task?

Consider rendering with ReactJS for zero load time.

flatdoc looks great. I was considering writing my own documentation renderer with React but flatdoc looks like it has a great start already. Have you considered rendering via reactJS? The benefit to doing so, is that you can still do all the client rendering you like, and client side interactions, but also:

  1. Those client renderings are very fast because ReactJS has a very highly optimized initial render time.
  2. You can seamlessly "prerender" docs on the server, which will just spit out markup that loads instantly in any browser - which is then brought to life after the JavaScript loads (you don't have to know any of this is happening as the user).

Tables and <pre> section side by side

Hi, flatdoc is great.. thanks for open sourcing..

I've an issue with <table> and <pre> section being not aligned properly side by side as show in the picture..
image

i expect them to be side by side like other <p> and <pre> section like

image

even in above image, i expect <pre> section to be aligned with first <p>

I would love to modify this by myself but i don't know CSS/HTML much. please suggest how to achieve this.
Also I'm not sure whether current behavior is intended or not.

regards

utf-8 character encoding for quotes in markdown files

In the markdown, whenever you use:

&quot;
"
'

they are all rendered by flatdoc as their equivalent raw UTF-8 codes ( ie. †).

<meta charset='utf-8'> in the html, as well as <meta charset='iso-8859-1'> made no difference.

Note that this does not happen if the quote appears inside of a code or quote block.

anchors in flatdoc

Loving Flatdoc. Hopefully someone can help.

I'm having trouble with anchors in Flatdoc - for example: http://ricostacruz.com/flatdoc/#javascript-hooks doesn't take you to #javascript-hooks (unless you're already on the page)

I'm guessing that it's because the anchor doesn't exist in the page when it's loaded, but it would be great if it could be picked up somehow once loaded.

Tables with empty headers

Github is just fine with this table:

The other header is empty
something something else

But Flatdoc doesn't render it.

The workaround is to put &nbsp; into the header.

Multiple Markdown Files

It'd be great to be able to include several (or a whole folder of) .md files, and then have Flatdoc simply add them to the navigation on the left, so that a few .md files can be navigated (and several "guides" included in one interface).

"Debug" mode?

What would you recommend is the best way for crafting a README & seeing the rendering via FlatDoc without constantly pushing changes?

Files don't fetch

Hi,
I'm having an issue when fetching files. The GH repos work well but not files... I tried to put absolute paths and relative ones but any worked nor in Firefox neither in Chrome. I'm on a Win8 machine.

What I did:

  • I copy template.html and I leave it in a folder, renaming it to index.html
  • I edit the Initializer section to this: fetcher: Flatdoc.file('Readme.md')
  • Then I put a Readme.md file next to index.html
  • I open index.html with FF or Chrome
  • I get the template correctly rendered but empty

If I change the init to point a GitHub repo, then it works

The same if I put it in a local web server the same occurs. Can anyone help me to find what I'm missing?

Getting 403 (Forbidden)

Hi! I'm trying to create a custom theme, so I downloaded that starting html file and entered rstacruz/flatdoc to USER/REPO and began styling it. I'm getting 403 (Forbidden) error, when refreshing the page after 10-20 minutes of using. I changed repo and user to other and it worked. But after 10 minutes I got the same error. What is it? Is it GitHub blocking my access to any repo?

Request: completely separate styling from logic

Hi, I love Flatdoc, but have decided to implement a front-end framework removing the default theme. I was not able to do that smoothly because some of the code, the Menu creation (Flatdoc.menuView) for example, is set on the core files.

I could make an workaround adding the class after rendering, setting up my own Runner or overriding the current, but seems it has sense to move menuView and any other similar function to the Theme js, instead.

What do you think?

Internal links

I might be doing something wrong, but I can't make this work:

Title
====
Section
--------

### Header

This is the header description

### Footer

This contains a link to [header](#header)

This does not generate a proper link in Footer to go to the Header section (the [header](#header) part),
it should render <a href="#title-section-header">header</a>
but instead renders <a href="#header">header</a>

FYI, the markdown works on github, and putting [header](#title-section-header) instead will break the markdown

Should it be parsing a single line break as <br>?

Or at least allowing an option to enable it? Some IDEs trailing spaces automagically and it's kind of a pain to have to edit the md file in a different editor just to manually double-space the line end instead of just using a single line break.

Embed REST API calls in markdown

Hi,

Is there any way we can embed REST API calls into the flatdoc generated pages. Like a "Try Out" or a "Request" button and get a response from API and show it there itself.

Tables get screwed

Hi, first of all, thank you for this project! It's amazing and I've been using it a lot! Its simplicity and the super clean design are amazing. Great job.

But, as it's normal, not everything works perfectly all the time. Recently I updated my README to add a table and I realised it got weird on the flatdoc.

Check it out under the section "Platform badge": http://fjcaetano.github.io/cocoapod-badges/

Aligning right col with multiple paragraphs in left

It appears to be impossible to keep the left col from leaving huge gaps between elements.

If using multiple smallish paragraphs, there will be a large gap either before or after as you attempt to line up the codeblock. I tried using a list, parses properly as a single <ul>, but the code on the right won't align either: it either leaves a huge gap between the description paragraph and the <ul> or it starts the code block after the last line of the list, leaving a huge gap at the top.

Theme menu bug when <h4> have the same name

Hi!
I've used Flatdoc and it worked like a charm except for one small thing :

screen shot 2013-06-28 at 1 05 52 pm

In the default theme, I get this bug when scrolling if I have different h4 with the same title.
The active class is applied to all of them.

Ability to define a table of contents?

Is it possible to define a table of contents for navigation purposes? E.g. an .md file would look like this:

# Section one
- [Link](file.md)
- [Link 2](file2.md)
  - [Nested link](file3.md)

# Section two
...

This would allow documentation designers to organize the documentation navigation menu.

Code block out of viewport

When viewing documentation on a normal screen with the default 'white' theme codes in code blocks runs out of the viewport. While on moble views the code blocks are rendered in a responsive scrollable block, this might also be a good option for the regular-non-mobile version.

Update: The interesting thing is, if the viewport is set to 1180px, the scroll function is enabled, if it is set to 1181px or more it is disabled, I try to find a solution but I'm not sure I will succeed.

"Getting Started" template on front page doesn't match downloaded version / doesn't work as is

Just to let you know: I hit a confusion trying out flatdoc today. I copied/pasted the "Getting Started snippet" from the flatdoc front page, and couldn't get it to work. I then realised that the download link in that section of the page gives you a different version, which did work for me, and by comparing the two, I realised that what was missing from the snippet I'd copied/pasted was class='content' on the flatdoc-content div. (I'm using Google Chrome 27.0.1453.110 under OSX 10.7.5, btw.)

Just thought you might like to know.

provide a "latest" tag

Providing a "latest" tag would make it possible to link to https://cdn.rawgit.com/rstacruz/flatdoc/latest/flatdoc.js in the template. So new versions are used automatically.

Default Theme broken in 0.8.6

When using the template in the README the script.js file throws up when trying to find a .menubar element.

If I add the menubar class to the template somewhere then things render but its a mess. The content container has the same x position as the menu.

Is there a newer template for the current version?

Not working ...

First error:
Uncaught SyntaxError: Invalid regular expression: /[À-ß][€-¿]|[à -ï][€-¿]{2}|[ð-÷][€-¿]{3}/: Range out of order in character class
Second:
Uncaught TypeError: Cannot call method 'decode' of undefined

Relative links break

GitHub recommends using relative links to link to files and images in your repo.

[download this file](build/foo.html)

![screenshot of something](screenshot-1.png)

However, these links do not convert to repo links, and instead look in the same directory as the flatdoc template.

Issues with Markdown and images

Hello!

I have detected a problem when the markdown file have images: The navbar active tab don't work fine because haven't in consideration the space of the images.

Normally active navbar section is different than the section that you are watching.

You can see a demo of this in the following link > http://server-dummies.herokuapp.com

Navigation issue on multiple headers with same name.

Nice work with FlatDoc! Very clean.

With the sample markdown below, clicking on the subheader 'A' on the left side menu will take you to the first header 'A'.

# A
Text text text.
## B
Text text text.
## C
Text text text.
## A
Text text text.
## D
Text text text.

For a more realistic example, see here: http://svs14.github.io/Orchestra.jl/
The header 'Orchestra' is used twice, and only navigates to the first.

Slug issue

There has already a PR for non-latin slug issue, so please refer to #50 and #13 for the details.

This issue is aimed for providing another way, to set a slug, instead of automatically fetch from the headings. Ideas are welcome.

Two column instead of three?

Is it possible to show two column instead of three?
Now it looks like menu-content-code, but for some pages, I would want menu-content or menu-code, instead of showing them all...

flatdoc in production does not work

When using the flatdoc with MEAN stack in the development and test environment, it works well. However, it does not work in the production environment. Nothing in the .md file got displayed. I am wondering if someone has the similar problem.

Interaction with Private Repositories?

Is there any way for Flatdoc to interact with private repositories? I know that GitHub's API provides a way, but I haven't seen it documented in Flatdoc at all.

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.