diff --git a/lib/common/entities.js b/lib/common/entities.js index 5061e3aa..706c6d5f 100644 --- a/lib/common/entities.js +++ b/lib/common/entities.js @@ -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", diff --git a/lib/common/html_blocks.js b/lib/common/html_blocks.js index 96848e0d..1accba4f 100644 --- a/lib/common/html_blocks.js +++ b/lib/common/html_blocks.js @@ -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 = {}; [ @@ -59,4 +57,4 @@ var html_blocks = {}; ].forEach(function (name) { html_blocks[name] = true; }); -module.exports = html_blocks; +export default html_blocks; diff --git a/lib/common/html_re.js b/lib/common/html_re.js index f4264dcb..7fa811c8 100644 --- a/lib/common/html_re.js +++ b/lib/common/html_re.js @@ -1,8 +1,5 @@ // Regexps to match html elements -'use strict'; - - function replace(regex, options) { regex = regex.source; options = options || ''; @@ -46,7 +43,7 @@ var processing = /<[?].*?[?]>/; var declaration = /]*>/; var 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) @@ -54,6 +51,3 @@ var HTML_TAG_RE = replace(/^(?:open_tag|close_tag|comment|processing|declaration ('declaration', declaration) ('cdata', cdata) (); - - -module.exports.HTML_TAG_RE = HTML_TAG_RE; diff --git a/lib/common/url_schemas.js b/lib/common/url_schemas.js index bd71c25b..fa198136 100644 --- a/lib/common/url_schemas.js +++ b/lib/common/url_schemas.js @@ -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', diff --git a/lib/common/utils.js b/lib/common/utils.js index 85e463da..c1c8a95a 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -1,4 +1,4 @@ -'use strict'; +import entities from './entities'; /** * Utility functions @@ -8,13 +8,13 @@ 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; @@ -22,7 +22,7 @@ function has(object, key) { // 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) { @@ -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; } @@ -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; @@ -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; @@ -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); @@ -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; diff --git a/lib/configs/commonmark.js b/lib/configs/commonmark.js index 5ec59606..1f934b8a 100644 --- a/lib/configs/commonmark.js +++ b/lib/configs/commonmark.js @@ -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 (
) diff --git a/lib/configs/default.js b/lib/configs/default.js index 57792e30..dfa8c5d7 100644 --- a/lib/configs/default.js +++ b/lib/configs/default.js @@ -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 (
) diff --git a/lib/configs/full.js b/lib/configs/full.js index cfad19a8..a8abdb38 100644 --- a/lib/configs/full.js +++ b/lib/configs/full.js @@ -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 (
) diff --git a/lib/helpers/normalize_link.js b/lib/helpers/normalize_link.js index cdec3956..67dfd49f 100644 --- a/lib/helpers/normalize_link.js +++ b/lib/helpers/normalize_link.js @@ -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. diff --git a/lib/helpers/normalize_reference.js b/lib/helpers/normalize_reference.js index 30e3129a..47cc35f4 100644 --- a/lib/helpers/normalize_reference.js +++ b/lib/helpers/normalize_reference.js @@ -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__`) diff --git a/lib/helpers/parse_link_destination.js b/lib/helpers/parse_link_destination.js index 3cf20559..14ff19a4 100644 --- a/lib/helpers/parse_link_destination.js +++ b/lib/helpers/parse_link_destination.js @@ -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 @@ -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; diff --git a/lib/helpers/parse_link_label.js b/lib/helpers/parse_link_label.js index c0480ef9..6a74d96c 100644 --- a/lib/helpers/parse_link_label.js +++ b/lib/helpers/parse_link_label.js @@ -1,5 +1,3 @@ -'use strict'; - /** * Parse link labels * @@ -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, diff --git a/lib/helpers/parse_link_title.js b/lib/helpers/parse_link_title.js index f6757a06..3d485385 100644 --- a/lib/helpers/parse_link_title.js +++ b/lib/helpers/parse_link_title.js @@ -1,7 +1,4 @@ -'use strict'; - - -var unescapeMd = require('../common/utils').unescapeMd; +import { unescapeMd } from '../common/utils'; /** * Parse link title @@ -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, diff --git a/lib/index.js b/lib/index.js index c8f19b1f..a9ee845b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 }; /** @@ -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'; @@ -88,7 +85,7 @@ function Remarkable(preset, options) { */ Remarkable.prototype.set = function (options) { - assign(this.options, options); + utils.assign(this.options, options); }; /** @@ -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; diff --git a/lib/linkify.js b/lib/linkify.js index 06b70af3..0097f905 100644 --- a/lib/linkify.js +++ b/lib/linkify.js @@ -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|@|\:\/\//; @@ -158,6 +156,6 @@ function parseTokens(state) { } }; -module.exports = function linkify(md) { +export default function linkify(md) { md.core.ruler.push('linkify', parseTokens); }; diff --git a/lib/parser_block.js b/lib/parser_block.js index 808c9e3f..a3281f9e 100644 --- a/lib/parser_block.js +++ b/lib/parser_block.js @@ -1,29 +1,36 @@ -'use strict'; - -/** - * Local dependencies - */ - -var Ruler = require('./ruler'); -var StateBlock = require('./rules_block/state_block'); +import Ruler from './ruler'; +import StateBlock from './rules_block/state_block'; + +import code from './rules_block/code'; +import fences from './rules_block/fences'; +import blockquote from './rules_block/blockquote'; +import hr from './rules_block/hr'; +import list from './rules_block/list'; +import footnote from './rules_block/footnote'; +import heading from './rules_block/heading'; +import lheading from './rules_block/lheading'; +import htmlblock from './rules_block/htmlblock'; +import table from './rules_block/table'; +import deflist from './rules_block/deflist'; +import paragraph from './rules_block/paragraph'; /** * Parser rules */ var _rules = [ - [ 'code', require('./rules_block/code') ], - [ 'fences', require('./rules_block/fences'), [ 'paragraph', 'blockquote', 'list' ] ], - [ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'blockquote', 'list' ] ], - [ 'hr', require('./rules_block/hr'), [ 'paragraph', 'blockquote', 'list' ] ], - [ 'list', require('./rules_block/list'), [ 'paragraph', 'blockquote' ] ], - [ 'footnote', require('./rules_block/footnote'), [ 'paragraph' ] ], - [ 'heading', require('./rules_block/heading'), [ 'paragraph', 'blockquote' ] ], - [ 'lheading', require('./rules_block/lheading') ], - [ 'htmlblock', require('./rules_block/htmlblock'), [ 'paragraph', 'blockquote' ] ], - [ 'table', require('./rules_block/table'), [ 'paragraph' ] ], - [ 'deflist', require('./rules_block/deflist'), [ 'paragraph' ] ], - [ 'paragraph', require('./rules_block/paragraph') ] + [ 'code', code ], + [ 'fences', fences, [ 'paragraph', 'blockquote', 'list' ] ], + [ 'blockquote', blockquote, [ 'paragraph', 'blockquote', 'list' ] ], + [ 'hr', hr, [ 'paragraph', 'blockquote', 'list' ] ], + [ 'list', list, [ 'paragraph', 'blockquote' ] ], + [ 'footnote', footnote, [ 'paragraph' ] ], + [ 'heading', heading, [ 'paragraph', 'blockquote' ] ], + [ 'lheading', lheading ], + [ 'htmlblock', htmlblock, [ 'paragraph', 'blockquote' ] ], + [ 'table', table, [ 'paragraph' ] ], + [ 'deflist', deflist, [ 'paragraph' ] ], + [ 'paragraph', paragraph ] ]; /** @@ -32,7 +39,7 @@ var _rules = [ * @api private */ -function ParserBlock() { +export default function ParserBlock() { this.ruler = new Ruler(); for (var i = 0; i < _rules.length; i++) { this.ruler.push(_rules[i][0], _rules[i][1], { @@ -147,9 +154,3 @@ ParserBlock.prototype.parse = function (str, options, env, outTokens) { state = new StateBlock(str, this, options, env, outTokens); this.tokenize(state, state.line, state.lineMax); }; - -/** - * Expose `ParserBlock` - */ - -module.exports = ParserBlock; diff --git a/lib/parser_core.js b/lib/parser_core.js index 14d7dbd3..bcb965f3 100644 --- a/lib/parser_core.js +++ b/lib/parser_core.js @@ -1,24 +1,27 @@ -'use strict'; +import Ruler from './ruler'; -/** - * Local dependencies - */ - -var Ruler = require('./ruler'); +import block from './rules_core/block'; +import abbr from './rules_core/abbr'; +import references from './rules_core/references'; +import inline from './rules_core/inline'; +import footnote_tail from './rules_core/footnote_tail'; +import abbr2 from './rules_core/abbr2'; +import replacements from './rules_core/replacements'; +import smartquotes from './rules_core/smartquotes'; /** * Core parser `rules` */ var _rules = [ - [ 'block', require('./rules_core/block') ], - [ 'abbr', require('./rules_core/abbr') ], - [ 'references', require('./rules_core/references') ], - [ 'inline', require('./rules_core/inline') ], - [ 'footnote_tail', require('./rules_core/footnote_tail') ], - [ 'abbr2', require('./rules_core/abbr2') ], - [ 'replacements', require('./rules_core/replacements') ], - [ 'smartquotes', require('./rules_core/smartquotes') ], + [ 'block', block ], + [ 'abbr', abbr ], + [ 'references', references ], + [ 'inline', inline ], + [ 'footnote_tail', footnote_tail ], + [ 'abbr2', abbr2 ], + [ 'replacements', replacements ], + [ 'smartquotes', smartquotes ], ]; /** @@ -27,7 +30,7 @@ var _rules = [ * @api private */ -function Core() { +export default function Core() { this.options = {}; this.ruler = new Ruler(); for (var i = 0; i < _rules.length; i++) { @@ -49,9 +52,3 @@ Core.prototype.process = function (state) { rules[i](state); } }; - -/** - * Expose `Core` - */ - -module.exports = Core; diff --git a/lib/parser_inline.js b/lib/parser_inline.js index 0c819c6c..041b331c 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -1,34 +1,45 @@ -'use strict'; - -/** - * Local dependencies - */ - -var Ruler = require('./ruler'); -var StateInline = require('./rules_inline/state_inline'); -var utils = require('./common/utils'); +import Ruler from './ruler'; +import StateInline from './rules_inline/state_inline'; +import * as utils from './common/utils'; + +import text from './rules_inline/text'; +import newline from './rules_inline/newline'; +import escape from './rules_inline/escape'; +import backticks from './rules_inline/backticks'; +import del from './rules_inline/del'; +import ins from './rules_inline/ins'; +import mark from './rules_inline/mark'; +import emphasis from './rules_inline/emphasis'; +import sub from './rules_inline/sub'; +import sup from './rules_inline/sup'; +import links from './rules_inline/links'; +import footnote_inline from './rules_inline/footnote_inline'; +import footnote_ref from './rules_inline/footnote_ref'; +import autolink from './rules_inline/autolink'; +import htmltag from './rules_inline/htmltag'; +import entity from './rules_inline/entity'; /** * Inline Parser `rules` */ var _rules = [ - [ 'text', require('./rules_inline/text') ], - [ 'newline', require('./rules_inline/newline') ], - [ 'escape', require('./rules_inline/escape') ], - [ 'backticks', require('./rules_inline/backticks') ], - [ 'del', require('./rules_inline/del') ], - [ 'ins', require('./rules_inline/ins') ], - [ 'mark', require('./rules_inline/mark') ], - [ 'emphasis', require('./rules_inline/emphasis') ], - [ 'sub', require('./rules_inline/sub') ], - [ 'sup', require('./rules_inline/sup') ], - [ 'links', require('./rules_inline/links') ], - [ 'footnote_inline', require('./rules_inline/footnote_inline') ], - [ 'footnote_ref', require('./rules_inline/footnote_ref') ], - [ 'autolink', require('./rules_inline/autolink') ], - [ 'htmltag', require('./rules_inline/htmltag') ], - [ 'entity', require('./rules_inline/entity') ] + [ 'text', text ], + [ 'newline', newline ], + [ 'escape', escape ], + [ 'backticks', backticks ], + [ 'del', del ], + [ 'ins', ins ], + [ 'mark', mark ], + [ 'emphasis', emphasis ], + [ 'sub', sub ], + [ 'sup', sup ], + [ 'links', links ], + [ 'footnote_inline', footnote_inline ], + [ 'footnote_ref', footnote_ref ], + [ 'autolink', autolink ], + [ 'htmltag', htmltag ], + [ 'entity', entity ] ]; /** @@ -39,7 +50,7 @@ var _rules = [ * @api private */ -function ParserInline() { +export default function ParserInline() { this.ruler = new Ruler(); for (var i = 0; i < _rules.length; i++) { this.ruler.push(_rules[i][0], _rules[i][1]); @@ -153,9 +164,3 @@ function validateLink(url) { } return true; } - -/** - * Expose `ParserInline` - */ - -module.exports = ParserInline; diff --git a/lib/renderer.js b/lib/renderer.js index efe9e671..3071e02d 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -1,24 +1,12 @@ -'use strict'; - -/** - * Local dependencies - */ - -var utils = require('./common/utils'); -var rules = require('./rules'); - -/** - * Expose `Renderer` - */ - -module.exports = Renderer; +import * as utils from './common/utils'; +import rules from './rules'; /** * Renderer class. Renders HTML and exposes `rules` to allow * local modifications. */ -function Renderer() { +export default function Renderer() { this.rules = utils.assign({}, rules); // exported helper, for custom rules only diff --git a/lib/ruler.js b/lib/ruler.js index 05064508..32ac77ad 100644 --- a/lib/ruler.js +++ b/lib/ruler.js @@ -1,5 +1,3 @@ -'use strict'; - /** * Ruler is a helper class for building responsibility chains from * parse rules. It allows: @@ -11,7 +9,7 @@ * @api private */ -function Ruler() { +export default function Ruler() { // List of added rules. Each element is: // // { name: XXX, @@ -265,9 +263,3 @@ Ruler.prototype.getRules = function (chainName) { } return this.__cache__[chainName] || []; }; - -/** - * Expose `Ruler` - */ - -module.exports = Ruler; diff --git a/lib/rules.js b/lib/rules.js index d879bb80..52a0999c 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -1,13 +1,4 @@ -'use strict'; - -/** - * Local dependencies - */ - -var has = require('./common/utils').has; -var unescapeMd = require('./common/utils').unescapeMd; -var replaceEntities = require('./common/utils').replaceEntities; -var escapeHtml = require('./common/utils').escapeHtml; +import { has, unescapeMd, replaceEntities, escapeHtml } from './common/utils'; /** * Renderer rules cache @@ -422,8 +413,4 @@ var getBreak = rules.getBreak = function getBreak(tokens, idx) { return '\n'; }; -/** - * Expose `rules` - */ - -module.exports = rules; +export default rules; diff --git a/lib/rules_block/blockquote.js b/lib/rules_block/blockquote.js index ca7b026e..e2392196 100644 --- a/lib/rules_block/blockquote.js +++ b/lib/rules_block/blockquote.js @@ -1,9 +1,6 @@ // Block quotes -'use strict'; - - -module.exports = function blockquote(state, startLine, endLine, silent) { +export default function blockquote(state, startLine, endLine, silent) { var nextLine, lastLineEmpty, oldTShift, oldBMarks, oldIndent, oldParentType, lines, terminatorRules, i, l, terminate, diff --git a/lib/rules_block/code.js b/lib/rules_block/code.js index 77d6f90a..7e59f199 100644 --- a/lib/rules_block/code.js +++ b/lib/rules_block/code.js @@ -1,9 +1,6 @@ // Code block (4 spaces padded) -'use strict'; - - -module.exports = function code(state, startLine, endLine/*, silent*/) { +export default function code(state, startLine, endLine/*, silent*/) { var nextLine, last; if (state.tShift[startLine] - state.blkIndent < 4) { return false; } diff --git a/lib/rules_block/deflist.js b/lib/rules_block/deflist.js index 7fde6ccf..227b9d1f 100644 --- a/lib/rules_block/deflist.js +++ b/lib/rules_block/deflist.js @@ -1,8 +1,5 @@ // Definition lists -'use strict'; - - // Search `[:~][\n ]`, returns next pos after marker on success // or -1 on fail. function skipMarker(state, line) { @@ -40,7 +37,7 @@ function markTightParagraphs(state, idx) { } } -module.exports = function deflist(state, startLine, endLine, silent) { +export default function deflist(state, startLine, endLine, silent) { var contentStart, ddLine, dtLine, diff --git a/lib/rules_block/fences.js b/lib/rules_block/fences.js index 186cdbb0..b86b4eb3 100644 --- a/lib/rules_block/fences.js +++ b/lib/rules_block/fences.js @@ -1,9 +1,6 @@ // fences (``` lang, ~~~ lang) -'use strict'; - - -module.exports = function fences(state, startLine, endLine, silent) { +export default function fences(state, startLine, endLine, silent) { var marker, len, params, nextLine, mem, haveEndMarker = false, pos = state.bMarks[startLine] + state.tShift[startLine], diff --git a/lib/rules_block/footnote.js b/lib/rules_block/footnote.js index 7c8c5e4e..81d77c78 100644 --- a/lib/rules_block/footnote.js +++ b/lib/rules_block/footnote.js @@ -1,9 +1,6 @@ // Process footnote reference list -'use strict'; - - -module.exports = function footnote(state, startLine, endLine, silent) { +export default function footnote(state, startLine, endLine, silent) { var oldBMark, oldTShift, oldParentType, pos, label, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; diff --git a/lib/rules_block/heading.js b/lib/rules_block/heading.js index f5ef6a26..a9b5c2df 100644 --- a/lib/rules_block/heading.js +++ b/lib/rules_block/heading.js @@ -1,9 +1,6 @@ // heading (#, ##, ...) -'use strict'; - - -module.exports = function heading(state, startLine, endLine, silent) { +export default function heading(state, startLine, endLine, silent) { var ch, level, tmp, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; diff --git a/lib/rules_block/hr.js b/lib/rules_block/hr.js index 2fbbc07e..8842dc1e 100644 --- a/lib/rules_block/hr.js +++ b/lib/rules_block/hr.js @@ -1,9 +1,6 @@ // Horizontal rule -'use strict'; - - -module.exports = function hr(state, startLine, endLine, silent) { +export default function hr(state, startLine, endLine, silent) { var marker, cnt, ch, pos = state.bMarks[startLine], max = state.eMarks[startLine]; diff --git a/lib/rules_block/htmlblock.js b/lib/rules_block/htmlblock.js index c5851938..57f66af4 100644 --- a/lib/rules_block/htmlblock.js +++ b/lib/rules_block/htmlblock.js @@ -1,9 +1,6 @@ // HTML block -'use strict'; - - -var block_names = require('../common/html_blocks'); +import block_names from '../common/html_blocks'; var HTML_TAG_OPEN_RE = /^<([a-zA-Z]{1,15})[\s\/>]/; @@ -15,7 +12,7 @@ function isLetter(ch) { return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */); } -module.exports = function htmlblock(state, startLine, endLine, silent) { +export default function htmlblock(state, startLine, endLine, silent) { var ch, match, nextLine, pos = state.bMarks[startLine], max = state.eMarks[startLine], diff --git a/lib/rules_block/lheading.js b/lib/rules_block/lheading.js index 43da43bf..9c211ca3 100644 --- a/lib/rules_block/lheading.js +++ b/lib/rules_block/lheading.js @@ -1,9 +1,6 @@ // lheading (---, ===) -'use strict'; - - -module.exports = function lheading(state, startLine, endLine/*, silent*/) { +export default function lheading(state, startLine, endLine/*, silent*/) { var marker, pos, max, next = startLine + 1; diff --git a/lib/rules_block/list.js b/lib/rules_block/list.js index 65b653bf..3710db69 100644 --- a/lib/rules_block/list.js +++ b/lib/rules_block/list.js @@ -1,8 +1,5 @@ // Lists -'use strict'; - - // Search `[-+*][\n ]`, returns next pos arter marker on success // or -1 on fail. function skipBulletListMarker(state, startLine) { @@ -82,7 +79,7 @@ function markTightParagraphs(state, idx) { } -module.exports = function list(state, startLine, endLine, silent) { +export default function list(state, startLine, endLine, silent) { var nextLine, indent, oldTShift, diff --git a/lib/rules_block/paragraph.js b/lib/rules_block/paragraph.js index d25e5da7..98fa4b28 100644 --- a/lib/rules_block/paragraph.js +++ b/lib/rules_block/paragraph.js @@ -1,9 +1,6 @@ // Paragraph -'use strict'; - - -module.exports = function paragraph(state, startLine/*, endLine*/) { +export default function paragraph(state, startLine/*, endLine*/) { var endLine, content, terminate, i, l, nextLine = startLine + 1, terminatorRules; diff --git a/lib/rules_block/state_block.js b/lib/rules_block/state_block.js index ad1006d4..4d7f377f 100644 --- a/lib/rules_block/state_block.js +++ b/lib/rules_block/state_block.js @@ -1,9 +1,6 @@ // Parser state class -'use strict'; - - -function StateBlock(src, parser, options, env, tokens) { +export default function StateBlock(src, parser, options, env, tokens) { var ch, s, start, pos, len, indent, indent_found; this.src = src; @@ -153,6 +150,3 @@ StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF return queue.join(''); }; - - -module.exports = StateBlock; diff --git a/lib/rules_block/table.js b/lib/rules_block/table.js index 20689b9f..e1bcfb7e 100644 --- a/lib/rules_block/table.js +++ b/lib/rules_block/table.js @@ -1,8 +1,5 @@ // GFM table, non-standard -'use strict'; - - function getLine(state, line) { var pos = state.bMarks[line] + state.blkIndent, max = state.eMarks[line]; @@ -10,7 +7,7 @@ function getLine(state, line) { return state.src.substr(pos, max - pos); } -module.exports = function table(state, startLine, endLine, silent) { +export default function table(state, startLine, endLine, silent) { var ch, lineText, pos, i, nextLine, rows, cell, aligns, t, tableLines, tbodyLines; diff --git a/lib/rules_core/abbr.js b/lib/rules_core/abbr.js index abc669dd..5b3719ea 100644 --- a/lib/rules_core/abbr.js +++ b/lib/rules_core/abbr.js @@ -1,11 +1,8 @@ // Parse abbreviation definitions, i.e. `*[abbr]: description` // -'use strict'; - - -var StateInline = require('../rules_inline/state_inline'); -var parseLinkLabel = require('../helpers/parse_link_label'); +import StateInline from '../rules_inline/state_inline'; +import parseLinkLabel from '../helpers/parse_link_label'; function parseAbbr(str, parserInline, options, env) { @@ -40,7 +37,7 @@ function parseAbbr(str, parserInline, options, env) { return pos; } -module.exports = function abbr(state) { +export default function abbr(state) { var tokens = state.tokens, i, l, content, pos; if (state.inlineMode) { diff --git a/lib/rules_core/abbr2.js b/lib/rules_core/abbr2.js index cdc03ce9..6eba1c29 100644 --- a/lib/rules_core/abbr2.js +++ b/lib/rules_core/abbr2.js @@ -1,7 +1,5 @@ // Enclose abbreviations in tags // -'use strict'; - var PUNCT_CHARS = ' \n()[]\'".,!?-'; @@ -13,7 +11,7 @@ function regEscape(s) { } -module.exports = function abbr2(state) { +export default function abbr2(state) { var i, j, l, tokens, token, text, nodes, pos, level, reg, m, regText, blockTokens = state.tokens; diff --git a/lib/rules_core/block.js b/lib/rules_core/block.js index f3bbb6dd..2754a323 100644 --- a/lib/rules_core/block.js +++ b/lib/rules_core/block.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = function block(state) { +export default function block(state) { if (state.inlineMode) { state.tokens.push({ diff --git a/lib/rules_core/footnote_tail.js b/lib/rules_core/footnote_tail.js index faee3ec5..58895bbc 100644 --- a/lib/rules_core/footnote_tail.js +++ b/lib/rules_core/footnote_tail.js @@ -1,7 +1,4 @@ -'use strict'; - - -module.exports = function footnote_block(state) { +export default function footnote_block(state) { var i, l, j, t, lastParagraph, list, tokens, current, currentLabel, level = 0, insideRef = false, diff --git a/lib/rules_core/inline.js b/lib/rules_core/inline.js index 8b2280b6..f4e2e441 100644 --- a/lib/rules_core/inline.js +++ b/lib/rules_core/inline.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = function inline(state) { +export default function inline(state) { var tokens = state.tokens, tok, i, l; // Parse inlines diff --git a/lib/rules_core/references.js b/lib/rules_core/references.js index 2a6c7beb..870b8af4 100644 --- a/lib/rules_core/references.js +++ b/lib/rules_core/references.js @@ -1,11 +1,8 @@ -'use strict'; - - -var StateInline = require('../rules_inline/state_inline'); -var parseLinkLabel = require('../helpers/parse_link_label'); -var parseLinkDestination = require('../helpers/parse_link_destination'); -var parseLinkTitle = require('../helpers/parse_link_title'); -var normalizeReference = require('../helpers/normalize_reference'); +import StateInline from '../rules_inline/state_inline'; +import parseLinkLabel from '../helpers/parse_link_label'; +import parseLinkDestination from '../helpers/parse_link_destination'; +import parseLinkTitle from '../helpers/parse_link_title'; +import normalizeReference from '../helpers/normalize_reference'; function parseReference(str, parser, options, env) { @@ -66,7 +63,7 @@ function parseReference(str, parser, options, env) { } -module.exports = function references(state) { +export default function references(state) { var tokens = state.tokens, i, l, content, pos; state.env.references = state.env.references || {}; diff --git a/lib/rules_core/replacements.js b/lib/rules_core/replacements.js index f15439e6..5630689e 100644 --- a/lib/rules_core/replacements.js +++ b/lib/rules_core/replacements.js @@ -1,7 +1,5 @@ // Simple typographical replacements // -'use strict'; - // TODO: // - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾ // - miltiplication 2 x 4 -> 2 × 4 @@ -25,7 +23,7 @@ function replaceScopedAbbr(str) { } -module.exports = function replace(state) { +export default function replace(state) { var i, token, text, inlineTokens, blkIdx; if (!state.options.typographer) { return; } diff --git a/lib/rules_core/smartquotes.js b/lib/rules_core/smartquotes.js index 12a2e931..a596fb68 100644 --- a/lib/rules_core/smartquotes.js +++ b/lib/rules_core/smartquotes.js @@ -1,7 +1,5 @@ // Convert straight quotation marks to typographic ones // -'use strict'; - var QUOTE_TEST_RE = /['"]/; var QUOTE_RE = /['"]/g; @@ -21,7 +19,7 @@ function replaceAt(str, index, ch) { } -module.exports = function smartquotes(state) { +export default function smartquotes(state) { /*eslint max-depth:0*/ var i, token, text, t, pos, max, thisLevel, lastSpace, nextSpace, item, canOpen, canClose, j, isSingle, blkIdx, tokens, diff --git a/lib/rules_inline/autolink.js b/lib/rules_inline/autolink.js index e63b9aab..1b8722fe 100644 --- a/lib/rules_inline/autolink.js +++ b/lib/rules_inline/autolink.js @@ -1,9 +1,7 @@ // Process autolinks '' -'use strict'; - -var url_schemas = require('../common/url_schemas'); -var normalizeLink = require('../helpers/normalize_link'); +import url_schemas from '../common/url_schemas'; +import normalizeLink from '../helpers/normalize_link'; /*eslint max-len:0*/ @@ -11,7 +9,7 @@ var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9 var AUTOLINK_RE = /^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/; -module.exports = function autolink(state, silent) { +export default function autolink(state, silent) { var tail, linkMatch, emailMatch, url, fullUrl, pos = state.pos; if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false; } diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.js index fff04f52..0d6c1b2f 100644 --- a/lib/rules_inline/backticks.js +++ b/lib/rules_inline/backticks.js @@ -1,8 +1,6 @@ // Parse backticks -'use strict'; - -module.exports = function backticks(state, silent) { +export default function backticks(state, silent) { var start, max, marker, matchStart, matchEnd, pos = state.pos, ch = state.src.charCodeAt(pos); diff --git a/lib/rules_inline/del.js b/lib/rules_inline/del.js index 0af767c7..89981dda 100644 --- a/lib/rules_inline/del.js +++ b/lib/rules_inline/del.js @@ -1,8 +1,6 @@ // Process ~~deleted text~~ -'use strict'; - -module.exports = function del(state, silent) { +export default function del(state, silent) { var found, pos, stack, diff --git a/lib/rules_inline/emphasis.js b/lib/rules_inline/emphasis.js index 1bfb6fb6..c6e04834 100644 --- a/lib/rules_inline/emphasis.js +++ b/lib/rules_inline/emphasis.js @@ -1,8 +1,5 @@ // Process *this* and _that_ -'use strict'; - - function isAlphaNum(code) { return (code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || (code >= 0x41 /* A */ && code <= 0x5A /* Z */) || @@ -48,7 +45,7 @@ function scanDelims(state, start) { }; } -module.exports = function emphasis(state, silent) { +export default function emphasis(state, silent) { var startCount, count, found, diff --git a/lib/rules_inline/entity.js b/lib/rules_inline/entity.js index 52e7cbaf..b89594ea 100644 --- a/lib/rules_inline/entity.js +++ b/lib/rules_inline/entity.js @@ -1,18 +1,14 @@ // Process html entity - {, ¯, ", ... -'use strict'; - -var entities = require('../common/entities'); -var has = require('../common/utils').has; -var isValidEntityCode = require('../common/utils').isValidEntityCode; -var fromCodePoint = require('../common/utils').fromCodePoint; +import entities from '../common/entities'; +import { has, isValidEntityCode, fromCodePoint } from '../common/utils'; var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i; var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i; -module.exports = function entity(state, silent) { +export default function entity(state, silent) { var ch, code, match, pos = state.pos, max = state.posMax; if (state.src.charCodeAt(pos) !== 0x26/* & */) { return false; } diff --git a/lib/rules_inline/escape.js b/lib/rules_inline/escape.js index 09dee0b8..3018042f 100644 --- a/lib/rules_inline/escape.js +++ b/lib/rules_inline/escape.js @@ -1,7 +1,5 @@ // Proceess escaped chars and hardbreaks -'use strict'; - var ESCAPED = []; for (var i = 0; i < 256; i++) { ESCAPED.push(0); } @@ -10,7 +8,7 @@ for (var i = 0; i < 256; i++) { ESCAPED.push(0); } .split('').forEach(function(ch) { ESCAPED[ch.charCodeAt(0)] = 1; }); -module.exports = function escape(state, silent) { +export default function escape(state, silent) { var ch, pos = state.pos, max = state.posMax; if (state.src.charCodeAt(pos) !== 0x5C/* \ */) { return false; } diff --git a/lib/rules_inline/footnote_inline.js b/lib/rules_inline/footnote_inline.js index ee0fb231..03640140 100644 --- a/lib/rules_inline/footnote_inline.js +++ b/lib/rules_inline/footnote_inline.js @@ -1,11 +1,9 @@ // Process inline footnotes (^[...]) -'use strict'; +import parseLinkLabel from '../helpers/parse_link_label'; -var parseLinkLabel = require('../helpers/parse_link_label'); - -module.exports = function footnote_inline(state, silent) { +export default function footnote_inline(state, silent) { var labelStart, labelEnd, footnoteId, diff --git a/lib/rules_inline/footnote_ref.js b/lib/rules_inline/footnote_ref.js index f0ab553e..3f7e2b9c 100644 --- a/lib/rules_inline/footnote_ref.js +++ b/lib/rules_inline/footnote_ref.js @@ -1,9 +1,6 @@ // Process footnote references ([^...]) -'use strict'; - - -module.exports = function footnote_ref(state, silent) { +export default function footnote_ref(state, silent) { var label, pos, footnoteId, diff --git a/lib/rules_inline/htmltag.js b/lib/rules_inline/htmltag.js index db3dd76b..a4b15f62 100644 --- a/lib/rules_inline/htmltag.js +++ b/lib/rules_inline/htmltag.js @@ -1,9 +1,6 @@ // Process html tags -'use strict'; - - -var HTML_TAG_RE = require('../common/html_re').HTML_TAG_RE; +import { HTML_TAG_RE } from '../common/html_re'; function isLetter(ch) { @@ -13,7 +10,7 @@ function isLetter(ch) { } -module.exports = function htmltag(state, silent) { +export default function htmltag(state, silent) { var ch, match, max, pos = state.pos; if (!state.options.html) { return false; } diff --git a/lib/rules_inline/ins.js b/lib/rules_inline/ins.js index 2a55981a..ed013be9 100644 --- a/lib/rules_inline/ins.js +++ b/lib/rules_inline/ins.js @@ -1,8 +1,6 @@ // Process ++inserted text++ -'use strict'; - -module.exports = function ins(state, silent) { +export default function ins(state, silent) { var found, pos, stack, diff --git a/lib/rules_inline/links.js b/lib/rules_inline/links.js index b356f404..f1e73040 100644 --- a/lib/rules_inline/links.js +++ b/lib/rules_inline/links.js @@ -1,14 +1,12 @@ // Process [links]( "stuff") -'use strict'; +import parseLinkLabel from '../helpers/parse_link_label'; +import parseLinkDestination from '../helpers/parse_link_destination'; +import parseLinkTitle from '../helpers/parse_link_title'; +import normalizeReference from '../helpers/normalize_reference'; -var parseLinkLabel = require('../helpers/parse_link_label'); -var parseLinkDestination = require('../helpers/parse_link_destination'); -var parseLinkTitle = require('../helpers/parse_link_title'); -var normalizeReference = require('../helpers/normalize_reference'); - -module.exports = function links(state, silent) { +export default function links(state, silent) { var labelStart, labelEnd, label, diff --git a/lib/rules_inline/mark.js b/lib/rules_inline/mark.js index d154ba45..31b8b1ca 100644 --- a/lib/rules_inline/mark.js +++ b/lib/rules_inline/mark.js @@ -1,8 +1,6 @@ // Process ==highlighted text== -'use strict'; - -module.exports = function del(state, silent) { +export default function mark(state, silent) { var found, pos, stack, diff --git a/lib/rules_inline/newline.js b/lib/rules_inline/newline.js index 3fe8eb81..d748c4a3 100644 --- a/lib/rules_inline/newline.js +++ b/lib/rules_inline/newline.js @@ -1,8 +1,6 @@ // Proceess '\n' -'use strict'; - -module.exports = function newline(state, silent) { +export default function newline(state, silent) { var pmax, max, pos = state.pos; if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; } diff --git a/lib/rules_inline/state_inline.js b/lib/rules_inline/state_inline.js index fc3c0cfc..01535b02 100644 --- a/lib/rules_inline/state_inline.js +++ b/lib/rules_inline/state_inline.js @@ -1,8 +1,6 @@ // Inline parser state -'use strict'; - -function StateInline(src, parserInline, options, env, outTokens) { +export default function StateInline(src, parserInline, options, env, outTokens) { this.src = src; this.env = env; this.options = options; @@ -72,5 +70,3 @@ StateInline.prototype.cacheSet = function (key, val) { StateInline.prototype.cacheGet = function (key) { return key < this.cache.length ? this.cache[key] : 0; }; - -module.exports = StateInline; diff --git a/lib/rules_inline/sub.js b/lib/rules_inline/sub.js index a126e9ae..75bdc9e8 100644 --- a/lib/rules_inline/sub.js +++ b/lib/rules_inline/sub.js @@ -1,11 +1,9 @@ // Process ~subscript~ -'use strict'; - // same as UNESCAPE_MD_RE plus a space var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; -module.exports = function sub(state, silent) { +export default function sub(state, silent) { var found, content, max = state.posMax, diff --git a/lib/rules_inline/sup.js b/lib/rules_inline/sup.js index 07bf3574..b661828b 100644 --- a/lib/rules_inline/sup.js +++ b/lib/rules_inline/sup.js @@ -1,11 +1,9 @@ // Process ^superscript^ -'use strict'; - // same as UNESCAPE_MD_RE plus a space var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g; -module.exports = function sup(state, silent) { +export default function sup(state, silent) { var found, content, max = state.posMax, diff --git a/lib/rules_inline/text.js b/lib/rules_inline/text.js index 1bae53ee..c3d4384e 100644 --- a/lib/rules_inline/text.js +++ b/lib/rules_inline/text.js @@ -1,8 +1,6 @@ // Skip text characters for text token, place those to pending buffer // and increment current pos -'use strict'; - // Rule to skip pure text // '{}$%@~+=:' reserved for extentions @@ -35,7 +33,7 @@ function isTerminatorChar(ch) { } } -module.exports = function text(state, silent) { +export default function text(state, silent) { var pos = state.pos; while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) { diff --git a/package.json b/package.json index bce61024..cd92b7f5 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,7 @@ "bin", "linkify", "dist", - "index.js", - "lib" + "index.js" ], "bin": "./bin/remarkable.js", "main": "./dist/cjs/index.js", diff --git a/rollup.config.js b/rollup.config.js index 65df7b46..4a23bbee 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -10,19 +10,13 @@ export default [ { input: ['./lib/index.js', './lib/linkify.js'], output: { dir: 'dist/cjs', format: 'cjs' }, - external, - plugins: [ - commonjs(), - ] + external }, { input: ['./lib/index.js', './lib/linkify.js'], output: { dir: 'dist/esm', format: 'esm' }, - external, - plugins: [ - commonjs(), - ] + external }, {