Permalink
Browse files

Rewrite

  • Loading branch information...
webpro committed Feb 19, 2017
1 parent f80ead3 commit 05c76ec570fd8ccfa10bc5bad81cdbb138179215
Showing with 575 additions and 429 deletions.
  1. +28 −2 .eslintrc
  2. +1 −0 .gitignore
  3. +7 −12 README.md
  4. +22 −144 bin/cli.js
  5. +0 −245 bin/server.js
  6. +3 −1 demo/sub/c.md
  7. +16 −0 lib/defaults.json
  8. +36 −0 lib/index.js
  9. +119 −0 lib/options.js
  10. +33 −0 lib/print.js
  11. +86 −0 lib/render.js
  12. +70 −0 lib/serve.js
  13. +25 −0 lib/static.js
  14. +1 −1 { → lib}/template/listing.html
  15. +18 −21 { → lib}/template/reveal.html
  16. +16 −3 package.json
  17. +7 −0 test/preproc.js
  18. +87 −0 test/render.spec.js
@@ -2,9 +2,35 @@
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {}
},
"extends": "eslint:recommended",
"plugins": [
"import"
],
"rules": {
"strict": 0,
"quotes": [1, "single"],
"semi": [1, "always"]
"indent": ["error", 2],
"quotes": [2, "single"],
"semi": [2, "always"],
"keyword-spacing": [2, {
"before": true,
"after": true,
"overrides": {
"catch": { "after": false},
"for": {"after": false},
"if": {"after": false},
"switch": { "after": false},
"while": {"after": false}
}
}],
"eqeqeq": [2, "smart"],
"no-multi-spaces": 2,
"import/no-unresolved": 2
},
"globals": {
"Promise": true
}
}
@@ -1,3 +1,4 @@
node_modules
.idea
dist
_static
@@ -205,18 +205,13 @@ the script `preproc.js`:
```javascript
// headings trigger a new slide
// headings with a caret (e.g., '##^ foo`) trigger a new vertical slide
module.exports = (mkd,opt) =>
mkd.split( "\n" )
.map( line => {
if ( ! /^#/.test(line) ) return line;
var is_vertical = /#\^/.test(line);
return (
is_vertical ? "\n\n<!--v-->\n\n" : "\n\n---\n\n"
) + line.replace( '#^', '#' );
})
.join("\n");
module.exports = (markdown, options) => {
return markdown.split('\n').map((line, index) => {
if(!/^#/.test(line) || index === 0) return line;
const is_vertical = /#\^/.test(line);
return (is_vertical ? '\n----\n\n' : '\n---\n\n') + line.replace('#^', '#');
}).join('\n');
};
```

and use it like this
@@ -1,152 +1,30 @@
#!/usr/bin/env node

var fs = require('fs'),
path = require('path'),
glob = require('glob'),
program = require('commander'),
server = require('./server'),
pkg = require('../package.json');

var basePath = process.cwd(),
baseName,
filePath,
revealPath = path.resolve(require.resolve('reveal.js'), '..', '..'),
theme = 'black',
highlightTheme = 'zenburn',
watch = false,
title;
const program = require('commander'),
defaults = require('../lib/defaults'),
revealMarkdown = require('./../lib'),
pkg = require('../package.json');

program
.version(pkg.version)
.usage('<slides.md> [options]')
.option('-h, --host [host]', 'Host')
.option('-p, --port [port]', 'Port')
.option('-t, --theme [theme]', 'Theme')
.option('-H, --highlightTheme [highlight theme]', 'Highlight theme')
.option('--title [title]', 'Title of the presentation')
.option('-r, --print [filename]', 'Print')
.option('-s, --separator [separator]', 'Slide separator')
.option('-v, --verticalSeparator [vertical separator]', 'Vertical slide separator')
.option('-i, --scripts [list of scripts]', 'Scripts to inject into the page')
.option('-w, --watch', 'Watch for changes in markdown file and livereload presentation')
.option('--disableAutoOpen', 'Disable to automatically open your web browser')
.option('-P, --preprocessor [script]', 'Preprocessor script')
.option('--static', 'Export static html to stdout. Save to reveal.js/index.html to' +
' match dependencies. HINT: printing does not work properly in this mode')
.parse(process.argv);
.version(pkg.version)
.usage('<slides.md> [options]')
.option('-D, --disable-auto-open', 'Disable auto-opening your web browser', defaults.disableAutoOpen)
.option('-H, --highlight-theme <theme>', 'Highlight theme [zenburn]', defaults.highlightTheme)
.option('-h, --host <host>', 'Host [localhost]', defaults.host)
.option('-i, --scripts <scripts>', 'Scripts to inject into the page', defaults.scripts)
.option('-m, --preprocessor <script>', 'Markdown preprocessor script', defaults.preprocessor)
.option('-p, --port <port>', 'Port [1948]', defaults.port)
.option('-P, --print [filename]', 'Print', defaults.print)
.option('-t, --theme <theme>', 'Theme [black]', defaults.theme)
.option('-T, --title <title>', 'Title of the presentation', defaults.title)
.option('-s, --separator <separator>', 'Slide separator', defaults.separator)
.option('-S, --static [dir]', 'Export static html to directory [_static]. Incompatible with --print.', defaults.static)
.option('-v, --vertical-separator <separator>', 'Vertical slide separator', defaults.verticalSeparator)
.option('-w, --watch', 'Watch for changes in markdown file and livereload presentation [false]', defaults.watch)
.parse(process.argv);

if(program.args.length > 2) {
program.help();
}

var pathArg = program.args[0];

// TODO: fix user can have own demo file/directory
if(pathArg === 'demo') {

basePath = path.join(__dirname, '../demo');

} else if(pathArg) {

filePath = path.resolve(pathArg);

if(fs.existsSync(filePath)) {

var stat = fs.statSync(filePath);

if(stat.isFile()) {

basePath = path.dirname(filePath);
baseName = path.basename(filePath);

} else if(stat.isDirectory()) {

basePath = filePath;

}

} else {

basePath = baseName = pathArg;

}
}

if (program.theme && program.theme.match(/^http.*css$/)) {
theme = program.theme;
} else {
theme = glob.sync('css/theme/*.css', {
cwd: revealPath
}).concat(glob.sync('theme/*.css', {
cwd: path.resolve(basePath)
})).filter(function(themePath) {
return path.basename(themePath).replace(path.extname(themePath), '') === program.theme;
}).pop() || 'css/theme/' + theme + '.css';
}
highlightTheme = program.highlightTheme || highlightTheme;
title = program.title || title;

// load custom reveal.js options from reveal.json
var revealOptions = {};
var manifestPath = path.join(basePath, 'reveal.json');
if(fs.existsSync(manifestPath) && fs.statSync(manifestPath).isFile(manifestPath)) {
try {
var options = require(manifestPath);
if(typeof options === 'object') {
revealOptions = options;
}
} catch(err) {
console.log(err);
}
}

// overide default theme from manifest options
if(!program.theme && revealOptions.theme) {
theme = revealOptions.theme;
}

// overide default highlight theme from manifest options
if(!program.highlightTheme && revealOptions.highlightTheme) {
highlightTheme = revealOptions.highlightTheme;
}

var scripts = (typeof program.scripts === 'string' ? program.scripts.split(',') : []).map(function(script) {
return script[0] === '/' ? script : path.resolve(process.cwd(), script);
});

if(program.static) {
server.toStaticHTML({
basePath: basePath,
initialMarkdownPath: baseName,
theme: theme,
highlightTheme: highlightTheme,
title: title,
separator: program.separator,
verticalSeparator: program.verticalSeparator,
printFile: program.print,
revealOptions: revealOptions,
scripts: scripts,
preprocessor: program.preprocessor,
watch: program.watch
});
} else {
server.start({
basePath: basePath,
initialMarkdownPath: baseName,
host: program.host,
port: program.port,
theme: theme,
highlightTheme: highlightTheme,
title: title,
separator: program.separator,
verticalSeparator: program.verticalSeparator,
printFile: program.print,
revealOptions: revealOptions,
openWebBrowser: !program.disableAutoOpen,
scripts: scripts,
preprocessor: program.preprocessor,
watch: program.watch
});
program.help();
}

// TODO: include make_static here!
revealMarkdown(program);
Oops, something went wrong.

0 comments on commit 05c76ec

Please sign in to comment.