1.7.4 • Published 10 months ago

docusaurus-theme-jarle-codeblock v1.7.4

Weekly downloads
23
License
MIT
Repository
github
Last release
10 months ago

docusaurus-theme-jarle-codeblock

A Docusaurus theme for editable live code examples using JARLE.

Usage

Install

npm install docusaurus-theme-jarle-codeblock

Modify your docusaurus.config.js

module.exports = {
  ...
+ themes: ['docusaurus-theme-jarle-codeblock'],
  presets: ['@docusaurus/preset-classic']
  ...
}

Example in your markdown

```jsx live
function Clock(props) {
  const [date, setDate] = useState(new Date());
  useEffect(() => {
    var timerID = setInterval(() => tick(), 1000);

    return function cleanup() {
      clearInterval(timerID);
    };
  });

  function tick() {
    setDate(new Date());
  }

  return (
    <div>
      <h2>It is {date.toLocaleTimeString()}.</h2>
    </div>
  );
}
```

Handling local imports

By default import statements in a JARLE codeblock will use native ESM imports, which lets you use dependencies from online repositories like skypack.

If you want to use local dependencies bundling with your app instead, a "remark" plugin is provided to do some processing on Markdown code blocks to enable this.

Modify your docusaurus.config.js

module.exports = {
  themes: ['docusaurus-theme-jarle-codeblock'],
  presets: [
    [
      '@docusaurus/preset-classic',
      {
        docs: {
+          remarkPlugins: [require('docusaurus-theme-jarle-codeblock/remark')],
        },
        blog: {
+          remarkPlugins: [require('docusaurus-theme-jarle-codeblock/remark')],
        },
      },
    ],
  ],
  ...
};

This allows codeblocks like the following:

```jsx live
  import Button from '@site/src/components/Button';

  <Button>My Button</Button>
```
1.7.4

10 months ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.7.0

2 years ago

1.6.0

2 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago