From e5d4764dbc36731c5281308a396c1cc977ab352b Mon Sep 17 00:00:00 2001 From: Vyacheslav Date: Thu, 4 May 2017 19:54:52 +0300 Subject: [PATCH] Create definitions for markdown-it-container (#16313) --- types/markdown-it-container/index.d.ts | 20 ++++++++++++ .../markdown-it-container-tests.ts | 32 +++++++++++++++++++ types/markdown-it-container/tsconfig.json | 22 +++++++++++++ types/markdown-it-container/tslint.json | 1 + 4 files changed, 75 insertions(+) create mode 100644 types/markdown-it-container/index.d.ts create mode 100644 types/markdown-it-container/markdown-it-container-tests.ts create mode 100644 types/markdown-it-container/tsconfig.json create mode 100644 types/markdown-it-container/tslint.json diff --git a/types/markdown-it-container/index.d.ts b/types/markdown-it-container/index.d.ts new file mode 100644 index 0000000000..f2d3722a3d --- /dev/null +++ b/types/markdown-it-container/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for MarkdownItContainer (markdown-it-container) 2.0 +// Project: https://github.com/markdown-it/markdown-it-container +// Definitions by: Vyacheslav Demot +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import { MarkdownIt, Token, Renderer } from 'markdown-it'; + +declare namespace markdownItContainer { + interface ContainerOpts { + marker?: string; + validate?(params: string): boolean; + render?(tokens: Token[], index: number, options: any, env: any, self: Renderer): void; + } + + function container_plugin(md: MarkdownIt, name: string, opts: ContainerOpts): void; +} + +declare var MarkdownItContainer: typeof markdownItContainer.container_plugin; +export = MarkdownItContainer; diff --git a/types/markdown-it-container/markdown-it-container-tests.ts b/types/markdown-it-container/markdown-it-container-tests.ts new file mode 100644 index 0000000000..f3ef2dbba1 --- /dev/null +++ b/types/markdown-it-container/markdown-it-container-tests.ts @@ -0,0 +1,32 @@ +import * as MarkdownIt from "markdown-it"; +import MarkdownItContainer = require("markdown-it-container"); + +const md = new MarkdownIt(); + +md.use(MarkdownItContainer, 'spoiler', { + validate: (params: any) => params.trim().match(/^spoiler\s+(.*)$/), + render: (tokens: MarkdownIt.Token[], index: number) => { + const match = tokens[index].info.trim().match(/^spoiler\s+(.*)$/); + const onClick = + "this.parentNode.classList.toggle('_expanded');" + + "event.preventDefault();"; + + if (tokens[index].nesting === 1) { + return ( + '
\n' + + '
\n' + + md.utils.escapeHtml(match && match[1] || '') + '\n' + + '
\n' + + '
\n' + ); + } else { + return '
\n'; + } + } +}); + +const src = `:::spoiler This Is Spoiler Title +Here is spoiler content. +:::`; + +md.render(src); diff --git a/types/markdown-it-container/tsconfig.json b/types/markdown-it-container/tsconfig.json new file mode 100644 index 0000000000..270b4284f0 --- /dev/null +++ b/types/markdown-it-container/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "markdown-it-container-tests.ts" + ] +} \ No newline at end of file diff --git a/types/markdown-it-container/tslint.json b/types/markdown-it-container/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/markdown-it-container/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }