2.4.3 • Published 9 years ago

canvas-native v2.4.3

Weekly downloads
92
License
-
Repository
github
Last release
9 years ago

Canvas Native Circle CI

Canvas Native is a set of utilities for parsing and converting between the native Canvas format and other formats.

Usage

Install canvas-native from npm:

npm i --save canvas-native

Parsing

A canvas can be parsed from its native text form into an array of objects that can then be converted into other formats:

import { parse } from 'canvas-native/lib/parser';
parse(myCanvasString);

Formatting

A parsed canvas can be converted into other formats. The available formatters can be found in lib/formatters:

import format      from 'canvas-native/lib/formatters/markdown';
import { parse   } from 'canvas-native/lib/parser';

const parsed   = parse(myCanvasString);
const markdown = format(parsed);

Creating Types

To create a new type, create a subclass of lib/types/type and add the missing getters and methods (see that file for latest format):

// lib/types/my-type.js

import Type     from './type';
import { wrap } from '../brackets';

export default class MyType extends Type {
  toMarkdown(/* prevLine, nextLine */) {
    return 'My type as Markdown';
  }

  static get name() {
    return 'my-type';
  }

  static get pattern() {
    return new RegExp(`^${wrap('my-type')}(.*)$`);
  }
}

Prefixed Lines

In the above example, we make use of the wrap function exported from lib/brackets. That function wraps a given string in the special brackets used for parsing some lines in the Canvas native format.

2.4.3

9 years ago

2.4.2

9 years ago

2.4.1

9 years ago

2.4.0

9 years ago

2.3.4

9 years ago

2.3.3

10 years ago

2.3.2

10 years ago

2.3.1

10 years ago

2.3.0

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.3

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.4.0

10 years ago

1.3.0

10 years ago

1.2.3

10 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago