diff --git a/dist/lib/defaults.js b/dist/lib/defaults.js
index 13eb696..bf2801f 100644
--- a/dist/lib/defaults.js
+++ b/dist/lib/defaults.js
@@ -1,5 +1,41 @@
-import * as tags from "./tags";
-export const defaultTags = new tags.TagCollection([
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ var desc = Object.getOwnPropertyDescriptor(m, k);
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+ desc = { enumerable: true, get: function() { return m[k]; } };
+ }
+ Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || (function () {
+ var ownKeys = function(o) {
+ ownKeys = Object.getOwnPropertyNames || function (o) {
+ var ar = [];
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
+ return ar;
+ };
+ return ownKeys(o);
+ };
+ return function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
+ __setModuleDefault(result, mod);
+ return result;
+ };
+})();
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.defaultTags = void 0;
+const tags = __importStar(require("./tags"));
+exports.defaultTags = new tags.TagCollection([
new tags.Bold(),
new tags.Italic(),
new tags.BoldItalic(),
diff --git a/dist/lib/hopdown.js b/dist/lib/hopdown.js
index e6d2c50..b7b28b3 100644
--- a/dist/lib/hopdown.js
+++ b/dist/lib/hopdown.js
@@ -1,10 +1,14 @@
+"use strict";
/*
* hopdown.ts
* - Configurable markdown <=> HTML converter.
*/
-import { defaultTags } from "./defaults";
-import { Tokenizer } from "./tokenizer";
-export function escapeHtml(source) {
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.HopDown = void 0;
+exports.escapeHtml = escapeHtml;
+const defaults_1 = require("./defaults");
+const tokenizer_1 = require("./tokenizer");
+function escapeHtml(source) {
return source
.replace(/&/g, '&')
.replace(/"
* );
*/
-export class HopDown {
+class HopDown {
tags;
referenceLinks = new Map();
tokenizer;
constructor(tags) {
- this.tags = tags || defaultTags;
- this.tokenizer = new Tokenizer(this.tags);
+ this.tags = tags || defaults_1.defaultTags;
+ this.tokenizer = new tokenizer_1.Tokenizer(this.tags);
}
/**
* Convert a markdown string to tokens.
@@ -376,3 +380,4 @@ export class HopDown {
return result;
}
}
+exports.HopDown = HopDown;
diff --git a/dist/lib/index.js b/dist/lib/index.js
index 1581dbb..6b5fadd 100644
--- a/dist/lib/index.js
+++ b/dist/lib/index.js
@@ -1,2 +1,18 @@
-export * from "./hopdown";
-export * from "./defaults";
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ var desc = Object.getOwnPropertyDescriptor(m, k);
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+ desc = { enumerable: true, get: function() { return m[k]; } };
+ }
+ Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./hopdown"), exports);
+__exportStar(require("./defaults"), exports);
diff --git a/dist/lib/tags.js b/dist/lib/tags.js
index 6d56153..2d2bd6c 100644
--- a/dist/lib/tags.js
+++ b/dist/lib/tags.js
@@ -1,4 +1,8 @@
-import { escapeHtml } from "./hopdown";
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Paragraph = exports.Table = exports.OrderedList = exports.UnorderedList = exports.Blockquote = exports.Heading = exports.HorizontalRule = exports.FencedCode = exports.HardBreak = exports.Anchor = exports.Code = exports.Strikethrough = exports.BoldItalic = exports.Italic = exports.Bold = exports.TagCollection = exports.Tag = void 0;
+exports.childNodesToMarkdown = childNodesToMarkdown;
+const hopdown_1 = require("./hopdown");
/**
* Patterns shared across multiple tag classes. Defined once here
* so the regexes aren't duplicated and can be referenced by name.
@@ -17,12 +21,12 @@ const tableSeparator = new RegExp('^'
+ '\\|?' // optional trailing pipe
+ '\\s*$' // end of line
);
-export function childNodesToMarkdown(element, callback) {
+function childNodesToMarkdown(element, callback) {
return Array.from(element.childNodes)
.map(child => callback(child))
.join('');
}
-export class Tag {
+class Tag {
element = [''];
opener = '';
closer = '';
@@ -66,7 +70,8 @@ export class Tag {
}
;
}
-export class TagCollection {
+exports.Tag = Tag;
+class TagCollection {
tags = {};
ordered;
openers;
@@ -125,41 +130,47 @@ export class TagCollection {
})[0] || undefined;
}
}
-export class Bold extends Tag {
+exports.TagCollection = TagCollection;
+class Bold extends Tag {
element = ['STRONG'];
aliases = ['B'];
delimiter = '**';
shortcut = 'Ctrl+B';
precedence = 40;
}
-export class Italic extends Tag {
+exports.Bold = Bold;
+class Italic extends Tag {
element = ['EM'];
aliases = ['I'];
delimiter = '*';
shortcut = 'Ctrl+I';
precedence = 30;
}
-export class BoldItalic extends Tag {
+exports.Italic = Italic;
+class BoldItalic extends Tag {
element = ['STRONG', 'EM'];
delimiter = '***';
precedence = 50;
}
-export class Strikethrough extends Tag {
+exports.BoldItalic = BoldItalic;
+class Strikethrough extends Tag {
element = ['DEL'];
aliases = ['S', 'STRIKE'];
delimiter = '~~';
}
-export class Code extends Tag {
+exports.Strikethrough = Strikethrough;
+class Code extends Tag {
element = ['CODE'];
delimiter = '`';
}
-export class Anchor extends Tag {
+exports.Code = Code;
+class Anchor extends Tag {
element = ['A'];
toHTML(token, callback) {
const titleAttr = token.title
- ? ` TITLE="${escapeHtml(token.title)}"`
+ ? ` TITLE="${(0, hopdown_1.escapeHtml)(token.title)}"`
: '';
- return `${escapeHtml(token.value)}`;
+ return `${(0, hopdown_1.escapeHtml)(token.value)}`;
}
toMarkdown(element, callback) {
const href = element.getAttribute('href') || '';
@@ -171,6 +182,7 @@ export class Anchor extends Tag {
return document.createElement('A');
}
}
+exports.Anchor = Anchor;
class BlockTag extends Tag {
isBlock = true;
delimiter = null;
@@ -184,20 +196,21 @@ class BlockTag extends Tag {
return null;
}
}
-export class HardBreak extends BlockTag {
+class HardBreak extends BlockTag {
match(context) {
return null;
}
toHTML() { return '
'; }
toMarkdown() { return ' \n'; }
}
+exports.HardBreak = HardBreak;
/**
* Fenced code blocks: lines between ``` delimiters become
.
*
* converter.toHTML('```js\nlet x = 1;\n```')
* // let x = 1;
*/
-export class FencedCode extends BlockTag {
+class FencedCode extends BlockTag {
opener = '```';
closer = '```';
element = ['PRE'];
@@ -233,9 +246,9 @@ export class FencedCode extends BlockTag {
}
toHTML(token, callback) {
const langAttr = token.meta?.lang
- ? ` class="language-${escapeHtml(token.meta.lang)}"`
+ ? ` class="language-${(0, hopdown_1.escapeHtml)(token.meta.lang)}"`
: '';
- return `${escapeHtml(token.content)}`;
+ return `${(0, hopdown_1.escapeHtml)(token.content)}`;
}
toMarkdown(element, callback) {
const lang = element.className.match(/language-(\S+)/)?.[1] || '';
@@ -243,12 +256,13 @@ export class FencedCode extends BlockTag {
return '\n\n' + this.opener + `${lang}\n${content}\n` + this.closer + '\n\n';
}
}
+exports.FencedCode = FencedCode;
/**
* Three or more *, -, or _ on a line become
.
*
* converter.toHTML('---') // '
'
*/
-export class HorizontalRule extends BlockTag {
+class HorizontalRule extends BlockTag {
element = ['HR'];
button = {
show: true,
@@ -278,7 +292,8 @@ export class HorizontalRule extends BlockTag {
return '\n***\n';
}
}
-export class Heading extends BlockTag {
+exports.HorizontalRule = HorizontalRule;
+class Heading extends BlockTag {
element = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
match(context) {
// ATX heading: # through ######, optional closing #s
@@ -333,6 +348,7 @@ export class Heading extends BlockTag {
return text.replace(escapeRegex, ' ').trim().split(/\s+/).map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join('_');
}
}
+exports.Heading = Heading;
/**
* Lines prefixed with > become blockquotes. Consecutive > lines
* are merged into a single blockquote.
@@ -340,7 +356,7 @@ export class Heading extends BlockTag {
* converter.toHTML('> hello\n> world')
* // hello\nworld
*/
-export class Blockquote extends BlockTag {
+class Blockquote extends BlockTag {
element = ['BLOCKQUOTE'];
hidden = false;
template = '> Quote\n> continues here';
@@ -410,13 +426,14 @@ export class Blockquote extends BlockTag {
return lines;
}
}
+exports.Blockquote = Blockquote;
/**
* Ordered and unordered lists with arbitrary nesting. Indentation
* determines depth; mixed list types (ul inside ol) are supported.
*
* converter.toHTML('- one\n- two\n 1. nested')
*/
-export class UnorderedList extends BlockTag {
+class UnorderedList extends BlockTag {
element = ['UL'];
hidden = false;
match(context) {
@@ -551,15 +568,17 @@ export class UnorderedList extends BlockTag {
};
}
}
-export class OrderedList extends UnorderedList {
+exports.UnorderedList = UnorderedList;
+class OrderedList extends UnorderedList {
element = ['OL'];
}
+exports.OrderedList = OrderedList;
/**
* Pipe-delimited tables with optional column alignment.
*
* converter.toHTML('| A | B |\n|---|---|\n| 1 | 2 |')
*/
-export class Table extends BlockTag {
+class Table extends BlockTag {
element = ['TABLE'];
hidden = false;
template = '| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |';
@@ -654,7 +673,8 @@ export class Table extends BlockTag {
});
}
}
-export class Paragraph extends BlockTag {
+exports.Table = Table;
+class Paragraph extends BlockTag {
element = ['P'];
opener = '';
closer = '';
@@ -694,3 +714,4 @@ export class Paragraph extends BlockTag {
return '' + callback(token.content) + '
';
}
}
+exports.Paragraph = Paragraph;
diff --git a/dist/lib/tokenizer.js b/dist/lib/tokenizer.js
index e038a08..1bd5fe2 100644
--- a/dist/lib/tokenizer.js
+++ b/dist/lib/tokenizer.js
@@ -1,3 +1,4 @@
+"use strict";
/*
* tokenizer.ts — markdown tokenizer.
*
@@ -10,6 +11,8 @@
* const tokens = tokenizer.tokenize('hello **bold** end');
* // [text "hello "] [open "**"] [text "bold"] [close "**"] [text " end"]
*/
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Tokenizer = void 0;
/**
* Characters that count as punctuation for flanking delimiter rules.
* A delimiter is left-flanking if preceded by whitespace/punctuation
@@ -42,7 +45,7 @@ const NAMED_ENTITIES = {
* ]);
* const tokens = tokenizer.tokenize('**bold**');
*/
-export class Tokenizer {
+class Tokenizer {
tags;
constructor(tags) {
this.tags = tags.ordered;
@@ -318,3 +321,4 @@ export class Tokenizer {
return null;
}
}
+exports.Tokenizer = Tokenizer;
diff --git a/dist/lib/types.js b/dist/lib/types.js
index f8bdff4..fabb051 100644
--- a/dist/lib/types.js
+++ b/dist/lib/types.js
@@ -1 +1,2 @@
-export {};
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
diff --git a/package.json b/package.json
index 555df00..53f294d 100644
--- a/package.json
+++ b/package.json
@@ -2,10 +2,11 @@
"name": "hopdown",
"version": "1.0.0",
"description": "Configurable HTML <=> Markdown converter for WYSIWYG editors.",
- "module": "dist/lib/index.js",
"files": [
"dist/lib/"
],
+ "type": "module",
+ "types": "src/ts/index.d.ts",
"scripts": {
"tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
"build": "npm run tsc",
diff --git a/tsconfig.json b/tsconfig.json
index 8ec9bb2..502a1ba 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,7 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "ES2025",
- "module": "ES2022",
+ "module": "CommonJS",
"esModuleInterop": true,
"types": ["node"],
"forceConsistentCasingInFileNames": true,