Skip to content

Commit

Permalink
feat: @plain
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Nov 1, 2023
1 parent b4f0f93 commit f8fe184
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,23 @@ flowchart
```
````

### @plain

````markdown
Turn

```markdown @plain
anything
```

Into

anything
````

## Related

- [markdown-code-block-meta](https://github.com/nice-move/markdown-code-block-meta)
- [rehype-extended-table](https://github.com/nice-move/rehype-extended-table)
- [remark-docusaurus](https://github.com/nice-move/remark-docusaurus)
- [remark-kroki](https://github.com/nice-move/remark-kroki)
18 changes: 18 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,23 @@ export function remarkCodeExample({ metas = {} } = {}) {

node.meta = stringify(new Map([...extra, ...newMeta]));
});

visitCode(tree, '@plain', ({ node, lang }) => {
if (lang === 'markdown') {
node.type = 'paragraph';

node.children = [
{
type: 'text',
value: node.value,
},
];

delete node.lang;
delete node.meta;
delete node.value;
delete node.position;
}
});
};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"ava": "^5.3.1",
"eslint": "^8.52.0",
"eslint-plugin-ava": "^14.0.0",
"fs-chain": "^8.2.3",
"garou": "^0.6.17",
"prettier": "^3.0.3",
"remark": "^15.0.1"
Expand Down
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixture/math.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```markdown @plain
$$
I = \int_0^{2\pi} \sin(x) dx
$$
```
23 changes: 23 additions & 0 deletions test/snapshots/to-plain.mjs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Snapshot report for `test/to-plain.mjs`

The actual snapshot is saved in `to-plain.mjs.snap`.

Generated by [AVA](https://avajs.dev).

## @plain

> Snapshot 1
`\`\`\`markdown @plain␊
$$␊
I = \\int_0^{2\\pi} \\sin(x) dx␊
$$␊
\`\`\`␊
`

> Snapshot 2
`$$␊
I = \\int\\_0^{2\\pi} \\sin(x) dx␊
$$␊
`
Binary file added test/snapshots/to-plain.mjs.snap
Binary file not shown.
17 changes: 17 additions & 0 deletions test/to-plain.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import test from 'ava';
import { Text } from 'fs-chain';

import { transform } from './helper/lib.mjs';

function Read(path) {
return new Text(import.meta.url).source(path);
}

test('@plain', async (t) => {
const input = await Read('../fixture/math.md');

const output = await transform(input);

t.snapshot(input);
t.snapshot(output);
});

0 comments on commit f8fe184

Please sign in to comment.