Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support frontmatter for options #177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/frontmatter.md
@@ -0,0 +1,25 @@
---
title: Basic Example
author:
name: Jordan Scales
twitter: jdan
url: http://jordanscales.com
output: frontmatter.html
---

--

# Cleaver 101
## A first look at quick HTML presentations

-- bg blink

### A textual example

Content can be written in **Markdown!** New lines no longer need two angle brackets.

This will be in a separate paragraph.

<img src="https://github.global.ssl.fastly.net/images/modules/logos_page/GitHub-Logo.png" width="50%">

[Here's a link](http://google.com).
15 changes: 12 additions & 3 deletions lib/index.js
Expand Up @@ -296,7 +296,7 @@ Cleaver.prototype.renderAuthorSlide = function (content) {
* @return {Array.<string>} A list of all slides
*/
Cleaver.prototype.slice = function(document) {
var cuts = document.split(/\n(?=\-\-)/);
var cuts = document.split(/\n(?=\-\-[^-])/);
var slices = [];
var nlIndex;

Expand All @@ -307,9 +307,9 @@ Cleaver.prototype.slice = function(document) {
*
* Otherwise, we slice off the `--` at the beginning.
*/
if (!cuts[i].match(/^--/)) {
if (!cuts[i].match(/^--[^-]/)) {
slices.push({
content: cuts[i].trim()
content: this.unwrapFrontmatter(cuts[i])
});

continue;
Expand Down Expand Up @@ -342,6 +342,15 @@ Cleaver.prototype.slice = function(document) {
return slices;
};

/**
* Strips frontmatter tags (---) around YAML.
*
* @param {string} A slide content
* @return {string} A slide content without frontmatter tags
*/
Cleaver.prototype.unwrapFrontmatter = function(content) {
return content.trim().replace(/^---\n/, '').replace(/\n---$/, '');
};

/**
* Method to run the whole show.
Expand Down