Skip to content

Commit

Permalink
chore: switch RuleType back to an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Jan 1, 2024
1 parent 62c6878 commit 7ec5872
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 77 deletions.
12 changes: 7 additions & 5 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3799,7 +3799,7 @@ describe('options.slugify', () => {

describe('overrides', () => {
it('should substitute the appropriate JSX tag if given a component', () => {
class FakeParagraph extends React.Component {
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
render() {
return <p className="foo">{this.props.children}</p>
}
Expand Down Expand Up @@ -3837,7 +3837,7 @@ describe('overrides', () => {
})

it('should accept an override shorthand if props do not need to be overidden', () => {
class FakeParagraph extends React.Component {
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
render() {
return <p className="foo">{this.props.children}</p>
}
Expand Down Expand Up @@ -3865,7 +3865,9 @@ describe('overrides', () => {
})

it('should override the title property when parsing a link', () => {
class FakeLink extends React.Component<{ title: string }> {
class FakeLink extends React.Component<
React.PropsWithChildren<{ title: string }>
> {
render() {
const { title, children } = this.props
return <a title={title}>{children}</a>
Expand Down Expand Up @@ -3910,7 +3912,7 @@ describe('overrides', () => {
})

it('should substitute pre & code tags if supplied with an override component', () => {
class OverridenPre extends React.Component {
class OverridenPre extends React.Component<React.PropsWithChildren<{}>> {
render() {
const { children, ...props } = this.props

Expand All @@ -3922,7 +3924,7 @@ describe('overrides', () => {
}
}

class OverridenCode extends React.Component {
class OverridenCode extends React.Component<React.PropsWithChildren<{}>> {
render() {
const { children, ...props } = this.props

Expand Down
2 changes: 1 addition & 1 deletion index.component.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ it('handles a no-children scenario', () => {
})

it('accepts options', () => {
class FakeParagraph extends React.Component {
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
render() {
return <p className="foo">{this.props.children}</p>
}
Expand Down
142 changes: 71 additions & 71 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ import * as React from 'react'
* Analogous to `node.type`. Please note that the values here may change at any time,
* so do not hard code against the value directly.
*/
export const RuleType = {
blockQuote: '0',
breakLine: '1',
breakThematic: '2',
codeBlock: '3',
codeFenced: '4',
codeInline: '5',
footnote: '6',
footnoteReference: '7',
gfmTask: '8',
heading: '9',
headingSetext: '10',
export 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',
/** only available if not `disableHTMLParsing` */
htmlBlock: '11',
htmlComment: '12',
htmlBlock = '11',
htmlComment = '12',
/** only available if not `disableHTMLParsing` */
htmlSelfClosing: '13',
image: '14',
link: '15',
htmlSelfClosing = '13',
image = '14',
link = '15',
/** emits a `link` 'node', does not render directly */
linkAngleBraceStyleDetector: '16',
linkAngleBraceStyleDetector = '16',
/** emits a `link` 'node', does not render directly */
linkBareUrlDetector: '17',
linkBareUrlDetector = '17',
/** emits a `link` 'node', does not render directly */
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',
} as const
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',
}

const enum Priority {
/**
Expand Down Expand Up @@ -768,7 +768,7 @@ function parserFor(
// there can be a single output function for all links,
// even if there are several rules to parse them.
if (parsed.type == null) {
parsed.type = ruleType as unknown as keyof typeof RuleType
parsed.type = ruleType as unknown as RuleType
}

result.push(parsed)
Expand Down Expand Up @@ -1925,130 +1925,130 @@ export namespace MarkdownToJSX {

export interface BlockQuoteNode {
children: MarkdownToJSX.ParserResult[]
type: (typeof RuleType)['blockQuote']
type: RuleType.blockQuote
}

export interface BreakLineNode {
type: (typeof RuleType)['breakLine']
type: RuleType.breakLine
}

export interface BreakThematicNode {
type: (typeof RuleType)['breakThematic']
type: RuleType.breakThematic
}

export interface CodeBlockNode {
type: (typeof RuleType)['codeBlock']
type: RuleType.codeBlock
attrs?: JSX.IntrinsicAttributes
lang?: string
text: string
}

export interface CodeFencedNode {
type: (typeof RuleType)['codeFenced']
type: RuleType.codeFenced
}

export interface CodeInlineNode {
type: (typeof RuleType)['codeInline']
type: RuleType.codeInline
text: string
}

export interface FootnoteNode {
type: (typeof RuleType)['footnote']
type: RuleType.footnote
}

export interface FootnoteReferenceNode {
type: (typeof RuleType)['footnoteReference']
type: RuleType.footnoteReference
target: string
text: string
}

export interface GFMTaskNode {
type: (typeof RuleType)['gfmTask']
type: RuleType.gfmTask
completed: boolean
}

export interface HeadingNode {
type: (typeof RuleType)['heading']
type: RuleType.heading
children: MarkdownToJSX.ParserResult[]
id: string
level: 1 | 2 | 3 | 4 | 5 | 6
}

export interface HeadingSetextNode {
type: (typeof RuleType)['headingSetext']
type: RuleType.headingSetext
}

export interface HTMLCommentNode {
type: (typeof RuleType)['htmlComment']
type: RuleType.htmlComment
}

export interface ImageNode {
type: (typeof RuleType)['image']
type: RuleType.image
alt?: string
target: string
title?: string
}

export interface LinkNode {
type: (typeof RuleType)['link']
type: RuleType.link
children: MarkdownToJSX.ParserResult[]
target: string
title?: string
}

export interface LinkAngleBraceNode {
type: (typeof RuleType)['linkAngleBraceStyleDetector']
type: RuleType.linkAngleBraceStyleDetector
}

export interface LinkBareURLNode {
type: (typeof RuleType)['linkBareUrlDetector']
type: RuleType.linkBareUrlDetector
}

export interface LinkMailtoNode {
type: (typeof RuleType)['linkMailtoDetector']
type: RuleType.linkMailtoDetector
}

export interface OrderedListNode {
type: (typeof RuleType)['orderedList']
type: RuleType.orderedList
items: MarkdownToJSX.ParserResult[][]
ordered: true
start?: number
}

export interface UnorderedListNode {
type: (typeof RuleType)['unorderedList']
type: RuleType.unorderedList
items: MarkdownToJSX.ParserResult[][]
ordered: false
}

export interface NewlineNode {
type: (typeof RuleType)['newlineCoalescer']
type: RuleType.newlineCoalescer
}

export interface ParagraphNode {
type: (typeof RuleType)['paragraph']
type: RuleType.paragraph
children: MarkdownToJSX.ParserResult[]
}

export interface ReferenceNode {
type: (typeof RuleType)['ref']
type: RuleType.ref
}

export interface ReferenceImageNode {
type: (typeof RuleType)['refImage']
type: RuleType.refImage
alt?: string
ref: string
}

export interface ReferenceLinkNode {
type: (typeof RuleType)['refLink']
type: RuleType.refLink
children: MarkdownToJSX.ParserResult[]
fallbackChildren: MarkdownToJSX.ParserResult[]
ref: string
}

export interface TableNode {
type: (typeof RuleType)['table']
type: RuleType.table
/**
* alignment for each table column
*/
Expand All @@ -2058,40 +2058,40 @@ export namespace MarkdownToJSX {
}

export interface TableSeparatorNode {
type: (typeof RuleType)['tableSeparator']
type: RuleType.tableSeparator
}

export interface TextNode {
type: (typeof RuleType)['text']
type: RuleType.text
text: string
}

export interface BoldTextNode {
type: (typeof RuleType)['textBolded']
type: RuleType.textBolded
children: MarkdownToJSX.ParserResult[]
}

export interface ItalicTextNode {
type: (typeof RuleType)['textEmphasized']
type: RuleType.textEmphasized
children: MarkdownToJSX.ParserResult[]
}

export interface EscapedTextNode {
type: (typeof RuleType)['textEscaped']
type: RuleType.textEscaped
}

export interface MarkedTextNode {
type: (typeof RuleType)['textMarked']
type: RuleType.textMarked
children: MarkdownToJSX.ParserResult[]
}

export interface StrikethroughTextNode {
type: (typeof RuleType)['textStrikethroughed']
type: RuleType.textStrikethroughed
children: MarkdownToJSX.ParserResult[]
}

export interface HTMLNode {
type: (typeof RuleType)['htmlBlock']
type: RuleType.htmlBlock
attrs: JSX.IntrinsicAttributes
children?: ReturnType<MarkdownToJSX.NestedParser> | undefined
noInnerParse: Boolean
Expand All @@ -2100,7 +2100,7 @@ export namespace MarkdownToJSX {
}

export interface HTMLSelfClosingNode {
type: (typeof RuleType)['htmlSelfClosing']
type: RuleType.htmlSelfClosing
attrs: JSX.IntrinsicAttributes
tag: string
}
Expand Down

0 comments on commit 7ec5872

Please sign in to comment.