Code Monkey home page Code Monkey logo

jekyll-include_snippet's Introduction

Jekyll::IncludeSnippet

Include snippets of text from external files into your markdown

Installation

Add it to your Gemfile (in a way that Jekyll will load):

source 'https://rubygems.org'

group :jekyll_plugins do
  gem 'jekyll-include_snippet'
end

Usage

Put the special "begin-snippet" and "end-snippet" comments into your source file:

# blah.rb

class Blah
  # begin-snippet: my_method_snippet
  def blah
    puts 'blah blah blah'
  end
  # end-snippet
end

Use it from your markdown:

---
title: "My Blerg Post"
date: "2018-01-01"
---

Blah blah here is some code:

```ruby
{% include_snippet my_method_snippet from path/to/blah.rb %}
```

Optionally, you can set a default source path in the YAML frontmatter:

---
title: "My Blerg Post"
date: "2018-01-01"
snippet_source: "path/to/blah.rb"
---

```ruby
{% include_snippet my_method_snippet %}
```

Languages Other Than Ruby

If you're using another language, you will probably need to change the "comment prefix".

---
title: "My Blerg Post"
date: "2018-01-01"
snippet_comment_prefix: "//"
---

```js
{% include_snippet whatever from whatever.js %}
```
// whatever.js

// begin-snippet: whatever
function whatever() {
  console.log("Hello there");
}
// end-snippet

License

The gem is available as open source under the terms of the MIT License.

TODO

  • Could easily be optimised for better performance
  • Maybe a feature for evaluating code and including the result

jekyll-include_snippet's People

Contributors

tomdalling avatar

Stargazers

Andy Coates avatar Mario E. Bermonti Pérez avatar Daniel Warner Smith avatar Josh Thompson avatar Mike Coutermarsh avatar Devendra Tewari avatar Joseph Junker avatar Aliou Diallo avatar Giuliano Garcés avatar Susan Joshi avatar Joren De Groof avatar Saroj Maharjan avatar Andreas Ofner avatar Andy Waite avatar Gerald Bauer avatar

Watchers

 avatar James Cloos avatar

Forkers

carolkng

jekyll-include_snippet's Issues

Fails with Go and other C like languages

It seems that the plugin fails for any C like language.

Here's an example document:

---
title: Hello
layout: page
---

# Hello

```go
{% include_snippet my_method_snippet from code/hello.go %}
```

The code for code/hello.go looks something like this

// #begin-snippet: my_method_snippet

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}

// #end-snippet

When it is rendered, it looks like this:

ackage main
mport "fmt"
unc main() {
fmt.Println("Hello World")

Instead, it should look something like this:

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}

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.