Skip to content

Commit

Permalink
feat: add footnotes plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Jun 27, 2020
1 parent a485eb3 commit d1e3b67
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ new Viewer({

| Package | Status | Description |
| --- | --- | --- |
| [@bytemd/plugin-footnotes](./packages/plugin-footnotes) | [![npm](https://img.shields.io/npm/v/@bytemd/plugin-footnotes.svg)](https://npm.im/@bytemd/plugin-footnotes) | support footnotes |
| [@bytemd/plugin-highlight](./packages/plugin-highlight) | [![npm](https://img.shields.io/npm/v/@bytemd/plugin-highlight.svg)](https://npm.im/@bytemd/plugin-highlight) | highlight code blocks |
| [@bytemd/plugin-math](./packages/plugin-math) | [![npm](https://img.shields.io/npm/v/@bytemd/plugin-math.svg)](https://npm.im/@bytemd/plugin-math) | support math equation |
| [@bytemd/plugin-mermaid](./packages/plugin-mermaid) | [![npm](https://img.shields.io/npm/v/@bytemd/plugin-mermaid.svg)](https://npm.im/@bytemd/plugin-mermaid) | support [mermaid](https://mermaid-js.github.io/mermaid/) diagram and flowchart |
Expand Down
5 changes: 4 additions & 1 deletion examples/svelte/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import highlight from '@bytemd/plugin-highlight';
import math from '@bytemd/plugin-math';
import mermaid from '@bytemd/plugin-mermaid';
import footnotes from '@bytemd/plugin-footnotes';
import 'github-markdown-css';
import 'highlight.js/styles/vs.css';
import 'katex/dist/katex.css';
Expand All @@ -26,12 +27,14 @@
highlight: true,
math: true,
mermaid: true,
footnotes: true,
};
$: plugins = [
enabled.mermaid && mermaid(),
enabled.highlight && highlight(),
enabled.math && math(),
enabled.footnotes && footnotes(),
].filter((x) => x);
</script>

Expand All @@ -46,7 +49,7 @@

<div>
Plugins:
{#each ['math', 'highlight', 'mermaid'] as p}
{#each Object.keys(enabled) as p}
{' '}
<label>
<input type="checkbox" bind:checked={enabled[p]} />
Expand Down
1 change: 1 addition & 0 deletions packages/bytemd/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export function processMarkdown({

parser = parser.use(stringify);

// console.log(parser.parse(value));
return parser.processSync(value).toString();
}
2 changes: 2 additions & 0 deletions packages/plugin-footnotes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/*.js
src/*.d.ts
37 changes: 37 additions & 0 deletions packages/plugin-footnotes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# @bytemd/plugin-footnotes

[![npm](https://img.shields.io/npm/v/@bytemd/plugin-footnotes.svg)](https://npm.im/@bytemd/plugin-footnotes)

[bytemd](https://github.com/bytedance/bytemd) plugin to support footnotes

## Usage

```js
import { Editor } from 'bytemd';
import footnotes from '@bytemd/plugin-footnotes';

new Editor({
target: document.body,
props: {
plugins: [
footnotes(),
// ... other plugins
],
},
});
```

## Example

```md
Here is a footnote reference,[^1]

another,[^longnote],

[^1]: Here is the footnote.
[^longnote]: Here’s one with multiple blocks.
```

## License

MIT
1 change: 1 addition & 0 deletions packages/plugin-footnotes/docs/desc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
support footnotes
8 changes: 8 additions & 0 deletions packages/plugin-footnotes/docs/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```md
Here is a footnote reference,[^1]

another,[^longnote],

[^1]: Here is the footnote.
[^longnote]: Here’s one with multiple blocks.
```
21 changes: 21 additions & 0 deletions packages/plugin-footnotes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@bytemd/plugin-footnotes",
"version": "0.0.2",
"description": "@bytemd/plugin-footnotes",
"author": "Rongjian Zhang <pd4d10@gmail.com>",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"unpkg": "dist/index.min.js",
"types": "src/index.d.ts",
"files": [
"dist",
"src/*.d.ts"
],
"dependencies": {
"remark-footnotes": "^1.0.0"
},
"peerDependencies": {
"bytemd": "*"
}
}
14 changes: 14 additions & 0 deletions packages/plugin-footnotes/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BytemdPlugin } from 'bytemd';
import remarkFootnotes from 'remark-footnotes';

export default function footnotes(): BytemdPlugin {
return {
remarkTransformer: (u) => u.use(remarkFootnotes),
markdownSanitizeSchema: {
attributes: {
div: ['className'],
a: ['className'],
},
},
};
}
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const packageConfigs = {
'plugin-highlight': {},
'plugin-math': {},
'plugin-mermaid': {},
'plugin-footnotes': {},
};

if (umd) {
Expand Down

0 comments on commit d1e3b67

Please sign in to comment.