Skip to content

Commit

Permalink
Added lead option to markdown.json, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sethen committed Mar 6, 2015
1 parent 9bf262c commit 718988e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ node path/to/markdown-include.js path/to/markdown.json

`markdown.json` can be populated with the following options:

| Option | Type | Description |
|:-------------------------:|:-------------:|:--------------------------------------------------------------------------:|
| `build` | String | File path of where everything should be compiled, like `README.md` |
| `files` | Array | Array of files to to compile |
| `tableOfContents` | Object | Object to hold options for table of contents generation |
| `tableOfContents.heading` | String | Heading for table of contents, added to the `tableOfContents` object |

| Option | Type | Description |
|:-------------------------:|:-------:|:--------------------------------------------------------------------------:|
| `build` | String | File path of where everything should be compiled, like `README.md`. |
| `files` | Array | Array of files to to compile. |
| `tableOfContents` | Object | Object to hold options for table of contents generation. |
| `tableOfContents.heading` | String | Heading for table of contents (use markdown syntax if desired). |
| `tableOfContents.lead` | String | What navigation items in table of contents lead with. If value is `number` will add numbers before each item and subitem. If not, will add asterisks. Refer to markdown syntax to understand the difference. |
# How It Works

markdown-include works by recursively going through files based on the tags that are found. For instance, consider the following in a `_README.md` file:
Expand Down
13 changes: 7 additions & 6 deletions docs/how_to_use.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ node path/to/markdown-include.js path/to/markdown.json

`markdown.json` can be populated with the following options:

| Option | Type | Description |
|:-------------------------:|:-------------:|:--------------------------------------------------------------------------:|
| `build` | String | File path of where everything should be compiled, like `README.md` |
| `files` | Array | Array of files to to compile |
| `tableOfContents` | Object | Object to hold options for table of contents generation |
| `tableOfContents.heading` | String | Heading for table of contents (use markdown syntax if desired) |
| Option | Type | Description |
|:-------------------------:|:-------:|:--------------------------------------------------------------------------:|
| `build` | String | File path of where everything should be compiled, like `README.md`. |
| `files` | Array | Array of files to to compile. |
| `tableOfContents` | Object | Object to hold options for table of contents generation. |
| `tableOfContents.heading` | String | Heading for table of contents (use markdown syntax if desired). |
| `tableOfContents.lead` | String | What navigation items in table of contents lead with. If value is `number` will add numbers before each item and subitem. If not, will add asterisks. Refer to markdown syntax to understand the difference. |
33 changes: 15 additions & 18 deletions markdown-include.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

var exec = require('child_process').exec;
var fs = require('fs');
var build = {};
var includePattern = /^#include\s"(.+\/|\/|\w|-|\/)+.md"/gm;
var ignorePattern = /^#include\s"(.+\/|\/|\w|-|\/)+.md" !ignore/gm;
var headingPattern = /^#+\s.+ !heading/gm;
var build = {};
var tableOfContents = '';
var options;

/**
* Builds links for table of contents
Expand Down Expand Up @@ -48,6 +49,7 @@
var item = headingTag.substring(count + 1);
var index = headingTag.indexOf(item);
var headingTrimmed = buildLinkString(headingTag.substring(index));
var lead = options.tableOfContents.lead && options.tableOfContents.lead === 'number' ? '1.' : '*';
var navItem;

/**
Expand All @@ -61,22 +63,22 @@

switch (obj.count) {
case 1:
navItem = '* ' + buildNavItem(headingTrimmed);
navItem = lead + ' ' + buildNavItem(headingTrimmed);
break;
case 2:
navItem = ' * ' + buildNavItem(headingTrimmed);
navItem = ' ' + lead + ' ' + buildNavItem(headingTrimmed);
break;
case 3:
navItem = ' * ' + buildNavItem(headingTrimmed);
navItem = ' ' + lead + ' ' + buildNavItem(headingTrimmed);
break;
case 4:
navItem = ' * ' + buildNavItem(headingTrimmed);
navItem = ' ' + lead + ' ' + buildNavItem(headingTrimmed);
break;
case 5:
navItem = ' * ' + buildNavItem(headingTrimmed);
navItem = ' ' + lead + ' ' + buildNavItem(headingTrimmed);
break;
case 6:
navItem = ' * ' + buildNavItem(headingTrimmed);
navItem = ' ' + lead + ' ' + buildNavItem(headingTrimmed);
break;
}

Expand All @@ -93,7 +95,7 @@
throw err;
}

var options = JSON.parse(data.toString());
options = JSON.parse(data.toString());
var files = options.files;
var i;

Expand All @@ -118,7 +120,7 @@
}
}

writeFile(options, build[file].parsedData);
writeFile(build[file].parsedData);
}
});
}
Expand Down Expand Up @@ -324,16 +326,11 @@
var currentPatternTagLength = patterns[i].length;
var replacedTag = currentPattern.substring(0, currentPatternTagLength - stringLength);

if (obj.replace) {
console.log('do something else');
if (replacedData) {
replacedData = replacedData.replace(currentPattern, replacedTag);
}
else {
if (replacedData) {
replacedData = replacedData.replace(currentPattern, replacedTag);
}
else {
replacedData = obj.data.replace(currentPattern, replacedTag);
}
replacedData = obj.data.replace(currentPattern, replacedTag);
}
}

Expand All @@ -346,7 +343,7 @@
* @param {String} path Path to build new file
* @param {String} data Data to write into file
*/
function writeFile(options, parsedData) {
function writeFile(parsedData) {
fs.writeFile(options.build, parsedData, function (err) {
if (err) {
throw err;
Expand Down

0 comments on commit 718988e

Please sign in to comment.