mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[showdown] fix and reorder definitions, add and fix docs (#35104)
* docs(ShowdownOptions): add and fix
* fix(ShowdownOptions): add missing props
* `encodeEmails`
* `rawPrefixHeaderId `
* `rawHeaderId`
* fix(ShowdownOptions): Mark `excludeTrailingPunctuationFromURLs` as deprecated
It now default behavior:
d3ebff7ef0
* chore(Converter): order the method by the code order
https://github.com/showdownjs/showdown/blob/master/src/converter.js
* fix(Converter): add missing method `getFlavor`
* feat: add `Flavor` type for flavor names
* docs(Converter): fix and add
* chore(Showdown): order the mthods by the code order
https://github.com/showdownjs/showdown/blob/master/src/showdown.js
* fix(Showdown): Remove duplicate method definitions
* `getOption`
* `getOptions`
* `getDefaultOptions`
* `extension`
* `resetExtensions`
* fix(Showdown): add missing methods
* `getFlavor`
* `getFlavorOptions`
* `subParser`
* `validateExtension`
* fix(Showdown): fix incorrect definitions and order
* `setOption` - fix incorrect returns signature
* `getDefaultOptions` - fix incorrect args and returns signature
* `extension` - fix incorrect args and returns signature
* `ShowdownOptions` - support for custom options.
* `ShowdownOptionsSchema` - new interface to describe showdown options schema(`getDefaultOptions` method)
* `ShowdownExtensions` - new interface to describe showdown extensions store.
* `SubParser` - new type to describe showdown SubParser (`subParser` method)
* docs(Showdown): fix and add
* fix(ConverterOptions): incorrect property type of `extensions`
* fix: incorrect arg (`extension`) type of several method signatures
* test: fix and add
* fix(ShowdownExtension): add missing support of event listener
* add missing property 'listeners' type `Extension` (for listener extension and mixing)
* add new interface to describe showdown event listener function.
* fix(Converter): add missing `listen` method
This commit is contained in:
parent
d116b4da12
commit
498c398948
946
types/showdown/index.d.ts
vendored
946
types/showdown/index.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -9,18 +9,54 @@ var exampleMarkdown = '#hello, markdown',
|
||||
exampleHTML = '<h1>hello, markdown</h1>',
|
||||
converter = new showdown.Converter();
|
||||
|
||||
var myExt: showdown.ShowdownExtension = { type: 'output', filter: (text, converter) => { return text.replace('#', '*') } };
|
||||
var markdownToShowdownExt = {
|
||||
type: 'lang',
|
||||
regex: /markdown/g,
|
||||
replace: 'showdown'
|
||||
};
|
||||
var commaExt: showdown.FilterExtension = {type: 'output', filter: text => text.replace(',', '')};
|
||||
var myExt: showdown.ShowdownExtension = { type: 'lang', filter: (text, converter) => { return text.replace('#', '*') } };
|
||||
var someExtArray: showdown.ShowdownExtension[] = [markdownToShowdownExt, commaExt];
|
||||
var listenToCodeBlocksExt = {
|
||||
type: 'listener',
|
||||
listeners: {
|
||||
"codeBlocks.before": (evtName: string) => {
|
||||
console.log(evtName);
|
||||
},
|
||||
"codeBlocks.after": (evtName: string, text: string) => {
|
||||
console.log(evtName);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
};
|
||||
var combinedExt = {
|
||||
type: 'lang',
|
||||
regex: /\s+/g,
|
||||
replace: ' ',
|
||||
listeners: {'paragraphs.after': console.log}
|
||||
};
|
||||
|
||||
showdown.extension('my-ext', myExt);
|
||||
showdown.extension('listen-ext', listenToCodeBlocksExt);
|
||||
showdown.extension('combinedExt', () => [combinedExt]);
|
||||
|
||||
var preloadedExtensions = [ 'my-ext' ],
|
||||
extensionsConverter = new showdown.Converter({ extensions: preloadedExtensions });
|
||||
|
||||
var preloadedMultipleExtensions = [
|
||||
'my-ext',
|
||||
{type: 'lang', filter: (text: string) => text.replace('h', 'H')},
|
||||
() => [markdownToShowdownExt],
|
||||
() => commaExt
|
||||
],
|
||||
multipleExtensionsConverter = new showdown.Converter({ extensions: preloadedMultipleExtensions });
|
||||
|
||||
var configuredConverter = new showdown.Converter();
|
||||
configuredConverter.addExtension({type: 'output', filter: (text, converter)=>{return text.replace('#', '*')}}, 'myext');
|
||||
configuredConverter.addExtension({type: 'output', filter(text: string){ return text.replace(' ', '_')} }, 'myext');
|
||||
|
||||
configuredConverter.addExtension([
|
||||
{type: 'output', filter: (text, converter)=>{return text.replace('#', '*')}},
|
||||
{type: 'output', filter: (text, converter)=>{return text.replace('#', '*')}}
|
||||
{type: 'lang', filter: (text, converter)=>{return text.replace('#', '*')}},
|
||||
{type: 'output', filter: (text, converter)=>{return text.replace('p', 'span')}}
|
||||
], 'myext');
|
||||
|
||||
console.log(showdown.helper);
|
||||
@ -31,13 +67,24 @@ console.log(converter.makeHtml(exampleMarkdown));
|
||||
console.log(extensionsConverter.makeHtml(exampleMarkdown));
|
||||
// should log '<p>*hello, markdown</p>'
|
||||
|
||||
console.log(multipleExtensionsConverter.makeHtml(exampleMarkdown));
|
||||
// should log '<p>*Hello showdown</p>'
|
||||
|
||||
console.log(configuredConverter.makeHtml(exampleMarkdown));
|
||||
// should log '<p>*hello, markdown</p>'
|
||||
// should log '<span>*hello,_markdown</p>'
|
||||
|
||||
|
||||
console.log(converter.makeMarkdown(exampleHTML));
|
||||
// should log '#hello, markdown'
|
||||
|
||||
configuredConverter.useExtension('listen-ext');
|
||||
configuredConverter.addExtension(commaExt);
|
||||
configuredConverter.addExtension([combinedExt]);
|
||||
configuredConverter.addExtension(() => markdownToShowdownExt);
|
||||
configuredConverter.removeExtension(combinedExt);
|
||||
configuredConverter.addExtension(() => [listenToCodeBlocksExt, combinedExt]);
|
||||
configuredConverter.listen('unescapeSpecialChars.after', (evtName, text) => `"${ text }"`);
|
||||
|
||||
showdown.extension('myExt', function () {
|
||||
var matches: string[] = [];
|
||||
return [
|
||||
@ -64,3 +111,26 @@ showdown.extension('myExt', function () {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
showdown.extension('myExt');
|
||||
showdown.removeExtension('myExt');
|
||||
showdown.extension('myExt', someExtArray);
|
||||
showdown.resetExtensions()
|
||||
showdown.extension('commaExt', () => commaExt)
|
||||
|
||||
showdown.validateExtension(markdownToShowdownExt);
|
||||
showdown.validateExtension([markdownToShowdownExt, markdownToShowdownExt])
|
||||
|
||||
showdown.setOption('noHeaderId', true);
|
||||
showdown.setOption('foo', 'bar'); // custom option
|
||||
|
||||
converter.setOption('tables', true);
|
||||
converter.setOption('color', 'red'); // custom option
|
||||
|
||||
showdown.setFlavor('github');
|
||||
console.log(showdown.getFlavor());
|
||||
// should log 'github'
|
||||
|
||||
converter.setFlavor('ghost');
|
||||
console.log(converter.getFlavor());
|
||||
// should log 'ghost'
|
||||
Loading…
Reference in New Issue
Block a user