All Projects → bnjmnt4n → reveal-code-focus

bnjmnt4n / reveal-code-focus

Licence: MIT license
A Reveal.js plugin that allows focusing on specific lines of code blocks.

Programming Languages

HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to reveal-code-focus

CodeEditorView
Code Editor UITextView
Stars: ✭ 20 (-81.48%)
Mutual labels:  code, highlight
laravel-markdown
A highly configurable markdown renderer and Blade component for Laravel
Stars: ✭ 159 (+47.22%)
Mutual labels:  code, highlight
Highlightjs Line Numbers.js
Line numbering plugin for Highlight.js
Stars: ✭ 323 (+199.07%)
Mutual labels:  code, highlight
marknotes
📝 You’re taking a lot of notes and need a solution to manage them i.e. put your knowledge base in one central place and being able to retrieve quickly information’s, display them nicely through the browser as a HTML page or a slideshow, export them in many file formats (docx, odt, pdf, txt, …). Sensitive information’s can be encrypted and notes …
Stars: ✭ 73 (-32.41%)
Mutual labels:  reveal-js
vue-focus-keyboard
A keyboard component for Vue. Start to write immediately. No input element definition. Plug and play!
Stars: ✭ 63 (-41.67%)
Mutual labels:  focus
codeReads
goodReads (pun intended) for coding and programming
Stars: ✭ 29 (-73.15%)
Mutual labels:  code
gintonic
A declarative transformation language for GraphQL 🍸
Stars: ✭ 27 (-75%)
Mutual labels:  code
i-am-root-nuget-package
📦🏴‍☠️ NuGet package that shows we can run arbitrary code from any NuGet package
Stars: ✭ 22 (-79.63%)
Mutual labels:  code
Lua-Obfuscator
Obfuscate your lua code because it's so easy to steal!
Stars: ✭ 69 (-36.11%)
Mutual labels:  code
PasteServer
PasteServer to upload text or code
Stars: ✭ 29 (-73.15%)
Mutual labels:  code
lrud
Left, Right, Up, Down. A spatial navigation library for devices with input via directional controls
Stars: ✭ 31 (-71.3%)
Mutual labels:  focus
GitHub-tab-size
📏 Userstyle to set a custom tab-size on GitHub and Gist
Stars: ✭ 17 (-84.26%)
Mutual labels:  code
Sketch-Highlighter
Sketch plugin that generates highlights for selected text layers
Stars: ✭ 41 (-62.04%)
Mutual labels:  highlight
awesome-end2end-speech-recognition
💬 A list of End-to-End speech recognition, including papers, codes and other materials
Stars: ✭ 49 (-54.63%)
Mutual labels:  code
Fundamental-Kotlin
Code examples for the Fundamental Kotlin book.
Stars: ✭ 16 (-85.19%)
Mutual labels:  code
Bagel
IPCCC 2018: Robust and Unsupervised KPI Anomaly Detection Based on Conditional Variational Autoencoder
Stars: ✭ 45 (-58.33%)
Mutual labels:  code
open-source-DSA-code
open source contribution during hacktoberfest for beginners.
Stars: ✭ 31 (-71.3%)
Mutual labels:  code
open source start
Go through the readme... fork ....add....send a pull request .... get yourself in the contribution list...Plant the tree
Stars: ✭ 10 (-90.74%)
Mutual labels:  code
playcode
Online Javascript Editor
Stars: ✭ 127 (+17.59%)
Mutual labels:  code
sandboni-core
Sandboni - Java test optimization library which reduces test execution time without compromising quality
Stars: ✭ 27 (-75%)
Mutual labels:  code

reveal-code-focus

A Reveal.js plugin that allows focusing on specific lines of code blocks.

View the live demo.

Installation

Using npm:

$ npm install --save reveal-code-focus

Dependencies

reveal-code-focus must first be loaded along with highlight.js (used for code highlighting).

Reveal.initialize({
  // Include other options…
  dependencies: [
    // Include other dependencies…
    // Load highlight.js
    { src: 'path/to/highlight.pack.js' },
    {
      src: 'node_modules/reveal-code-focus/reveal-code-focus.js',
      async: true,
      callback: function() {
        RevealCodeFocus();
      }
    }
  ]
});

Note: the highlight.js file mentioned is not the Reveal.js plugin, but the actual highlight.js library.

How it works

reveal-code-focus breaks down code blocks into individual lines. Fragments with the attribute data-code-focus are then associated with the lines of code to focus on. When these fragments are displayed, reveal-code-focus will focus on the respective lines of code.

Each line of code is wrapped in a <span> element with a class of "line". When lines are focused on, they will also have the "focus" class. The .line.focus selector can thus be used for custom styling to highlight particular lines.

Usage

<section>
  <pre><code>
  // Useless comment.
  alert('hi');
  </pre></code>
  <p class="fragment" data-code-focus="1">
    When this fragment is shown, the first line of code (`span.line`) will have the `"focus"` class added to it.
  </p>
  <p class="fragment" data-code-focus="1-2">
    Another fragment. This time, both lines will now have the `"focus"` class.
  </p>
</section>

Styling

The most important style is to ensure that .line is set to display: block, so that lines will be rendered as block elements. You can then customize your CSS to set a different background or text colour when lines are focused on.

.line { display: block; }
.line.focus { background: yellow; }

You can also use a specific theme by default then switch to a different one when lines are focused on.

/* use a specific highlight.js theme by default */
/* eg. solarized dark */
/* … */

.line { display: block; }
/* on focused: switch to solarized light */
.line.focus { background: #fdf6e3; color: #657b83; }
.line.focus .hljs-comment, .line.focus .hljs-quote { color: #93a1a1; }
/* … */

Configuration

reveal-code-focus can be configured by passing in an options object.

// Configure `reveal-code-focus`.
RevealCodeFocus({
  // options
});

scrollToFocused

scrollToFocused automatically scrolls the <code> elements such that the lines of code to be focused on is centered. This is enabled by default.

RevealCodeFocus({
  scrollToFocused: false // default: true
});

Multiple code blocks

For slides with multiple code blocks, the data-code-block attribute can be used to focus on lines from a particular code block. By default, all fragments will focus on the first code block, unless otherwise specified.

<span class="fragment"
  data-code-focus="1-5"
  data-code-block="2">
</span>

data-trim

The data-trim attribute can be used to indicate that code blocks should have whitespace trimmed from their front and back.

<pre><code data-trim>

.line { display: block; }
.line.focus { background: yellow; }

</code></pre>

Demo

View the live demo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].