diff --git a/types/markdown-to-jsx/index.d.ts b/types/markdown-to-jsx/index.d.ts new file mode 100644 index 0000000000..ac7a6fb8e9 --- /dev/null +++ b/types/markdown-to-jsx/index.d.ts @@ -0,0 +1,76 @@ +// Type definitions for markdown-to-jsx 6.9 +// Project: https://probablyup.github.io/markdown-to-jsx +// Definitions by: Elizabeth Craig +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; + +export default class Markdown extends React.Component { } + +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?:

( + type: React.SFC

| React.ComponentClass

| string, + props?: React.Attributes & P | null, + ...children: React.ReactNode[]) => React.ReactElement

; + + /** Custom function to generate an HTML id from headings. */ + slugify?: (text: string) => string; +} + +export function compiler(markdown: string, options?: MarkdownOptions): JSX.Element; diff --git a/types/markdown-to-jsx/markdown-to-jsx-tests.tsx b/types/markdown-to-jsx/markdown-to-jsx-tests.tsx new file mode 100644 index 0000000000..f34b18afc1 --- /dev/null +++ b/types/markdown-to-jsx/markdown-to-jsx-tests.tsx @@ -0,0 +1,62 @@ +import Markdown, { compiler } from 'markdown-to-jsx'; +import * as React from 'react'; +import { render } from 'react-dom'; + +render(# Hello world!, document.body); + +Hello there old chap!; +compiler('Hello there old chap!', { forceBlock: true }); + +# You got it babe!; + +const MyParagraph: React.FunctionComponent = ({ children, ...props }) => ( +

{children}
+); +render( + + # Hello world! + , + document.body +); + +render( + ( + type: React.FunctionComponent

| React.ComponentClass

| string, + props?: React.Attributes & P | null, + ...children: React.ReactNode[]) => ( +

+ {React.createElement(type, props, children)} +
+ ) + }} + />, + document.body +); + + str }}># 中文; diff --git a/types/markdown-to-jsx/tsconfig.json b/types/markdown-to-jsx/tsconfig.json new file mode 100644 index 0000000000..8544a5755a --- /dev/null +++ b/types/markdown-to-jsx/tsconfig.json @@ -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" + ] +} diff --git a/types/markdown-to-jsx/tslint.json b/types/markdown-to-jsx/tslint.json new file mode 100644 index 0000000000..a87684c220 --- /dev/null +++ b/types/markdown-to-jsx/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-null-undefined-union": false + } +}