Skip to content

Commit 4213fdd

Browse files
authored
Merge pull request #117 from DavidWells/cursor/initial-codebase-assessment-4791
Initial codebase assessment
2 parents 37ed26b + f1394c4 commit 4213fdd

File tree

22 files changed

+422
-207
lines changed

22 files changed

+422
-207
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This `README.md` is generated with `markdown-magic` [view the raw file](https://
5959
</details>
6060
<!-- ⛔️ MD-MAGIC-EXAMPLE:END -->
6161

62-
<!-- ⛔️ MD-MAGIC-EXAMPLE:START FILE src=./docs/1_Getting-Started.md -->
62+
<!-- ⛔️ MD-MAGIC-EXAMPLE:START FILE src=./docs/1-getting-started.md -->
6363
## Install
6464

6565
**Via npm**
@@ -127,7 +127,7 @@ In NPM scripts, `npm run docs` would run the markdown magic and parse all the `.
127127
},
128128
```
129129

130-
If you have a `markdown.config.js` file where `markdown-magic` is invoked, it will automatically use that as the configuration unless otherwise specified by `--config` flag.
130+
If you have an `md.config.js` or `markdown.config.js` file where `markdown-magic` is invoked, it will automatically use that as the configuration unless otherwise specified by `--config` flag.
131131

132132
### Running programmatically
133133

@@ -191,7 +191,7 @@ jobs:
191191
- [markdown-autodocs](https://github.com/dineshsonachalam/markdown-autodocs) - Auto-generate docs from code
192192
<!-- ⛔️ MD-MAGIC-EXAMPLE:END *-->
193193
194-
<!-- ⛔️ MD-MAGIC-EXAMPLE:START (FILE:src=./docs/Syntax.md) -->
194+
<!-- ⛔️ MD-MAGIC-EXAMPLE:START (FILE:src=./docs/2-syntax-reference.md) -->
195195
## Syntax Examples
196196
197197
There are various syntax options. Choose your favorite.
@@ -669,7 +669,7 @@ const config = {
669669
return '**⊂◉‿◉つ**'
670670
},
671671
lolz() {
672-
return `This section was generated by the cli config markdown.config.js file`
672+
return `This section was generated by the cli config md.config.js file`
673673
},
674674
/* Match <!-- AUTO-GENERATED-CONTENT:START (pluginExample) --> */
675675
pluginExample: require('./plugin-example')({ addNewLine: true }),

docs/1-getting-started.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ npm install markdown-magic --save-dev
1818
Add comment blocks to your markdown files to define where content should be generated:
1919

2020
```md
21-
<!-- doc-gen remote url=http://url-to-raw-md-file.md -->
21+
<!-- docs remote url=http://url-to-raw-md-file.md -->
2222
This content will be dynamically replaced from the remote url
23-
<!-- end-doc-gen -->
23+
<!-- /docs -->
2424
```
2525

2626
Then run markdown-magic to process your files.
@@ -44,7 +44,7 @@ md-magic
4444

4545
Process specific files with custom config:
4646
```bash
47-
md-magic --path '**/*.md' --config ./config.file.js
47+
md-magic --files '**/*.md' --config ./config.file.js
4848
```
4949

5050
### NPM Scripts Integration
@@ -54,7 +54,7 @@ Add to your `package.json`:
5454
```json
5555
{
5656
"scripts": {
57-
"docs": "md-magic --path '**/*.md'"
57+
"docs": "md-magic --files '**/*.md'"
5858
}
5959
}
6060
```
@@ -63,7 +63,7 @@ Run with: `npm run docs`
6363

6464
### Configuration File
6565

66-
Create a `markdown.config.js` file in your project root for automatic configuration:
66+
Create an `md.config.js` or `markdown.config.js` file in your project root for automatic configuration:
6767

6868
```js
6969
module.exports = {

docs/2-syntax-reference.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ All transform blocks follow this basic structure:
1414
```md
1515
<!-- matchWord transformName [options] -->
1616
Content to be replaced
17-
<!-- end-matchWord -->
17+
<!-- /matchWord -->
1818
```
1919

2020
Where:
21-
- `matchWord` is the opening keyword (default: `doc-gen`)
21+
- `matchWord` is the opening keyword (default: `docs`)
2222
- `transformName` is the name of the transform to apply
2323
- `options` are optional parameters for the transform
2424
- Content between the tags will be replaced by the transform output
@@ -30,74 +30,74 @@ Where:
3030
The simplest form - just specify the transform name and options:
3131

3232
```md
33-
<!-- doc-gen transformName optionOne='hello' optionTwo='there' -->
33+
<!-- docs transformName optionOne='hello' optionTwo='there' -->
3434
content to be replaced
35-
<!-- end-doc-gen -->
35+
<!-- /docs -->
3636
```
3737

3838
### Curly Braces
3939

4040
Wrap the transform name in curly braces:
4141

4242
```md
43-
<!-- doc-gen {transformName} optionOne='hello' optionTwo='there' -->
43+
<!-- docs {transformName} optionOne='hello' optionTwo='there' -->
4444
content to be replaced
45-
<!-- end-doc-gen -->
45+
<!-- /docs -->
4646
```
4747

4848
### Square Brackets
4949

5050
Wrap the transform name in square brackets:
5151

5252
```md
53-
<!-- doc-gen [transformName] optionOne='hello' optionTwo='there' -->
53+
<!-- docs [transformName] optionOne='hello' optionTwo='there' -->
5454
content to be replaced
55-
<!-- end-doc-gen -->
55+
<!-- /docs -->
5656
```
5757

5858
### Parentheses
5959

6060
Wrap the transform name in parentheses:
6161

6262
```md
63-
<!-- doc-gen (transformName) optionOne='hello' optionTwo='there' -->
63+
<!-- docs (transformName) optionOne='hello' optionTwo='there' -->
6464
content to be replaced
65-
<!-- end-doc-gen -->
65+
<!-- /docs -->
6666
```
6767

6868
### Function Style
6969

7070
Use function-like syntax with parentheses for options:
7171

7272
```md
73-
<!-- doc-gen transformName(
73+
<!-- docs transformName(
7474
foo='bar'
7575
baz=['qux', 'quux']
7676
) -->
7777
content to be replaced
78-
<!-- end-doc-gen -->
78+
<!-- /docs -->
7979
```
8080

8181
## Option Formats
8282

8383
### String Options
8484
```md
85-
<!-- doc-gen transform option='string value' -->
85+
<!-- docs transform option='string value' -->
8686
```
8787

8888
### Boolean Options
8989
```md
90-
<!-- doc-gen transform enabled=true disabled=false -->
90+
<!-- docs transform enabled=true disabled=false -->
9191
```
9292

9393
### Array Options
9494
```md
95-
<!-- doc-gen transform items=['one', 'two', 'three'] -->
95+
<!-- docs transform items=['one', 'two', 'three'] -->
9696
```
9797

9898
### Multiple Options
9999
```md
100-
<!-- doc-gen transform
100+
<!-- docs transform
101101
url='https://example.com'
102102
format='json'
103103
cache=true
@@ -122,7 +122,7 @@ Then use it in your markdown:
122122
```md
123123
<!-- auto-gen transformName -->
124124
content to be replaced
125-
<!-- end-auto-gen -->
125+
<!-- /auto-gen -->
126126
```
127127

128128
## Best Practices

docs/3-plugin-development.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,40 @@ Learn how to create custom transforms (plugins) for markdown-magic to extend its
99

1010
## Transform Basics
1111

12-
A transform is a function that takes content and options, then returns processed content:
12+
A transform is a function that takes a single API object and returns processed content:
1313

1414
```js
1515
// Basic transform structure
16-
function myTransform(content, options, config) {
16+
function myTransform(api) {
17+
const { content, options, settings } = api
1718
// Process the content
1819
return processedContent
1920
}
2021
```
2122

22-
### Parameters
23+
### API Parameters
2324

2425
- `content`: The content between the comment blocks
2526
- `options`: Parsed options from the comment block
26-
- `config`: Global markdown-magic configuration
27+
- `srcPath`: Current source markdown file path
28+
- `settings`: Global markdown-magic configuration
2729

2830
## Creating Your First Transform
2931

3032
### Simple String Transform
3133

3234
```js
3335
// transforms/greeting.js
34-
module.exports = function greeting(content, options) {
36+
module.exports = function greeting({ options }) {
3537
const name = options.name || 'World'
3638
return `Hello, ${name}!`
3739
}
3840
```
3941

4042
Usage:
4143
```md
42-
<!-- doc-gen greeting name='Alice' -->
43-
<!-- end-doc-gen -->
44+
<!-- docs greeting name='Alice' -->
45+
<!-- /docs -->
4446
```
4547

4648
Result: `Hello, Alice!`
@@ -52,7 +54,7 @@ Result: `Hello, Alice!`
5254
const fs = require('fs')
5355
const path = require('path')
5456

55-
module.exports = function include(content, options) {
57+
module.exports = function include({ content, options }) {
5658
if (!options.src) {
5759
throw new Error('include transform requires "src" option')
5860
}
@@ -70,8 +72,8 @@ module.exports = function include(content, options) {
7072

7173
Usage:
7274
```md
73-
<!-- doc-gen include src='./snippets/example.md' -->
74-
<!-- end-doc-gen -->
75+
<!-- docs include src='./snippets/example.md' -->
76+
<!-- /docs -->
7577
```
7678

7779
## Async Transforms
@@ -82,7 +84,7 @@ For operations that require network requests or file system operations:
8284
// transforms/fetchContent.js
8385
const fetch = require('node-fetch')
8486

85-
module.exports = async function fetchContent(content, options) {
87+
module.exports = async function fetchContent({ content, options }) {
8688
if (!options.url) {
8789
throw new Error('fetchContent requires "url" option')
8890
}
@@ -108,7 +110,7 @@ module.exports = async function fetchContent(content, options) {
108110
// transforms/template.js
109111
const mustache = require('mustache')
110112

111-
module.exports = function template(content, options) {
113+
module.exports = function template({ content, options }) {
112114
const template = options.template || content
113115
const data = {
114116
...options.data,
@@ -126,7 +128,7 @@ module.exports = function template(content, options) {
126128
// transforms/codeStats.js
127129
const fs = require('fs')
128130

129-
module.exports = function codeStats(content, options) {
131+
module.exports = function codeStats({ options }) {
130132
if (!options.src) {
131133
throw new Error('codeStats requires "src" option')
132134
}
@@ -149,7 +151,7 @@ module.exports = function codeStats(content, options) {
149151

150152
```js
151153
// transforms/tableOfContents.js
152-
module.exports = function tableOfContents(content, options) {
154+
module.exports = function tableOfContents({ content, options }) {
153155
const format = options.format || 'markdown'
154156
const maxDepth = parseInt(options.maxDepth) || 3
155157
const minDepth = parseInt(options.minDepth) || 1
@@ -194,7 +196,7 @@ function extractHeadings(content, minDepth, maxDepth) {
194196
### In Configuration File
195197

196198
```js
197-
// markdown.config.js
199+
// md.config.js
198200
const greeting = require('./transforms/greeting')
199201
const include = require('./transforms/include')
200202

@@ -215,7 +217,7 @@ import markdownMagic from 'markdown-magic'
215217

216218
const config = {
217219
transforms: {
218-
myTransform: (content, options) => {
220+
myTransform: ({ content, options }) => {
219221
return `Processed: ${content}`
220222
}
221223
}
@@ -231,7 +233,7 @@ markdownMagic('./docs/*.md', config)
231233
Markdown-magic automatically parses options from the comment block:
232234

233235
```md
234-
<!-- doc-gen myTransform
236+
<!-- docs myTransform
235237
stringOption='value'
236238
numberOption=42
237239
boolOption=true
@@ -242,7 +244,7 @@ Markdown-magic automatically parses options from the comment block:
242244

243245
Access in transform:
244246
```js
245-
module.exports = function myTransform(content, options) {
247+
module.exports = function myTransform({ options }) {
246248
console.log(options.stringOption) // 'value'
247249
console.log(options.numberOption) // 42
248250
console.log(options.boolOption) // true
@@ -254,7 +256,7 @@ module.exports = function myTransform(content, options) {
254256
### Default Options
255257

256258
```js
257-
module.exports = function myTransform(content, options) {
259+
module.exports = function myTransform({ options }) {
258260
const defaults = {
259261
format: 'markdown',
260262
includeTitle: true,
@@ -272,7 +274,7 @@ module.exports = function myTransform(content, options) {
272274
### Validation
273275

274276
```js
275-
module.exports = function strictTransform(content, options) {
277+
module.exports = function strictTransform({ options }) {
276278
// Required options
277279
const required = ['url', 'format']
278280
for (const opt of required) {
@@ -294,7 +296,7 @@ module.exports = function strictTransform(content, options) {
294296
### Graceful Degradation
295297

296298
```js
297-
module.exports = async function robustTransform(content, options) {
299+
module.exports = async function robustTransform({ content, options }) {
298300
try {
299301
// Attempt primary operation
300302
return await primaryOperation(options)
@@ -353,8 +355,8 @@ describe('transform integration', () => {
353355
beforeEach(() => {
354356
// Reset test file
355357
fs.writeFileSync(testFile, `
356-
<!-- doc-gen greeting name='Test' -->
357-
<!-- end-doc-gen -->
358+
<!-- docs greeting name='Test' -->
359+
<!-- /docs -->
358360
`.trim())
359361
})
360362

0 commit comments

Comments
 (0)