mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Add markdown-to-jsx typings
This commit is contained in:
76
types/markdown-to-jsx/index.d.ts
vendored
Normal file
76
types/markdown-to-jsx/index.d.ts
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
// Type definitions for markdown-to-jsx 6.9
|
||||
// Project: https://probablyup.github.io/markdown-to-jsx
|
||||
// Definitions by: Elizabeth Craig <https://github.com/ecraig12345>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export default class Markdown extends React.Component<MarkdownProps> { }
|
||||
|
||||
export interface MarkdownProps {
|
||||
options?: MarkdownOptions;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export type ComponentOverride = string | React.ComponentClass | React.SFC | {
|
||||
component: string | React.ComponentClass | React.SFC;
|
||||
props?: any;
|
||||
};
|
||||
|
||||
export interface MarkdownOptions {
|
||||
/** Force all input strings to use block layout. */
|
||||
forceBlock?: boolean;
|
||||
|
||||
/** Force all input strings to use inline layout. */
|
||||
forceInline?: boolean;
|
||||
|
||||
/** Override representation of any HTML tag or custom component. */
|
||||
overrides?: {
|
||||
// As of 6.9.3, these tags are the only ones automatically generated by markdown-to-jsx.
|
||||
a?: ComponentOverride;
|
||||
br?: ComponentOverride;
|
||||
button?: ComponentOverride;
|
||||
code?: ComponentOverride;
|
||||
del?: ComponentOverride;
|
||||
div?: ComponentOverride;
|
||||
em?: ComponentOverride;
|
||||
footer?: ComponentOverride;
|
||||
input?: ComponentOverride;
|
||||
h1?: ComponentOverride;
|
||||
h2?: ComponentOverride;
|
||||
h3?: ComponentOverride;
|
||||
h4?: ComponentOverride;
|
||||
h5?: ComponentOverride;
|
||||
h6?: ComponentOverride;
|
||||
hr?: ComponentOverride;
|
||||
img?: ComponentOverride;
|
||||
ol?: ComponentOverride;
|
||||
p?: ComponentOverride;
|
||||
pre?: ComponentOverride;
|
||||
span?: ComponentOverride;
|
||||
strong?: ComponentOverride;
|
||||
sub?: ComponentOverride;
|
||||
sup?: ComponentOverride;
|
||||
table?: ComponentOverride;
|
||||
tbody?: ComponentOverride;
|
||||
td?: ComponentOverride;
|
||||
th?: ComponentOverride;
|
||||
thead?: ComponentOverride;
|
||||
tr?: ComponentOverride;
|
||||
ul?: ComponentOverride;
|
||||
/** In addition to HTML tags, you can specify a custom component name which can be used within markdown text. */
|
||||
[key: string]: ComponentOverride | undefined;
|
||||
};
|
||||
|
||||
/** Custom React.createElement behavior. */
|
||||
createElement?: <P extends {}>(
|
||||
type: React.SFC<P> | React.ComponentClass<P> | string,
|
||||
props?: React.Attributes & P | null,
|
||||
...children: React.ReactNode[]) => React.ReactElement<P>;
|
||||
|
||||
/** Custom function to generate an HTML id from headings. */
|
||||
slugify?: (text: string) => string;
|
||||
}
|
||||
|
||||
export function compiler(markdown: string, options?: MarkdownOptions): JSX.Element;
|
||||
62
types/markdown-to-jsx/markdown-to-jsx-tests.tsx
Normal file
62
types/markdown-to-jsx/markdown-to-jsx-tests.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import Markdown, { compiler } from 'markdown-to-jsx';
|
||||
import * as React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
|
||||
render(<Markdown># Hello world!</Markdown>, document.body);
|
||||
|
||||
<Markdown options={{ forceBlock: true }}>Hello there old chap!</Markdown>;
|
||||
compiler('Hello there old chap!', { forceBlock: true });
|
||||
|
||||
<Markdown options={{ forceInline: true }}># You got it babe!</Markdown>;
|
||||
|
||||
const MyParagraph: React.FunctionComponent = ({ children, ...props }) => (
|
||||
<div {...props}>{children}</div>
|
||||
);
|
||||
render(
|
||||
<Markdown
|
||||
options={{
|
||||
overrides: {
|
||||
h1: {
|
||||
component: MyParagraph,
|
||||
props: {
|
||||
className: 'foo',
|
||||
},
|
||||
},
|
||||
h2: {
|
||||
component: 'div'
|
||||
},
|
||||
h3: {
|
||||
component: 'span',
|
||||
props: {
|
||||
className: 'foo'
|
||||
}
|
||||
},
|
||||
p: MyParagraph,
|
||||
h4: 'h3',
|
||||
MyParagraph
|
||||
},
|
||||
}}
|
||||
>
|
||||
# Hello world!
|
||||
</Markdown>,
|
||||
document.body
|
||||
);
|
||||
|
||||
render(
|
||||
<Markdown
|
||||
children="# Hello world"
|
||||
options={{
|
||||
createElement: <P extends {}>(
|
||||
type: React.FunctionComponent<P> | React.ComponentClass<P> | string,
|
||||
props?: React.Attributes & P | null,
|
||||
...children: React.ReactNode[]) => (
|
||||
<div className="parent">
|
||||
{React.createElement(type, props, children)}
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
/>,
|
||||
document.body
|
||||
);
|
||||
|
||||
<Markdown options={{ slugify: str => str }}># 中文</Markdown>;
|
||||
20
types/markdown-to-jsx/tsconfig.json
Normal file
20
types/markdown-to-jsx/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"markdown-to-jsx-tests.tsx"
|
||||
]
|
||||
}
|
||||
6
types/markdown-to-jsx/tslint.json
Normal file
6
types/markdown-to-jsx/tslint.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-null-undefined-union": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user