diff --git a/dist/lib/defaults.js b/dist/lib/defaults.js index bf2801f..13eb696 100644 --- a/dist/lib/defaults.js +++ b/dist/lib/defaults.js @@ -1,41 +1,5 @@ -"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([ +import * as tags from "./tags"; +export const 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 b7b28b3..e6d2c50 100644 --- a/dist/lib/hopdown.js +++ b/dist/lib/hopdown.js @@ -1,14 +1,10 @@ -"use strict"; /* * hopdown.ts * - Configurable markdown <=> HTML converter. */ -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) { +import { defaultTags } from "./defaults"; +import { Tokenizer } from "./tokenizer"; +export function escapeHtml(source) { return source .replace(/&/g, '&') .replace(/" * ); */ -class HopDown { +export class HopDown { tags; referenceLinks = new Map(); tokenizer; constructor(tags) { - this.tags = tags || defaults_1.defaultTags; - this.tokenizer = new tokenizer_1.Tokenizer(this.tags); + this.tags = tags || defaultTags; + this.tokenizer = new Tokenizer(this.tags); } /** * Convert a markdown string to tokens. @@ -380,4 +376,3 @@ class HopDown { return result; } } -exports.HopDown = HopDown; diff --git a/dist/lib/index.js b/dist/lib/index.js index 6b5fadd..1581dbb 100644 --- a/dist/lib/index.js +++ b/dist/lib/index.js @@ -1,18 +1,2 @@ -"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); +export * from "./hopdown"; +export * from "./defaults"; diff --git a/dist/lib/tags.js b/dist/lib/tags.js index 2d2bd6c..6d56153 100644 --- a/dist/lib/tags.js +++ b/dist/lib/tags.js @@ -1,8 +1,4 @@ -"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"); +import { escapeHtml } from "./hopdown"; /** * Patterns shared across multiple tag classes. Defined once here * so the regexes aren't duplicated and can be referenced by name. @@ -21,12 +17,12 @@ const tableSeparator = new RegExp('^' + '\\|?' // optional trailing pipe + '\\s*$' // end of line ); -function childNodesToMarkdown(element, callback) { +export function childNodesToMarkdown(element, callback) { return Array.from(element.childNodes) .map(child => callback(child)) .join(''); } -class Tag { +export class Tag { element = ['']; opener = ''; closer = ''; @@ -70,8 +66,7 @@ class Tag { } ; } -exports.Tag = Tag; -class TagCollection { +export class TagCollection { tags = {}; ordered; openers; @@ -130,47 +125,41 @@ class TagCollection { })[0] || undefined; } } -exports.TagCollection = TagCollection; -class Bold extends Tag { +export class Bold extends Tag { element = ['STRONG']; aliases = ['B']; delimiter = '**'; shortcut = 'Ctrl+B'; precedence = 40; } -exports.Bold = Bold; -class Italic extends Tag { +export class Italic extends Tag { element = ['EM']; aliases = ['I']; delimiter = '*'; shortcut = 'Ctrl+I'; precedence = 30; } -exports.Italic = Italic; -class BoldItalic extends Tag { +export class BoldItalic extends Tag { element = ['STRONG', 'EM']; delimiter = '***'; precedence = 50; } -exports.BoldItalic = BoldItalic; -class Strikethrough extends Tag { +export class Strikethrough extends Tag { element = ['DEL']; aliases = ['S', 'STRIKE']; delimiter = '~~'; } -exports.Strikethrough = Strikethrough; -class Code extends Tag { +export class Code extends Tag { element = ['CODE']; delimiter = '`'; } -exports.Code = Code; -class Anchor extends Tag { +export class Anchor extends Tag { element = ['A']; toHTML(token, callback) { const titleAttr = token.title - ? ` TITLE="${(0, hopdown_1.escapeHtml)(token.title)}"` + ? ` TITLE="${escapeHtml(token.title)}"` : ''; - return `${(0, hopdown_1.escapeHtml)(token.value)}`; + return `${escapeHtml(token.value)}`; } toMarkdown(element, callback) { const href = element.getAttribute('href') || ''; @@ -182,7 +171,6 @@ class Anchor extends Tag { return document.createElement('A'); } } -exports.Anchor = Anchor; class BlockTag extends Tag { isBlock = true; delimiter = null; @@ -196,21 +184,20 @@ class BlockTag extends Tag { return null; } } -class HardBreak extends BlockTag { +export 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;
*/ -class FencedCode extends BlockTag { +export class FencedCode extends BlockTag { opener = '```'; closer = '```'; element = ['PRE']; @@ -246,9 +233,9 @@ class FencedCode extends BlockTag { } toHTML(token, callback) { const langAttr = token.meta?.lang - ? ` class="language-${(0, hopdown_1.escapeHtml)(token.meta.lang)}"` + ? ` class="language-${escapeHtml(token.meta.lang)}"` : ''; - return `${(0, hopdown_1.escapeHtml)(token.content)}
`; + return `${escapeHtml(token.content)}`; } toMarkdown(element, callback) { const lang = element.className.match(/language-(\S+)/)?.[1] || ''; @@ -256,13 +243,12 @@ 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('---') // '
' */ -class HorizontalRule extends BlockTag { +export class HorizontalRule extends BlockTag { element = ['HR']; button = { show: true, @@ -292,8 +278,7 @@ class HorizontalRule extends BlockTag { return '\n***\n'; } } -exports.HorizontalRule = HorizontalRule; -class Heading extends BlockTag { +export class Heading extends BlockTag { element = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; match(context) { // ATX heading: # through ######, optional closing #s @@ -348,7 +333,6 @@ 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. @@ -356,7 +340,7 @@ exports.Heading = Heading; * converter.toHTML('> hello\n> world') * //

hello\nworld

*/ -class Blockquote extends BlockTag { +export class Blockquote extends BlockTag { element = ['BLOCKQUOTE']; hidden = false; template = '> Quote\n> continues here'; @@ -426,14 +410,13 @@ 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') */ -class UnorderedList extends BlockTag { +export class UnorderedList extends BlockTag { element = ['UL']; hidden = false; match(context) { @@ -568,17 +551,15 @@ class UnorderedList extends BlockTag { }; } } -exports.UnorderedList = UnorderedList; -class OrderedList extends UnorderedList { +export class OrderedList extends UnorderedList { element = ['OL']; } -exports.OrderedList = OrderedList; /** * Pipe-delimited tables with optional column alignment. * * converter.toHTML('| A | B |\n|---|---|\n| 1 | 2 |') */ -class Table extends BlockTag { +export class Table extends BlockTag { element = ['TABLE']; hidden = false; template = '| Header 1 | Header 2 |\n|----------|----------|\n| Cell 1 | Cell 2 |'; @@ -673,8 +654,7 @@ class Table extends BlockTag { }); } } -exports.Table = Table; -class Paragraph extends BlockTag { +export class Paragraph extends BlockTag { element = ['P']; opener = ''; closer = ''; @@ -714,4 +694,3 @@ class Paragraph extends BlockTag { return '

' + callback(token.content) + '

'; } } -exports.Paragraph = Paragraph; diff --git a/dist/lib/tokenizer.js b/dist/lib/tokenizer.js index 1bd5fe2..e038a08 100644 --- a/dist/lib/tokenizer.js +++ b/dist/lib/tokenizer.js @@ -1,4 +1,3 @@ -"use strict"; /* * tokenizer.ts — markdown tokenizer. * @@ -11,8 +10,6 @@ * 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 @@ -45,7 +42,7 @@ const NAMED_ENTITIES = { * ]); * const tokens = tokenizer.tokenize('**bold**'); */ -class Tokenizer { +export class Tokenizer { tags; constructor(tags) { this.tags = tags.ordered; @@ -321,4 +318,3 @@ class Tokenizer { return null; } } -exports.Tokenizer = Tokenizer; diff --git a/dist/lib/types.js b/dist/lib/types.js index fabb051..f8bdff4 100644 --- a/dist/lib/types.js +++ b/dist/lib/types.js @@ -1,2 +1 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); +export {}; diff --git a/tsconfig.json b/tsconfig.json index a07fdc0..8ec9bb2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "strict": true, "target": "ES2025", - "module": "commonjs", + "module": "ES2022", "esModuleInterop": true, "types": ["node"], "forceConsistentCasingInFileNames": true,