markdown-to-jsx
- Version 7.4.7
- Published
- 466 kB
- No dependencies
- MIT license
Install
npm i markdown-to-jsx
yarn add markdown-to-jsx
pnpm add markdown-to-jsx
Overview
Convert markdown to JSX with ease for React and React-like projects. Super lightweight and highly configurable.
Index
Variables
Functions
Enums
RuleType
- blockQuote
- breakLine
- breakThematic
- codeBlock
- codeFenced
- codeInline
- footnote
- footnoteReference
- gfmTask
- heading
- headingSetext
- htmlBlock
- htmlComment
- htmlSelfClosing
- image
- link
- linkAngleBraceStyleDetector
- linkBareUrlDetector
- linkMailtoDetector
- newlineCoalescer
- orderedList
- paragraph
- ref
- refImage
- refLink
- table
- tableSeparator
- text
- textBolded
- textEmphasized
- textEscaped
- textMarked
- textStrikethroughed
- unorderedList
Namespaces
MarkdownToJSX
- BlockQuoteNode
- BoldTextNode
- BreakLineNode
- BreakThematicNode
- CodeBlockNode
- CodeFencedNode
- CodeInlineNode
- CreateElement
- EscapedTextNode
- FootnoteNode
- FootnoteReferenceNode
- GFMTaskNode
- HeadingNode
- HeadingSetextNode
- HTMLCommentNode
- HTMLNode
- HTMLSelfClosingNode
- HTMLTags
- ImageNode
- ItalicTextNode
- LinkAngleBraceNode
- LinkBareURLNode
- LinkMailtoNode
- LinkNode
- MarkedTextNode
- NestedParser
- NewlineNode
- Options
- OrderedListNode
- Override
- Overrides
- ParagraphNode
- Parser
- ParserResult
- ReferenceImageNode
- ReferenceLinkNode
- ReferenceNode
- Rule
- RuleOutput
- Rules
- State
- StrikethroughTextNode
- TableNode
- TableSeparatorNode
- TextNode
- UnorderedListNode
Variables
variable Markdown
const Markdown: React.FC<{ [key: string]: any; children: string; options?: MarkdownToJSX.Options;}>;
A simple HOC for easy React use. Feed the markdown content as a direct child and the rest is taken care of automatically.
Functions
Enums
enum RuleType
const enum RuleType { blockQuote = '0', breakLine = '1', breakThematic = '2', codeBlock = '3', codeFenced = '4', codeInline = '5', footnote = '6', footnoteReference = '7', gfmTask = '8', heading = '9', headingSetext = '10', htmlBlock = '11', htmlComment = '12', htmlSelfClosing = '13', image = '14', link = '15', linkAngleBraceStyleDetector = '16', linkBareUrlDetector = '17', linkMailtoDetector = '18', newlineCoalescer = '19', orderedList = '20', paragraph = '21', ref = '22', refImage = '23', refLink = '24', table = '25', tableSeparator = '26', text = '27', textBolded = '28', textEmphasized = '29', textEscaped = '30', textMarked = '31', textStrikethroughed = '32', unorderedList = '33',}
Analogous to
node.type
. Please note that the values here may change at any time, so do not hard code against the value directly.
member blockQuote
blockQuote = '0'
member breakLine
breakLine = '1'
member breakThematic
breakThematic = '2'
member codeBlock
codeBlock = '3'
member codeFenced
codeFenced = '4'
member codeInline
codeInline = '5'
member footnote
footnote = '6'
member footnoteReference
footnoteReference = '7'
member gfmTask
gfmTask = '8'
member heading
heading = '9'
member headingSetext
headingSetext = '10'
member htmlBlock
htmlBlock = '11'
only available if not
disableHTMLParsing
member htmlComment
htmlComment = '12'
member htmlSelfClosing
htmlSelfClosing = '13'
only available if not
disableHTMLParsing
member image
image = '14'
member link
link = '15'
member linkAngleBraceStyleDetector
linkAngleBraceStyleDetector = '16'
emits a
link
'node', does not render directly
member linkBareUrlDetector
linkBareUrlDetector = '17'
emits a
link
'node', does not render directly
member linkMailtoDetector
linkMailtoDetector = '18'
emits a
link
'node', does not render directly
member newlineCoalescer
newlineCoalescer = '19'
member orderedList
orderedList = '20'
member paragraph
paragraph = '21'
member ref
ref = '22'
member refImage
refImage = '23'
member refLink
refLink = '24'
member table
table = '25'
member tableSeparator
tableSeparator = '26'
member text
text = '27'
member textBolded
textBolded = '28'
member textEmphasized
textEmphasized = '29'
member textEscaped
textEscaped = '30'
member textMarked
textMarked = '31'
member textStrikethroughed
textStrikethroughed = '32'
member unorderedList
unorderedList = '33'
Namespaces
namespace MarkdownToJSX
namespace MarkdownToJSX {}
interface BlockQuoteNode
interface BlockQuoteNode {}
interface BoldTextNode
interface BoldTextNode {}
interface BreakLineNode
interface BreakLineNode {}
property type
type: RuleType.breakLine;
interface BreakThematicNode
interface BreakThematicNode {}
property type
type: RuleType.breakThematic;
interface CodeBlockNode
interface CodeBlockNode {}
interface CodeFencedNode
interface CodeFencedNode {}
property type
type: RuleType.codeFenced;
interface CodeInlineNode
interface CodeInlineNode {}
interface EscapedTextNode
interface EscapedTextNode {}
property type
type: RuleType.textEscaped;
interface FootnoteNode
interface FootnoteNode {}
property type
type: RuleType.footnote;
interface FootnoteReferenceNode
interface FootnoteReferenceNode {}
interface GFMTaskNode
interface GFMTaskNode {}
interface HeadingNode
interface HeadingNode {}
interface HeadingSetextNode
interface HeadingSetextNode {}
property type
type: RuleType.headingSetext;
interface HTMLCommentNode
interface HTMLCommentNode {}
property type
type: RuleType.htmlComment;
interface HTMLNode
interface HTMLNode {}
interface HTMLSelfClosingNode
interface HTMLSelfClosingNode {}
interface ImageNode
interface ImageNode {}
interface ItalicTextNode
interface ItalicTextNode {}
interface LinkAngleBraceNode
interface LinkAngleBraceNode {}
property type
type: RuleType.linkAngleBraceStyleDetector;
interface LinkBareURLNode
interface LinkBareURLNode {}
property type
type: RuleType.linkBareUrlDetector;
interface LinkMailtoNode
interface LinkMailtoNode {}
property type
type: RuleType.linkMailtoDetector;
interface LinkNode
interface LinkNode {}
interface MarkedTextNode
interface MarkedTextNode {}
interface NewlineNode
interface NewlineNode {}
property type
type: RuleType.newlineCoalescer;
interface OrderedListNode
interface OrderedListNode {}
interface ParagraphNode
interface ParagraphNode {}
interface ReferenceImageNode
interface ReferenceImageNode {}
interface ReferenceLinkNode
interface ReferenceLinkNode {}
property children
children: MarkdownToJSX.ParserResult[];
property fallbackChildren
fallbackChildren: MarkdownToJSX.ParserResult[];
property ref
ref: string;
property type
type: RuleType.refLink;
interface ReferenceNode
interface ReferenceNode {}
property type
type: RuleType.ref;
interface StrikethroughTextNode
interface StrikethroughTextNode {}
interface TableNode
interface TableNode {}
interface TableSeparatorNode
interface TableSeparatorNode {}
property type
type: RuleType.tableSeparator;
interface UnorderedListNode
interface UnorderedListNode {}
type CreateElement
type CreateElement = typeof React.createElement;
type HTMLTags
type HTMLTags = keyof JSX.IntrinsicElements;
type NestedParser
type NestedParser = ( input: string, state?: MarkdownToJSX.State) => MarkdownToJSX.ParserResult[];
type Options
type Options = Partial<{ /** * Ultimate control over the output of all rendered JSX. */ createElement: ( tag: Parameters<CreateElement>[0], props: JSX.IntrinsicAttributes, ...children: React.ReactChild[] ) => React.ReactChild; /** * Disable the compiler's best-effort transcription of provided raw HTML * into JSX-equivalent. This is the functionality that prevents the need to * use `dangerouslySetInnerHTML` in React. */ disableParsingRawHTML: boolean; /** * Forces the compiler to have space between hash sign and the header text which * is explicitly stated in the most of the markdown specs. * https://github.github.com/gfm/#atx-heading * `The opening sequence of # characters must be followed by a space or by the end of line.` */ enforceAtxHeadings: boolean; /** * Forces the compiler to always output content with a block-level wrapper * (`<p>` or any block-level syntax your markdown already contains.) */ forceBlock: boolean; /** * Forces the compiler to always output content with an inline wrapper (`<span>`) */ forceInline: boolean; /** * Forces the compiler to wrap results, even if there is only a single * child or no children. */ forceWrapper: boolean; /** * Supply additional HTML entity: unicode replacement mappings. * * Pass only the inner part of the entity as the key, * e.g. `≤` -> `{ "le": "\u2264" }` * * By default * the following entities are replaced with their unicode equivalents: * * ``` * & * ' * > * < * * " * ``` */ namedCodesToUnicode: { [key: string]: string; }; /** * Selectively control the output of particular HTML tags as they would be * emitted by the compiler. */ overrides: Overrides; /** * Allows for full control over rendering of particular rules. * For example, to implement a LaTeX renderer such as `react-katex`: * * ``` * renderRule(next, node, renderChildren, state) { * if (node.type === RuleType.codeBlock && node.lang === 'latex') { * return ( * <TeX as="div" key={state.key}> * {String.raw`${node.text}`} * </TeX> * ) * } * * return next(); * } * ``` * * Thar be dragons obviously, but you can do a lot with this * (have fun!) To see how things work internally, check the `render` * method in source for a particular rule. */ renderRule: ( /** Resume normal processing, call this function as a fallback if you are not returning custom JSX. */ next: () => React.ReactChild, /** the current AST node, use `RuleType` against `node.type` for identification */ node: ParserResult, /** use as `renderChildren(node.children)` for block nodes */ renderChildren: RuleOutput, /** contains `key` which should be supplied to the topmost JSX element */ state: State ) => React.ReactChild; /** * Override normalization of non-URI-safe characters for use in generating * HTML IDs for anchor linking purposes. */ slugify: (source: string) => string; /** * Declare the type of the wrapper to be used when there are multiple * children to render. Set to `null` to get an array of children back * without any wrapper, or use `React.Fragment` to get a React element * that won't show up in the DOM. */ wrapper: React.ElementType | null;}>;
type Override
type Override = | RequireAtLeastOne<{ component: React.ElementType; props: Object; }> | React.ElementType;
type Overrides
type Overrides = { [tag in HTMLTags]?: Override;} & { [customComponent: string]: Override;};
type Parser
type Parser<ParserOutput> = ( capture: RegExpMatchArray, nestedParse: NestedParser, state?: MarkdownToJSX.State) => ParserOutput;
type ParserResult
type ParserResult = | BlockQuoteNode | BreakLineNode | BreakThematicNode | CodeBlockNode | CodeFencedNode | CodeInlineNode | FootnoteNode | FootnoteReferenceNode | GFMTaskNode | HeadingNode | HeadingSetextNode | HTMLCommentNode | ImageNode | LinkNode | LinkAngleBraceNode | LinkBareURLNode | LinkMailtoNode | OrderedListNode | UnorderedListNode | NewlineNode | ParagraphNode | ReferenceNode | ReferenceImageNode | ReferenceLinkNode | TableNode | TableSeparatorNode | TextNode | BoldTextNode | ItalicTextNode | EscapedTextNode | MarkedTextNode | StrikethroughTextNode | HTMLNode | HTMLSelfClosingNode;
type Rule
type Rule<ParserOutput = MarkdownToJSX.ParserResult> = { match: ( source: string, state: MarkdownToJSX.State, prevCapturedString?: string ) => RegExpMatchArray; order: Priority; parse: MarkdownToJSX.Parser<Omit<ParserOutput, 'type'>>; render?: ( node: ParserOutput, /** * Continue rendering AST nodes if applicable. */ render: RuleOutput, state?: MarkdownToJSX.State ) => React.ReactChild;};
type RuleOutput
type RuleOutput = ( ast: MarkdownToJSX.ParserResult | MarkdownToJSX.ParserResult[], state: MarkdownToJSX.State) => JSX.Element;
type Rules
type Rules = { [K in ParserResult['type']]: K extends RuleType.table ? Rule< Extract< ParserResult, { type: K | RuleType.paragraph; } > > : Rule< Extract< ParserResult, { type: K; } > >;};
type State
type State = { /** true if the current content is inside anchor link grammar */ inAnchor?: boolean; /** true if parsing in an inline context (subset of rules around formatting and links) */ inline?: boolean; /** true if in a table */ inTable?: boolean; /** use this for the `key` prop */ key?: React.Key; /** true if in a list */ list?: boolean; /** true if parsing in inline context w/o links */ simple?: boolean;};
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (31)
- @babel/plugin-proposal-nullish-coalescing-operator
- @babel/plugin-proposal-object-rest-spread
- @babel/plugin-proposal-optional-chaining
- @babel/plugin-transform-typescript
- @changesets/cli
- @matejmazur/react-katex
- @size-limit/preset-small-lib
- @types/jest
- @types/node
- @types/react
- benchtable
- cli-progress
- in-publish
- jest
- jest-environment-jsdom
- jest-serializer-html
- markdown-it
- microbundle
- microtime
- mkdirp
- preact
- prettier
- react
- react-dom
- rimraf
- simple-markdown
- size-limit
- styled-components
- theredoc
- ts-jest
- typescript
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/markdown-to-jsx
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/markdown-to-jsx)
- HTML<a href="https://www.jsdocs.io/package/markdown-to-jsx"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3406 ms. - Missing or incorrect documentation? Open an issue for this package.