mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
Create definitions for markdown-it-container (#16313)
This commit is contained in:
committed by
Mohamed Hegazy
parent
56ce2fe50d
commit
e5d4764dbc
+20
@@ -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);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user