GithubHelp home page GithubHelp logo

rlugojr / reveal-sampler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ldionne/reveal-sampler

0.0 1.0 0.0 1.45 MB

A reveal.js plugin to fetch code samples from source files

C++ 0.28% CSS 41.38% HTML 1.34% JavaScript 56.92% C 0.05% Ruby 0.03%

reveal-sampler's Introduction

sampler.js

A reveal.js plugin to include code samples in slides

Dependencies

This plugin depends on jQuery, so make sure it is loaded before the plugin is loaded.

Usage

First, initialize the plugin in the dependencies part of the reveal.js config:

{ src: 'plugin/sampler.js' }

This assumes that you copied the sampler.js file to plugin/sampler.js in your reveal.js tree, but you can pick whatever you want. To include a code sample in a slide, use <code> tags as follows:

<pre><code class='sample' sample='path/to/source#sample-name'></code></pre>

The plugin will extract the sample named sample-name from the source file whose path is given, and write it inside the <code> tag. If no sample-name is given, the whole file is included. The plugin will also add the language-xxx class to the <code> tag, where xxx is the extension of the source file, so that code highlighting triggers properly if set up. This usually works out of the box, because highlight.js can recognize the extensions associated to most languages. If you need to explicitly set the language to use (e.g. because the file extension is misleading), set the language-xxx class yourself on the <code> tag and the plugin will leave it alone. To define a sample inside a source file, use the following syntax to delimit code samples:

...

sample(sample-name)
code-inside-the-sample
end-sample

...

sampler.js will parse the source file, and anything between the sample(...) and the end-sample tags will be taken to be a code sample named sample-name. Including that code sample in a slide will cause all the code between the two special tags to be included in that slide. However, anything on the same line as one of the special tags will not be taken as part of the sample, which allows commenting the tags:

// sample(sample-name)
...
// end-sample

Multiple samples can appear in the same source file, as long as they have different names. If many samples have the same name, they will be considered as a single sample and concatenated together, which can be useful to avoid showing unimportant bits of code in a slide. For example, the following code will create a single sample with name 'sample-name':

// sample(sample-name)
first part of the sample
// end-sample

some code not in the sample

// sample(sample-name)
second part of the sample
// end-sample

It's that simple! To get started, you can find an example of using the plugin in the example/ directory.

License

sampler.js is placed in the public domain.

reveal-sampler's People

Contributors

ldionne avatar

Watchers

 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.