Create definitions for markdown-it-container (#16313)

This commit is contained in:
Vyacheslav
2017-05-04 09:54:52 -07:00
committed by Mohamed Hegazy
parent 56ce2fe50d
commit e5d4764dbc
4 changed files with 75 additions and 0 deletions
+20
View File
@@ -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 <https://github.com/hronex>
// 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;
@@ -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 (
'<div class="markdown__spoiler">\n' +
'<div class="markdown__spoiler-title" onclick="' + onClick + '">\n' +
md.utils.escapeHtml(match && match[1] || '') + '\n' +
'</div>\n' +
'<div class="markdown__spoiler-content">\n'
);
} else {
return '</div></div>\n';
}
}
});
const src = `:::spoiler This Is Spoiler Title
Here is spoiler content.
:::`;
md.render(src);
+22
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }