Coder Social home page Coder Social logo

mdx-annotations's Introduction

mdx-annotations

Markdoc-style annotations for MDX

Installation

npm install mdx-annotations

To maximise compatibility mdx-annotations is provided as three separate plugins that must be used together:

import { compile } from '@mdx-js/mdx'
import { mdxAnnotations } from 'mdx-annotations'

let mdx = `# Hello, world! {{ id: 'intro' }}`

await compile(mdx, {
  remarkPlugins: [mdxAnnotations.remark],
  rehypePlugins: [mdxAnnotations.rehype],
  recmaPlugins: [mdxAnnotations.recma],
})

Note
It is recommended to include each plugin first in their respective plugin arrays.

Usage

An annotation is a JavaScript object associated with an MDX node. The object properties are passed to the resulting JSX element as props.

Input:

# Hello, world! {{ id: 'intro' }}

Output:

<h1 id="intro">Hello, world!</h1>

Examples

Headings
# Hello, world! {{ id: 'intro' }}

## Hello, world! {{ id: 'intro' }}

### Hello, world! {{ id: 'intro' }}

#### Hello, world! {{ id: 'intro' }}
List items
- Hello, world! {{ id: 'intro' }}

When a list item contains multiple children the annotation is attached to the child:

Input:

- Hello, world! {{ className: 'text-lg' }}

  Lorem ipsum {{ className: 'text-sm' }}

Output:

<ul>
  <li>
    <p className="text-lg">Hello, world!</p>
    <p className="text-sm">Lorem ipsum</p>
  </li>
</ul>
Code
```{{ title: 'Example' }}
Hello, world!
```

```php {{ title: 'Example' }}
echo 'Hello, world!';
```
Thematic breaks
--- {{ className: 'my-10' }}

*** {{ className: 'my-10' }}
Inline elements

To annotate an inline element ensure that there is no whitespace between the element and the annotation:

**Hello world**{{ className: 'text-red-500' }}
_Hello world_{{ className: 'text-red-500' }}
`Hello world`{{ className: 'text-red-500' }}
[Hello world](#){{ className: 'text-red-500' }}
![](/img.png){{ className: 'object-cover' }}

mdx-annotations's People

Contributors

bradlc avatar tobbentm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jonoise tobbentm

mdx-annotations's Issues

Rebuilding Protocol lockfile results in annotations

Sorry that this is specific to the Protocol template, however it's the only use case I have for this issue.

Essentially what's happening is that with a fresh download of the Protocol template, the specific deps listed in the lockfile work perfectly. However, if the lockfile is rebuilt (or you switch to a different package manager), there's an issue with mdx-annotations where it can successfully identify annotations and apply the annotation prop, but it's can't replace them with actual properties later on.

I went into a messy deep dive on Twitter. Seeing as it's dependency version based, I'm guessing it's based on an upgrade to an underlying dependency not directly listed. The diff o the thread might help. In terms of actually fixing it, I think the answer might lie in the recma transformer. Happy to do more digging if it helps. I'd be curious to see what the answer is!

โœŒ๏ธ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.