Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use named exports for public api #354

Merged
merged 3 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ npm install remarkable --save
## Usage

```js
var Remarkable = require('remarkable');
import { Remarkable } from 'remarkable';
var md = new Remarkable();

console.log(md.render('# Remarkable rulezz!'));
// => <h1>Remarkable rulezz!</h1>
```

or with commonjs

```js
const { Remarkable } = require('remarkable');
var md = new Remarkable();

console.log(md.render('# Remarkable rulezz!'));
// => <h1>Remarkable rulezz!</h1>
```


If installed globally with `npm`:

```sh
Expand Down Expand Up @@ -101,7 +112,8 @@ console.log(md.render('# Remarkable rulezz!'));
Or define options via the `.set()` method:

```js
var Remarkable = require('remarkable');
import { Remarkable } 'remarkable';

var md = new Remarkable();

md.set({
Expand All @@ -126,7 +138,7 @@ active syntax rules and options for common use cases.
Enable strict [CommonMark](http://commonmark.org/) mode with the `commonmark` preset:

```js
var Remarkable = require('remarkable');
import { Remarkable } from 'remarkable';
var md = new Remarkable('commonmark');
```

Expand All @@ -135,7 +147,7 @@ var md = new Remarkable('commonmark');
Enable all available rules (but still with default options, if not set):

```js
var Remarkable = require('remarkable');
import { Remarkable } from 'remarkable';
var md = new Remarkable('full');

// Or with options:
Expand All @@ -151,8 +163,8 @@ var md = new Remarkable('full', {
Apply syntax highlighting to fenced code blocks with the `highlight` option:

```js
var Remarkable = require('remarkable');
var hljs = require('highlight.js') // https://highlightjs.org/
import { Remarkable } from 'remarkable';
import hljs from 'highlight.js' // https://highlightjs.org/

// Actual default values
var md = new Remarkable({
Expand Down Expand Up @@ -233,7 +245,7 @@ Although full-weight typographical replacements are language specific, `remarkab
provides coverage for the most common and universal use cases:

```js
var Remarkable = require('remarkable');
import { Remarkable } from 'remarkable';
var md = new Remarkable({
typographer: true,
quotes: '“”‘’'
Expand Down Expand Up @@ -287,6 +299,14 @@ import linkify from 'remarkable/linkify';
var md = new Remarkable().use(linkify);
```

### UMD

UMD bundle provides linkify out of the box

```js
const { Remarkable, linkify, utils } = window.remarkable;
```


## References / Thanks

Expand Down
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import argparse from 'argparse';
import Remarkable from './index';
import linkify from './linkify';
import { Remarkable } from './index';
import { linkify } from './linkify';
import { version } from '../package.json';

////////////////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 10 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import defaultConfig from './configs/default';
import fullConfig from './configs/full';
import commonmarkConfig from './configs/commonmark';

/**
* Expose `utils`, Useful helper functions for custom
* rendering.
*/

export {
utils
}

/**
* Preset configs
*/
Expand Down Expand Up @@ -47,7 +56,7 @@ function StateCore(instance, str, env) {
* @param {Object} `options`
*/

export default function Remarkable(preset, options) {
export function Remarkable(preset, options) {
if (typeof preset !== 'string') {
options = preset;
preset = 'default';
Expand Down Expand Up @@ -186,10 +195,3 @@ Remarkable.prototype.renderInline = function (str, env) {
env = env || {};
return this.renderer.render(this.parseInline(str, env), this.options, env);
};

/**
* Expose `utils`, Useful helper functions for custom
* rendering.
*/

Remarkable.utils = utils;
2 changes: 1 addition & 1 deletion lib/linkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ function parseTokens(state) {
}
};

export default function linkify(md) {
export function linkify(md) {
md.core.ruler.push('linkify', parseTokens);
};
8 changes: 2 additions & 6 deletions lib/umd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
import Remarkable from './index';
import linkify from './linkify';

Remarkable.linkify = linkify;

export default Remarkable;
export { Remarkable, utils } from './index';
export { linkify } from './linkify';
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';

const name = 'Remarkable';
const name = 'remarkable';
const external = id => !id.startsWith('.') && !path.isAbsolute(id);

export default [
Expand Down
2 changes: 1 addition & 1 deletion support/specsplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fs from 'fs';
import util from 'util';
import argparse from 'argparse';
import Remarkable from '../lib/index.js';
import { Remarkable } from '../lib/index.js';
import pkg from '../package.json';

var cli = new argparse.ArgumentParser({
Expand Down
2 changes: 1 addition & 1 deletion test/commonmark.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { addTests } from './utils';
import Remarkable from '../lib/index';
import { Remarkable } from '../lib/index';

describe('CommonMark', function () {
var md = new Remarkable('commonmark');
Expand Down
4 changes: 2 additions & 2 deletions test/linkify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import assert from 'assert';
import { addTests } from './utils';
import Remarkable from '../lib/index';
import linkify from '../lib/linkify';
import { Remarkable } from '../lib/index';
import { linkify } from '../lib/linkify';

describe('linkify plugin', function () {
var md = new Remarkable({ html: true }).use(linkify);
Expand Down
6 changes: 2 additions & 4 deletions test/misc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import assert from 'assert';
import Remarkable from '../lib/index';
import linkify from '../lib/linkify';

const { utils } = Remarkable
import { Remarkable, utils } from '../lib/index';
import { linkify } from '../lib/linkify';


describe('Utils', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/remarkable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { addTests } from './utils';
import Remarkable from '../lib/index';
import { Remarkable } from '../lib/index';

describe('remarkable', function () {
var md = new Remarkable('full', {
Expand Down