-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, regexes were used to inspect and manipulate the example. This commit rewrites the whole plugin to instead properly depend on ASTs (yay!) This also comes with the benefit of asynchronous file system operations. And lastly, many new tests, support for multiple console results, better temp file management, and much better internals. We no longer support `options.cwd`. Instead, set the `cwd` on the processed file to that instead.
- Loading branch information
Showing
149 changed files
with
1,213 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
example.js | ||
test/fixtures/fail-could-not-parse-package/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
example/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
// This section is rendered by this module from [example.js][example-js]. | ||
// > This section is rendered by this module from [`example.js`][example-js]. | ||
// > Turtles all the way down. 🐢🐢🐢 | ||
|
||
// Dependencies: | ||
var fs = require('fs') | ||
var remark = require('remark') | ||
var usage = require('./index.js') // This is changed from `./index.js` to `remark-usage` | ||
// remark-usage-ignore-next 4 - Get the files to show them in our usage example. | ||
var readFile = require('fs').readFileSync | ||
var join = require('path').join | ||
var exampleJs = readFile(join('example', 'example.js'), 'utf8') | ||
var exampleMd = readFile(join('example', 'readme.md'), 'utf8') | ||
|
||
// Read and parse `readme.md`: | ||
var readme = fs.readFileSync('readme.md', 'utf-8') | ||
var ast = remark() | ||
.use(usage) | ||
.parse(readme) | ||
// remark-usage-ignore-next - Use async/await so it looks nicer. | ||
;(async function (){ | ||
|
||
// Log something with a language flag: | ||
console.log('markdown', remark().stringify(ast.children[2])) | ||
// Say we are making a module that exports just enough Pi (3.14159). | ||
// We’re documenting it with a readme file, [`example/readme.md`][example-md]: | ||
console.log('markdown', exampleMd) | ||
|
||
// Or without language: | ||
console.log(remark().stringify(ast.children[3])) | ||
// …and an example script to document it [`example/example.js`][example-js-2]: | ||
console.log('js', exampleJs) | ||
|
||
// …If we use `remark-usage`, we can generate the `Usage` section | ||
var path = require('path') | ||
var vfile = require('to-vfile') | ||
var remark = require('remark') | ||
var usage = require('.') | ||
|
||
var file = vfile.readSync({path: 'readme.md', cwd: 'example'}) | ||
|
||
var file = await remark() | ||
.use(usage) | ||
.process(file) | ||
|
||
// Log something which is never captured: | ||
function neverCalled() { | ||
console.log('javascript', 'alert("test")') | ||
} | ||
// Now, printing `file` (the newly generated readme) yields: | ||
console.log('markdown', String(file)) | ||
|
||
// Log something which isn’t captured because it’s not a string. | ||
console.log(this) | ||
// remark-usage-ignore-next | ||
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Load dependencies: | ||
var pi = require('.') | ||
|
||
// Logging `pi` yields: | ||
console.log('txt', pi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict' | ||
|
||
module.exports = Math.floor(Math.PI * 1e5) / 1e5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"private": true, | ||
"name": "pi", | ||
"main": "./index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# PI | ||
|
||
More than enough 🍰 | ||
|
||
## Usage | ||
|
||
## License | ||
|
||
MIT |
Oops, something went wrong.