Skip to content

acco/cqmd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cqmd: A markdown preprocessor for cq code blocks npm package Dolpins

cqmd is a markdown preprocessor that parses cq query blocks and replaces them with "regular" markdown code blocks.

Install

$ npm install --global @fullstackio/cqmd

Usage

$ cq --path <path/to/code/basepath> <input-markdown-file>

# or

$ cat file | cqmd --path <path>

Markdown Format

To use cqmd you write a normal markdown file but instead of using indented code blocks you use the following syntax:

{lang=myLang,crop-query=myQuery,format=myFormat}
<<[](path/to/file.js)

For example, say we have a file examples/basics.js with the following code:

// examples/basics.js
const bye = function() {
  return 'bye';
}
bye(); // -> 'bye'

let Farm = () => 'cow';

In our markdown file we could include the code block by using the following markdown:

// document.md

And here is how we say goodbye:

{lang=javascript,crop-query=.bye,format=gfm}
<<[](examples/basics.js)

Isn't that neat?

Notice that none of the values are quoted. You do not quote your crop-query. If you use quotes then you are searching for a string.

Now we can process document.md like so:

$ cqmd --path . document.md

Which emits:

// document.md

And here is how we say goodbye:

```javascript
const bye = function() {
  return 'bye';
}
```

Isn't that neat?

You can see the full list of possible queries in the cq manual.

Library Usage

var cqmd = require('@fullstackio/cqmd').default;
let results = cqmd(input, {path: __dirname});
console.log(results);

If you'd like to create a custom formatting function, use the format key in the options.

Future

Contributing

Please feel free to submit pull requests!

Authors

Originally written by Nate Murray.

Fullstack React Book

Fullstack React Book

This repo was written and is maintained by the Fullstack React team. If you're looking to learn React, there's no faster way than by spending a few hours with the Fullstack React book.

License

MIT

About

a markdown preprocessor for cq

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 96.2%
  • TypeScript 3.8%