# remark-yaml-annotations

> Markdown extension adding annotation capabilities

Latest version **1.0.2** (published 2016-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-yaml-annotations
pnpm add remark-yaml-annotations
yarn add remark-yaml-annotations
bun add remark-yaml-annotations
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-06-17 |
| First published | 2016-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Sean Fridman |
| Maintainers | sfrdmn |
| Keywords | markdown, yaml, annotate, annotation, notes |

## Links

- npm: https://www.npmjs.com/package/remark-yaml-annotations
- Repository: https://github.com/sfrdmn/remark-yaml-annotations
- Homepage: https://github.com/sfrdmn/remark-yaml-annotations#readme
- Issues: https://github.com/sfrdmn/remark-yaml-annotations/issues
- npm.io page: https://npm.io/package/remark-yaml-annotations

## Dependencies (2)

- [js-yaml](https://npm.io/package/js-yaml.md) ^3.5.5
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.1

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-06-17
- 1.0.1 — 2016-04-19
- 1.0.0 — 2016-04-19

## README

# remark-yaml-annotations
[![Build Status](https://travis-ci.org/sfrdmn/remark-yaml-annotations.svg?branch=master)](https://travis-ci.org/sfrdmn/remark-yaml-annotations) [![Dependencies](https://david-dm.org/sfrdmn/remark-yaml-annotations.svg)](https://david-dm.org/sfrdmn/remark-yaml-annotations) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![npm version](https://badge.fury.io/js/remark-yaml-annotations.svg)](https://badge.fury.io/js/remark-yaml-annotations)

[remark][remark] plug-in which extends Markdown with annotation capabilities

## Dependencies currently out of date

Please ping me if you're interested in using this and I'll make some time to update it

## huh?

Annotation! It's pretty good. Let's say, for example, you have a blog post:

```
Hey girls and guys,

I'm cool
```

Not particularly convincing. If, however, you annotate that claim:

```
Hey girls and guys,

{I'm cool}[cool-vid]

[cool-vid] {
  type: video
  source: youtube
  id: 123456
  title: me dancing
}
```

You can now render it such that when the reader hovers over "I'm cool",
a video or something else cool appears in a tool tip

More clicks, more cash money

## Installation

```bash
npm install remark-yaml-annotations
```

## Usage

__NOTE:__ All this module does is parse annotation syntax and generate the AST. Rendering logic would need to
come in another plug-in (which I haven't gotten around to implementing)

```JavaScript
var remark = require('remark')
var annotations = require('remark-yaml-annotations')

var file = remark().use(annotations).process(`
{BYAAAA!}[bya]

[bya] {
  type: image
  src: lord-have-mercy.bmp
  alt: me killing the game
}
`)
```

## Use case example

Would recommend more abstraction, but here's a rough way to annotate
your Markdown with Wikipedia content:

```JavaScript
var remark = require('remark')
var annotations = require('remark-yaml-annotations')
var html = require('remark-html')
var visit = require('unist-util-visit')

remark()
    .use(annotations)
    .use(renderWikiAnnotations)
    .use(html)
    .process(`
{Jean Baudrillard}[baudrillard] was a very sneaky theorist

[baudrillard] {
  type: wikipedia
  title: Jean Baudrillard
}
`, function (err, file) {
  console.log(file.contents)
})

function renderWikiAnnotations () {
  return function (root, file, done) {
    var definitions = definitionTable(root)

    visit(root, 'annotation', function (node) {
      var data = definitions[node.ids[0]]

      if (data.type === 'wikipedia') {
        fetchWikiData(data.title, function (err, data) {
          node.type = 'html'
          node.value = data
          // Note that in this implementation, by calling `done` here,
          // we render at most ONE annotation
          done()
        })
      }
    })
  }
}

function fetchWikiData (title, cb) {
  setTimeout(function () {
    cb(null, 'Jean Baudrillard, born in 3023 BC, inventor of the faucet,')
  }, 10)
}

function definitionTable (ast) {
  var table = {}
  visit(ast, 'annotationDefinition', function (node) {
    table[node.id] = node.annotation
    node.type = 'html'
    node.value = ''
  })
  return table
}
```

This prints:

`<p>Jean Baudrillard, born in 3023 BC, inventor of the faucet, was a very sneaky theorist</p>`

## Rough Grammar

```
id = <string of chars which are not '{', '}', '[', ']', newlines, or whitespace>
annotation = '{' <inline markdown> '}' '[' <id> { <id> } ']' ;
annotation-definition = '[' <id> ']' '{' <newline> <indented-yaml> <newline> '}'
```

Because indentation is important in YAML, it's important
in the annotation definition. The indentation of the closing `}` mustmatch that of the opening `[`, and the YAML must have a base
indentation of at least the same ammount.

OK

```
  [beep] {
      neat: and clean
  }
```

Not OK

```
[beep] {
    why: lord
    }
```

## AST

### `Annotation` ([`Parent`][parent])

```idl
interface Annotation <: Parent {
  type: "annotation";
  ids: [ "id" ];
}
```

### `Annotation Definition` ([`Parent`][parent])

```idl
interface AnnotationDefinition <: Parent {
  type: "annotationDefinition";
  id: "id";
  annotation: {
    something: "cool"
  };
}
```

## TODO

- Support annotating block elements (only works with inline right now)

<!-- Definitions -->

[remark]: https://github.com/wooorm/remark

[parent]: https://github.com/wooorm/unist#parent

---
_Source: https://npm.io/package/remark-yaml-annotations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
