From 2d29121e2e6a49912cd5e635974737d1002b6d3e Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 31 Mar 2014 15:54:26 -0700 Subject: [PATCH] Add lex sub-command to gitbook binary The lex command is useful for debugging files and seeing how they are parsed --- bin/gitbook.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bin/gitbook.js b/bin/gitbook.js index 6ec3e79b5..ad251f2d2 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -5,8 +5,11 @@ var _ = require('lodash'); var path = require('path'); var prog = require('commander'); +var fs = require('fs'); + var pkg = require('../package.json'); var generate = require("../lib/generate"); +var parse = require("../lib/parse"); var utils = require('./utils'); @@ -53,6 +56,16 @@ prog }); }); +prog +.command('lex ') +.description('Parse a page file into sections, display JSON dump') +.action(function(page_file) { + var parsed = parse.page(fs.readFileSync(page_file, 'utf-8')); + + console.log(JSON.stringify(parsed, null, 4)); +}); + + // Parse and fallback to help if no args if(_.isEmpty(prog.parse(process.argv).args) && process.argv.length === 2) {