Comparing version 2.0.0 to 3.0.0
@@ -5,4 +5,5 @@ /** | ||
*/ | ||
import { Component, MarkdownNode } from "./model"; | ||
export declare function createElement(component: Component, attributes: Record<string, unknown> | null, ...children: MarkdownNode[]): MarkdownNode | MarkdownNode[]; | ||
export declare function createElement(nodeType: string, attributes: null, ...children: MarkdownNode[]): MarkdownNode | MarkdownNode[]; | ||
import { Component, MarkdownElement, MdFragmentType, MdAwaitType, MarkdownChildren } from "./model"; | ||
export declare function createElement(component: Component, attributes: Record<string, unknown> | null, ...children: MarkdownChildren[]): MarkdownElement; | ||
export declare function createElement(nodeType: typeof MdFragmentType, attributes: null, ...children: MarkdownChildren[]): MarkdownElement; | ||
export declare function createElement(nodeType: typeof MdAwaitType, attributes: null, children: Promise<MarkdownChildren>): MarkdownElement; |
@@ -13,2 +13,9 @@ "use strict"; | ||
} | ||
if (typeOrComponent === model_1.MdAwaitType) { | ||
// Throws error if is it not exactly one children. | ||
if (children.length !== 1) { | ||
throw new TypeError(`Received ${children.length} promises, expected a single promise.`); | ||
} | ||
return createPromiseElement(children[0]); | ||
} | ||
if (typeof typeOrComponent === "function") { | ||
@@ -22,2 +29,3 @@ return createComponentElement(typeOrComponent, attributes, children); | ||
return { | ||
type: model_1.MdFragmentType, | ||
props: { | ||
@@ -27,5 +35,11 @@ children: children.flat(), | ||
key: null, | ||
type: model_1.MdFragmentType, | ||
}; | ||
} | ||
function createPromiseElement(children) { | ||
return { | ||
type: model_1.MdAwaitType, | ||
props: { children }, | ||
key: null, | ||
}; | ||
} | ||
function createComponentElement(component, attributes, children) { | ||
@@ -32,0 +46,0 @@ return { |
@@ -5,6 +5,6 @@ /** | ||
*/ | ||
export { Await } from "./Await"; | ||
export { BlockQuote } from "./BlockQuote"; | ||
export { Bold } from "./Bold"; | ||
export { CodeBlock } from "./CodeBlock"; | ||
export { Emphasis } from "./Emphasis"; | ||
export { Fragment } from "./Fragment"; | ||
@@ -11,0 +11,0 @@ export { Heading } from "./Heading"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnorderedList = exports.Text = exports.Task = exports.TableAlignment = exports.Table = exports.ReferenceLink = exports.ReferenceImage = exports.Reference = exports.Strikethrough = exports.OrderedList = exports.Link = exports.LineBreak = exports.Italics = exports.InlineCode = exports.Image = exports.HorizontalRule = exports.Heading = exports.Fragment = exports.Emphasis = exports.CodeBlock = exports.Bold = exports.BlockQuote = void 0; | ||
exports.UnorderedList = exports.Text = exports.Task = exports.TableAlignment = exports.Table = exports.ReferenceLink = exports.ReferenceImage = exports.Reference = exports.Strikethrough = exports.OrderedList = exports.Link = exports.LineBreak = exports.Italics = exports.InlineCode = exports.Image = exports.HorizontalRule = exports.Heading = exports.Fragment = exports.CodeBlock = exports.Bold = exports.BlockQuote = exports.Await = void 0; | ||
/** | ||
@@ -8,2 +8,4 @@ * @packageDocumentation | ||
*/ | ||
var Await_1 = require("./Await"); | ||
Object.defineProperty(exports, "Await", { enumerable: true, get: function () { return Await_1.Await; } }); | ||
var BlockQuote_1 = require("./BlockQuote"); | ||
@@ -15,4 +17,2 @@ Object.defineProperty(exports, "BlockQuote", { enumerable: true, get: function () { return BlockQuote_1.BlockQuote; } }); | ||
Object.defineProperty(exports, "CodeBlock", { enumerable: true, get: function () { return CodeBlock_1.CodeBlock; } }); | ||
var Emphasis_1 = require("./Emphasis"); | ||
Object.defineProperty(exports, "Emphasis", { enumerable: true, get: function () { return Emphasis_1.Emphasis; } }); | ||
var Fragment_1 = require("./Fragment"); | ||
@@ -19,0 +19,0 @@ Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return Fragment_1.Fragment; } }); |
/** @internal */ | ||
export declare const MdFragmentType: "mdFragment"; | ||
/** @internal */ | ||
export interface MdFunctionElement<Props = unknown> { | ||
type: Component<Props>; | ||
export declare const MdAwaitType: "mdAwait"; | ||
/** @internal */ | ||
interface MdElement<Type, Props = unknown> { | ||
type: Type; | ||
props: Props; | ||
@@ -10,9 +12,11 @@ key: string | number | null; | ||
/** @internal */ | ||
export interface MdFragmentElement { | ||
type: typeof MdFragmentType; | ||
props: PropsWithChildren; | ||
key: string | number | null; | ||
} | ||
export declare type MdFunctionElement<Props = unknown> = MdElement<Component<Props>, Props>; | ||
/** @internal */ | ||
export declare type MdFragmentElement = MdElement<typeof MdFragmentType, PropsWithChildren>; | ||
/** @internal */ | ||
export declare type MdAwaitElement = MdElement<typeof MdAwaitType, { | ||
children: Promise<MarkdownChildren>; | ||
}>; | ||
/** Internal representation of markdown before rendering. */ | ||
export declare type MarkdownElement<Props = unknown> = MdFunctionElement<Props> | MdFragmentElement; | ||
export declare type MarkdownElement<Props = unknown> = MdFunctionElement<Props> | MdFragmentElement | MdAwaitElement; | ||
/** Primitive text types that get converted into text. */ | ||
@@ -32,1 +36,15 @@ export declare type MarkdownText = string | number; | ||
export declare type Component<ComponentProps extends unknown = unknown> = (props: ComponentProps) => MarkdownElement | null; | ||
/** @internal */ | ||
declare global { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
mdFragment: { | ||
children?: MarkdownChildren; | ||
}; | ||
mdAwait: { | ||
children?: Promise<MarkdownChildren>; | ||
}; | ||
} | ||
} | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MdFragmentType = void 0; | ||
exports.MdAwaitType = exports.MdFragmentType = void 0; | ||
/** @internal */ | ||
exports.MdFragmentType = "mdFragment"; | ||
/** @internal */ | ||
exports.MdAwaitType = "mdAwait"; | ||
//# sourceMappingURL=model.js.map |
@@ -6,6 +6,5 @@ "use strict"; | ||
/** @internal */ | ||
function renderNode(element) { | ||
const results = renderFunctions_1.synchronousRenderFunctions | ||
.map((renderFunction) => renderFunction(element, renderNode)) | ||
.filter((result) => result !== null); | ||
async function renderNode(element) { | ||
const promises = renderFunctions_1.renderFunctions.map((renderFunction) => renderFunction(element, renderNode)); | ||
const results = (await Promise.all(promises)).filter((result) => result !== null); | ||
if (results.length === 0) { | ||
@@ -12,0 +11,0 @@ throw new Error("Invalid element"); |
import { RenderFunction } from "./RenderFunction"; | ||
export declare const synchronousRenderFunctions: RenderFunction[]; | ||
export declare const renderFunctions: RenderFunction[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.synchronousRenderFunctions = void 0; | ||
exports.renderFunctions = void 0; | ||
const renderNil_1 = require("./renderNil"); | ||
@@ -9,4 +9,5 @@ const renderString_1 = require("./renderString"); | ||
const renderFunctionElement_1 = require("./renderFunctionElement"); | ||
const renderPromiseElement_1 = require("./renderPromiseElement"); | ||
const renderFragmentElement_1 = require("./renderFragmentElement"); | ||
exports.synchronousRenderFunctions = [ | ||
exports.renderFunctions = [ | ||
renderNil_1.renderNil, | ||
@@ -18,3 +19,4 @@ renderString_1.renderString, | ||
renderFragmentElement_1.renderFragmentElement, | ||
renderPromiseElement_1.renderPromiseElement, | ||
]; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renderArray = void 0; | ||
exports.renderArray = (element, renderer) => Array.isArray(element) | ||
? element | ||
.map((el) => renderer(el)) | ||
.filter((el) => el !== null) | ||
.join("") | ||
exports.renderArray = async (element, renderer) => Array.isArray(element) | ||
? Promise.all(element.map((el) => renderer(el))) | ||
.then((results) => results.filter((el) => el !== null)) | ||
.then((results) => results.join("")) | ||
: null; | ||
//# sourceMappingURL=renderArray.js.map |
@@ -9,3 +9,5 @@ "use strict"; | ||
const isMdFragmentElement_1 = require("../util/isMdFragmentElement"); | ||
exports.renderFragmentElement = (element, renderer) => isMdFragmentElement_1.isMdFragmentElement(element) ? renderer(element.props.children) : null; | ||
exports.renderFragmentElement = async (element, renderer) => isMdFragmentElement_1.isMdFragmentElement(element) | ||
? Promise.resolve(renderer(element.props.children)) | ||
: null; | ||
//# sourceMappingURL=renderFragmentElement.js.map |
@@ -7,3 +7,3 @@ /** | ||
export interface RenderFunction { | ||
(element: MarkdownChildren, renderer: (el: MarkdownChildren) => string | null): string | null; | ||
(element: MarkdownChildren, renderer: (el: MarkdownChildren) => Promise<string | null>): Promise<string | null>; | ||
} |
@@ -9,3 +9,5 @@ "use strict"; | ||
const isMdFunctionElement_1 = require("../util/isMdFunctionElement"); | ||
exports.renderFunctionElement = (element, renderer) => isMdFunctionElement_1.isMdFunctionElement(element) ? renderer(element.type(element.props)) : null; | ||
exports.renderFunctionElement = async (element, renderer) => isMdFunctionElement_1.isMdFunctionElement(element) | ||
? Promise.resolve(renderer(element.type(element.props))) | ||
: null; | ||
//# sourceMappingURL=renderFunctionElement.js.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
const isMarkdownNil_1 = require("../util/isMarkdownNil"); | ||
exports.renderNil = (element) => isMarkdownNil_1.isMarkdownNil(element) ? "" : null; | ||
exports.renderNil = async (element) => isMarkdownNil_1.isMarkdownNil(element) ? Promise.resolve("") : null; | ||
//# sourceMappingURL=renderNil.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renderNumber = void 0; | ||
exports.renderNumber = (element) => typeof element === "number" ? element.toString() : null; | ||
exports.renderNumber = async (element) => typeof element === "number" ? Promise.resolve(element.toString()) : null; | ||
//# sourceMappingURL=renderNumber.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.renderString = void 0; | ||
exports.renderString = (element) => typeof element === "string" ? element : null; | ||
exports.renderString = async (element) => typeof element === "string" ? Promise.resolve(element) : null; | ||
//# sourceMappingURL=renderString.js.map |
{ | ||
"name": "jsx-md", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Generate markdown files with a React-like syntax.", | ||
@@ -52,2 +52,3 @@ "main": "lib/index.js", | ||
"ts-jest": "^26.2.0", | ||
"ts-node": "^9.0.0", | ||
"tslib": "^2.0.1", | ||
@@ -54,0 +55,0 @@ "typedoc": "^0.19.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80702
122
1675
26