Skip to content

Commit

Permalink
Merge 84a2434 into 46671dd
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jul 25, 2019
2 parents 46671dd + 84a2434 commit 9c85055
Show file tree
Hide file tree
Showing 61 changed files with 190 additions and 385 deletions.
3 changes: 1 addition & 2 deletions lib/common/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//
// Generate with ./support/entities.js script
//
'use strict';

/*eslint quotes:0*/
module.exports = {
export default {
"Aacute":"\u00C1",
"aacute":"\u00E1",
"Abreve":"\u0102",
Expand Down
4 changes: 1 addition & 3 deletions lib/common/html_blocks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// List of valid html blocks names, accorting to commonmark spec
// http://jgm.github.io/CommonMark/spec.html#html-blocks

'use strict';

var html_blocks = {};

[
Expand Down Expand Up @@ -59,4 +57,4 @@ var html_blocks = {};
].forEach(function (name) { html_blocks[name] = true; });


module.exports = html_blocks;
export default html_blocks;
8 changes: 1 addition & 7 deletions lib/common/html_re.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Regexps to match html elements

'use strict';


function replace(regex, options) {
regex = regex.source;
options = options || '';
Expand Down Expand Up @@ -46,14 +43,11 @@ var processing = /<[?].*?[?]>/;
var declaration = /<![A-Z]+\s+[^>]*>/;
var cdata = /<!\[CDATA\[([^\]]+|\][^\]]|\]\][^>])*\]\]>/;

var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)
export var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)
('open_tag', open_tag)
('close_tag', close_tag)
('comment', comment)
('processing', processing)
('declaration', declaration)
('cdata', cdata)
();


module.exports.HTML_TAG_RE = HTML_TAG_RE;
5 changes: 1 addition & 4 deletions lib/common/url_schemas.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// List of valid url schemas, accorting to commonmark spec
// http://jgm.github.io/CommonMark/spec.html#autolinks

'use strict';


module.exports = [
export default [
'coap',
'doi',
'javascript',
Expand Down
30 changes: 9 additions & 21 deletions lib/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
import entities from './entities';

/**
* Utility functions
Expand All @@ -8,21 +8,21 @@ function typeOf(obj) {
return Object.prototype.toString.call(obj);
}

function isString(obj) {
export function isString(obj) {
return typeOf(obj) === '[object String]';
}

var hasOwn = Object.prototype.hasOwnProperty;

function has(object, key) {
export function has(object, key) {
return object
? hasOwn.call(object, key)
: false;
}

// Extend objects
//
function assign(obj /*from1, from2, from3, ...*/) {
export function assign(obj /*from1, from2, from3, ...*/) {
var sources = [].slice.call(arguments, 1);

sources.forEach(function (source) {
Expand All @@ -44,14 +44,14 @@ function assign(obj /*from1, from2, from3, ...*/) {

var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;

function unescapeMd(str) {
export function unescapeMd(str) {
if (str.indexOf('\\') < 0) { return str; }
return str.replace(UNESCAPE_MD_RE, '$1');
}

////////////////////////////////////////////////////////////////////////////////

function isValidEntityCode(c) {
export function isValidEntityCode(c) {
/*eslint no-bitwise:0*/
// broken sequence
if (c >= 0xD800 && c <= 0xDFFF) { return false; }
Expand All @@ -68,7 +68,7 @@ function isValidEntityCode(c) {
return true;
}

function fromCodePoint(c) {
export function fromCodePoint(c) {
/*eslint no-bitwise:0*/
if (c > 0xffff) {
c -= 0x10000;
Expand All @@ -82,7 +82,6 @@ function fromCodePoint(c) {

var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi;
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;
var entities = require('./entities');

function replaceEntityPattern(match, name) {
var code = 0;
Expand All @@ -101,7 +100,7 @@ function replaceEntityPattern(match, name) {
return match;
}

function replaceEntities(str) {
export function replaceEntities(str) {
if (str.indexOf('&') < 0) { return str; }

return str.replace(NAMED_ENTITY_RE, replaceEntityPattern);
Expand All @@ -122,20 +121,9 @@ function replaceUnsafeChar(ch) {
return HTML_REPLACEMENTS[ch];
}

function escapeHtml(str) {
export function escapeHtml(str) {
if (HTML_ESCAPE_TEST_RE.test(str)) {
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
}
return str;
}

////////////////////////////////////////////////////////////////////////////////

exports.assign = assign;
exports.isString = isString;
exports.has = has;
exports.unescapeMd = unescapeMd;
exports.isValidEntityCode = isValidEntityCode;
exports.fromCodePoint = fromCodePoint;
exports.replaceEntities = replaceEntities;
exports.escapeHtml = escapeHtml;
5 changes: 1 addition & 4 deletions lib/configs/commonmark.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Commonmark default options

'use strict';


module.exports = {
export default {
options: {
html: true, // Enable HTML tags in source
xhtmlOut: true, // Use '/' to close single tags (<br />)
Expand Down
5 changes: 1 addition & 4 deletions lib/configs/default.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Remarkable default options

'use strict';


module.exports = {
export default {
options: {
html: false, // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br />)
Expand Down
5 changes: 1 addition & 4 deletions lib/configs/full.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Remarkable default options

'use strict';


module.exports = {
export default {
options: {
html: false, // Enable HTML tags in source
xhtmlOut: false, // Use '/' to close single tags (<br />)
Expand Down
6 changes: 2 additions & 4 deletions lib/helpers/normalize_link.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';
import { replaceEntities } from '../common/utils';

var replaceEntities = require('../common/utils').replaceEntities;

module.exports = function normalizeLink(url) {
export default function normalizeLink(url) {
var normalized = replaceEntities(url);
// We shouldn't care about the result of malformed URIs,
// and should not throw an exception.
Expand Down
4 changes: 1 addition & 3 deletions lib/helpers/normalize_reference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function normalizeReference(str) {
export default function normalizeReference(str) {
// use .toUpperCase() instead of .toLowerCase()
// here to avoid a conflict with Object.prototype
// members (most notably, `__proto__`)
Expand Down
9 changes: 3 additions & 6 deletions lib/helpers/parse_link_destination.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';


var normalizeLink = require('./normalize_link');
var unescapeMd = require('../common/utils').unescapeMd;
import normalizeLink from './normalize_link';
import { unescapeMd } from '../common/utils';

/**
* Parse link destination
Expand All @@ -15,7 +12,7 @@ var unescapeMd = require('../common/utils').unescapeMd;
* @api private
*/

module.exports = function parseLinkDestination(state, pos) {
export default function parseLinkDestination(state, pos) {
var code, level, link,
start = pos,
max = state.posMax;
Expand Down
4 changes: 1 addition & 3 deletions lib/helpers/parse_link_label.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

/**
* Parse link labels
*
Expand All @@ -11,7 +9,7 @@
* @api private
*/

module.exports = function parseLinkLabel(state, start) {
export default function parseLinkLabel(state, start) {
var level, found, marker,
labelEnd = -1,
max = state.posMax,
Expand Down
7 changes: 2 additions & 5 deletions lib/helpers/parse_link_title.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
'use strict';


var unescapeMd = require('../common/utils').unescapeMd;
import { unescapeMd } from '../common/utils';

/**
* Parse link title
Expand All @@ -14,7 +11,7 @@ var unescapeMd = require('../common/utils').unescapeMd;
* @api private
*/

module.exports = function parseLinkTitle(state, pos) {
export default function parseLinkTitle(state, pos) {
var code,
start = pos,
max = state.posMax,
Expand Down
39 changes: 15 additions & 24 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
'use strict';

/**
* Local dependencies
*/

var assign = require('./common/utils').assign;
var Renderer = require('./renderer');
var ParserCore = require('./parser_core');
var ParserBlock = require('./parser_block');
var ParserInline = require('./parser_inline');
var Ruler = require('./ruler');
import * as utils from './common/utils';
import Renderer from './renderer';
import ParserCore from './parser_core';
import ParserBlock from './parser_block';
import ParserInline from './parser_inline';
import Ruler from './ruler';
import defaultConfig from './configs/default';
import fullConfig from './configs/full';
import commonmarkConfig from './configs/commonmark';

/**
* Preset configs
*/

var config = {
'default': require('./configs/default'),
'full': require('./configs/full'),
'commonmark': require('./configs/commonmark')
'default': defaultConfig,
'full': fullConfig,
'commonmark': commonmarkConfig
};

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

function Remarkable(preset, options) {
export default function Remarkable(preset, options) {
if (typeof preset !== 'string') {
options = preset;
preset = 'default';
Expand Down Expand Up @@ -88,7 +85,7 @@ function Remarkable(preset, options) {
*/

Remarkable.prototype.set = function (options) {
assign(this.options, options);
utils.assign(this.options, options);
};

/**
Expand Down Expand Up @@ -190,15 +187,9 @@ Remarkable.prototype.renderInline = function (str, env) {
return this.renderer.render(this.parseInline(str, env), this.options, env);
};

/**
* Expose `Remarkable`
*/

module.exports = Remarkable;

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

Remarkable.utils = require('./common/utils');
Remarkable.utils = utils;
6 changes: 2 additions & 4 deletions lib/linkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
//
// Currently restricted by `inline.validateLink()` to http/https/ftp
//
'use strict';


var Autolinker = require('autolinker');
import Autolinker from 'autolinker';


var LINK_SCAN_RE = /www|@|\:\/\//;
Expand Down Expand Up @@ -158,6 +156,6 @@ function parseTokens(state) {
}
};

module.exports = function linkify(md) {
export default function linkify(md) {
md.core.ruler.push('linkify', parseTokens);
};

0 comments on commit 9c85055

Please sign in to comment.