documentary
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -10,2 +10,4 @@ "use strict"; | ||
var _util = require("util"); | ||
var _rules = require("./rules"); | ||
@@ -21,4 +23,8 @@ | ||
var _spawncommand = _interopRequireDefault(require("spawncommand")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const LOG = (0, _util.debuglog)('doc'); | ||
function createReplaceStream(toc) { | ||
@@ -40,2 +46,31 @@ const tocRule = (0, _rules.createTocRule)(toc); | ||
}, { | ||
re: /%TREE (.+)%/mg, | ||
async replacement(match, m) { | ||
const args = m.split(' '); | ||
const p = (0, _spawncommand.default)('tree', ['--noreport', ...args]); | ||
try { | ||
const { | ||
stdout | ||
} = await p.promise; | ||
if (/\[error opening dir\]/.test(stdout)) { | ||
LOG('Could not generate a tree for %s', args.join(' ')); | ||
return match; | ||
} | ||
return escape(stdout); | ||
} catch (err) { | ||
if (err.code == 'ENOENT') { | ||
console.warn('tree is not installed'); | ||
return match; | ||
} | ||
LOG(err.message); | ||
return match; | ||
} | ||
} | ||
}, tocRule, _rules.badgeRule, _table.default, _methodTitle.default, _example.default, { | ||
@@ -51,2 +86,4 @@ re: new RegExp(marker, 'g'), | ||
} | ||
const escape = m => `\`\`\`m\n${m.trim()}\n\`\`\``; | ||
//# sourceMappingURL=replace-stream.js.map |
## 21 June 2018 | ||
### 1.5.0 | ||
- [feature] `tree` rule to embed directories structures representation | ||
- [doc] embed examples, generate trees | ||
### 1.4.2 | ||
@@ -4,0 +9,0 @@ |
{ | ||
"name": "documentary", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "A library to manage documentation, such as README, usage, man pages and changelog.", | ||
@@ -5,0 +5,0 @@ "main": "build", |
@@ -29,3 +29,4 @@ # documentary | ||
- [API](#api) | ||
* [`new Toc()`](#new-toc) | ||
* [`Toc` Type](#toc-type) | ||
* [`constructor(config?: object): Toc`](#constructorconfig-skiplevelone-boolean--false-toc) | ||
@@ -153,17 +154,19 @@ ## Installation & Usage | ||
```m | ||
README | ||
documentation | ||
├── 1-installation-and-usage | ||
│ ├── 1-vs-code.md | ||
│ └── index.md | ||
│ ├── 1-vs-code.md | ||
│ └── index.md | ||
├── 2-features | ||
│ ├── 1-TOC-generation.md | ||
│ ├── 2-table-display.md | ||
│ ├── 3-method-title.md | ||
│ ├── 4-comment-stripping.md | ||
│ ├── 5-file-splitting.md | ||
│ └── index.md | ||
│ ├── 1-TOC-generation.md | ||
│ ├── 2-table-display.md | ||
│ ├── 3-method-title.md | ||
│ ├── 4-comment-stripping.md | ||
│ ├── 5-file-splitting.md | ||
│ ├── 6-rules.md | ||
│ ├── 7-examples.md | ||
│ └── index.md | ||
├── 3-cli.md | ||
├── 4-api | ||
│ ├── 1-toc.md | ||
│ └── index.md | ||
│ ├── 1-toc.md | ||
│ └── index.md | ||
├── footer.md | ||
@@ -179,2 +182,3 @@ └── index.md | ||
| `%NPM: package-name%` | Adds an NPM badge, e.g., `[![npm version] (https://badge.fury.io/js/documentary.svg)] (https://npmjs.org/package/documentary)` | | ||
| `%TREE directory ...args` | Executes the `tree` command with the given arguments. If `tree` is not installed, warns and does not replace the match. | | ||
### Examples Placement | ||
@@ -252,7 +256,11 @@ | ||
The programmatic use of the `documentary` is intended for developers who want to use this software in their projects. | ||
### `new Toc()` | ||
### `Toc` Type | ||
Toc is a transform stream which can generate a table of contents. | ||
`Toc` is a transform stream which can generate a table of contents for incoming markdown data. For every title that the transform sees, it will push the appropriate level of the table of contents. | ||
```js | ||
### `constructor(`<br/> `config?: {`<br/> `skipLevelOne?: boolean = false,`<br/> `},`<br/>`): Toc` | ||
Create a new instance of a `Toc` stream. | ||
```javascript | ||
/* yarn example/toc.js */ | ||
@@ -262,20 +270,15 @@ import { Toc } from 'documentary' | ||
import { createReadStream } from 'fs' | ||
import { resolve } from 'path' | ||
import { debuglog } from 'util' | ||
const LOG = debuglog('doc') | ||
(async () => { | ||
try { | ||
const md = createReadStream('example/markdown.md') | ||
const rs = new Toc() | ||
md.pipe(rs) | ||
const path = resolve(__dirname, 'markdown.md') | ||
;(async () => { | ||
LOG('Reading %s', path) | ||
const md = createReadStream(path) | ||
const rs = new Toc() | ||
md.pipe(rs) | ||
const { promise } = new Catchment({ | ||
rs, | ||
}) | ||
const res = await promise | ||
console.log(res) | ||
const { promise } = new Catchment({ rs }) | ||
const res = await promise | ||
console.log(res) | ||
} catch ({ stack }) { | ||
console.log(stack) | ||
} | ||
})() | ||
@@ -282,0 +285,0 @@ ``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52691
466
302