Giter Site home page Giter Site logo

gitbook-plugin-snippet's Introduction

Snippets for GitBook

Include entire code files or fragments of code files in your pages. Read files from file system, or from git.

Installation

{
  "plugins": [
    "snippet@git+https://github.com/cucumber-ltd/gitbook-plugin-snippet.git"
  ],
  "pluginsConfig": {
    "snippet": {
      "problem": "fail"
    }
  }
}

The problem property can be "warn" ,"error" or "fail". Default is "error".

Include entire file

Let's say you have a file some/file.rb:

puts "hello"

You can include its contents in a document as follows:

Look at this code:

```ruby
[snippet](some/file.rb)
```

The [snippet](...) link will be replaced with the entire contents of the file:

Look at this code:

```ruby
puts "hello"
```

Include fragments from files

Let's say you have a file some/file-with-fragment.rb with doxygen-like block markers:

class Fragment
  ### [the-marker]
  if true
    puts "the fragment"
  end
  ### [the-marker]
end

You can include just the fragment between the markers as follows:

Look at this code:

```ruby
[snippet](some/file-with-fragment.rb#the-marker)
```

Result:

Look at this code:

```ruby
if true
  puts "the fragment"
end
```

Note that the fragment has been unindented while preserving whitespace.

Include files from git

Just apend @ after the marker, followed by the commit message (or substring of commit message). Example:

[snippet](some/file-with-fragment.rb#the-marker@this fixes a bug)

All branches will be searched. If multiple commits match the commit message, the most recent one is always picked.

Inspiration

gitbook-plugin-snippet's People

Contributors

aslakhellesoy avatar

Watchers

 avatar  avatar

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.