-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related to unifiedjs/unified#53. Related to unifiedjs/unified#54. Related to unifiedjs/unified#56. Related to unifiedjs/unified#57. Related to unifiedjs/unified#58. Related to unifiedjs/unified#59. Related to unifiedjs/unified#60. Related to unifiedjs/unified#61. Related to unifiedjs/unified#62. Related to unifiedjs/unified#63. Related to unifiedjs/unified#64. Related to #426. Reviewed-by: Titus Wormer <tituswormer@gmail.com> Reviewed-by: Junyoung Choi <fluke8259@gmail.com> Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Co-authored-by: Junyoung Choi <fluke8259@gmail.com> Co-authored-by: Christian Murphy <christian.murphy.42@gmail.com>
- Loading branch information
Showing
16 changed files
with
300 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// TypeScript Version: 3.0 | ||
|
||
import {Node, Parent, Position} from 'unist' | ||
import {Parser, Attacher} from 'unified' | ||
|
||
declare class RemarkParser implements Parser { | ||
parse(): Node | ||
blockMethods: string[] | ||
inlineTokenizers: { | ||
[key: string]: remarkParse.Tokenizer | ||
} | ||
inlineMethods: string[] | ||
} | ||
|
||
declare namespace remarkParse { | ||
interface Parse extends Attacher<[Partial<RemarkParseOptions>]> { | ||
(options: Partial<RemarkParseOptions>): void | ||
Parser: typeof RemarkParser | ||
} | ||
|
||
type Parser = RemarkParser | ||
|
||
interface RemarkParseOptions { | ||
gfm: boolean | ||
commonmark: boolean | ||
footnotes: boolean | ||
blocks: string[] | ||
pedantic: boolean | ||
} | ||
|
||
interface Add { | ||
(node: Node, parent?: Parent): Node | ||
test(): Position | ||
reset(node: Node, parent?: Node): Node | ||
} | ||
|
||
type Eat = (value: string) => Add | ||
|
||
type Locator = (value: string, fromIndex: number) => number | ||
|
||
interface Tokenizer { | ||
(eat: Eat, value: string, silent: true): boolean | void | ||
(eat: Eat, value: string): Node | void | ||
locator?: Locator | ||
onlyAtStart?: boolean | ||
notInBlock?: boolean | ||
notInList?: boolean | ||
notInLink?: boolean | ||
} | ||
} | ||
declare const remarkParse: remarkParse.Parse | ||
|
||
export = remarkParse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import unified = require('unified') | ||
import * as Unist from 'unist' | ||
import remarkParse = require('remark-parse') | ||
|
||
const parseOptions = { | ||
gfm: true, | ||
pedantic: true | ||
} | ||
|
||
unified().use(remarkParse, parseOptions) | ||
|
||
const badParseOptions = { | ||
gfm: 'true' | ||
} | ||
|
||
// $ExpectError | ||
unified().use(remarkParse, badParseOptions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"remark-parse": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"callable-types": false, | ||
"max-line-length": false, | ||
"no-redundant-jsdoc": false, | ||
"no-void-expression": false, | ||
"only-arrow-functions": false, | ||
"semicolon": false, | ||
"unified-signatures": false, | ||
"whitespace": false, | ||
"interface-over-type-literal": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// TypeScript Version: 3.0 | ||
|
||
import {Attacher, Compiler, Processor} from 'unified' | ||
import {Node, Parent} from 'unist' | ||
|
||
declare class RemarkCompiler implements Compiler { | ||
compile(): string | ||
visitors: { | ||
[key: string]: remarkStringify.Visitor | ||
} | ||
} | ||
|
||
declare namespace remarkStringify { | ||
interface Stringify extends Attacher<[Partial<RemarkStringifyOptions>]> { | ||
Compiler: typeof RemarkCompiler | ||
(this: Processor, options?: Partial<RemarkStringifyOptions>): void | ||
} | ||
|
||
type Compiler = RemarkCompiler | ||
|
||
interface RemarkStringifyOptions { | ||
gfm: boolean | ||
commonmark: boolean | ||
entities: boolean | 'numbers' | 'escape' | ||
setext: boolean | ||
closeAtx: boolean | ||
looseTable: boolean | ||
spacedTable: boolean | ||
paddedTable: boolean | ||
stringLength: (s: string) => number | ||
fence: '~' | '`' | ||
fences: boolean | ||
bullet: '-' | '*' | '+' | ||
listItemIndent: 'tab' | '1' | 'mixed' | ||
incrementListMarker: boolean | ||
rule: '-' | '_' | '*' | ||
ruleRepetition: number | ||
ruleSpaces: boolean | ||
strong: '_' | '*' | ||
emphasis: '_' | '*' | ||
} | ||
|
||
type Visitor = (node: Node, parent?: Parent) => string | ||
} | ||
|
||
declare const remarkStringify: remarkStringify.Stringify | ||
|
||
export = remarkStringify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import remarkStringify = require('remark-stringify') | ||
import unified = require('unified') | ||
import {Node, Parent} from 'unist' | ||
|
||
const inferredStringifyOptions = { | ||
gfm: true, | ||
fences: true, | ||
incrementListMarker: false | ||
} | ||
|
||
unified().use(remarkStringify, inferredStringifyOptions) | ||
|
||
// These cannot be automatically inferred by TypeScript | ||
const nonInferredStringifyOptions: Partial< | ||
remarkStringify.RemarkStringifyOptions | ||
> = { | ||
fence: '~', | ||
bullet: '+', | ||
listItemIndent: 'tab', | ||
rule: '-', | ||
strong: '_', | ||
emphasis: '*' | ||
} | ||
|
||
unified().use(remarkStringify, nonInferredStringifyOptions) | ||
|
||
const badStringifyOptions = { | ||
gfm: 'true' | ||
} | ||
|
||
// $ExpectError | ||
unified().use(remarkStringify, badStringifyOptions) | ||
|
||
function gap(this: unified.Processor) { | ||
const Compiler = this.Compiler as typeof remarkStringify.Compiler | ||
const visitors = Compiler.prototype.visitors | ||
const original = visitors.heading | ||
|
||
visitors.heading = heading | ||
|
||
function heading(this: unified.Processor, node: Node, parent?: Parent) { | ||
// FIXME: remove need for explicit 'as' casting | ||
const headingNode = node as (Node & {depth: number}) | ||
return ( | ||
(headingNode.depth === 2 ? '\n' : '') + | ||
original.apply(this, [node, parent]) | ||
) | ||
} | ||
} | ||
|
||
const plugin: unified.Attacher = gap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"remark-stringify": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"callable-types": false, | ||
"max-line-length": false, | ||
"no-redundant-jsdoc": false, | ||
"no-void-expression": false, | ||
"only-arrow-functions": false, | ||
"semicolon": false, | ||
"unified-signatures": false, | ||
"whitespace": false, | ||
"interface-over-type-literal": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// TypeScript Version: 3.0 | ||
|
||
import unified = require('unified') | ||
import remarkParse = require('remark-parse') | ||
import remarkStringify = require('remark-stringify') | ||
|
||
type RemarkOptions = remarkParse.RemarkParseOptions & | ||
remarkStringify.RemarkStringifyOptions | ||
|
||
declare function remark< | ||
P extends Partial<RemarkOptions> = Partial<RemarkOptions> | ||
>(): unified.Processor<P> | ||
|
||
export = remark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import remark = require('remark') | ||
|
||
interface PluginOptions { | ||
example: boolean | ||
} | ||
|
||
const plugin = (options?: PluginOptions) => {} | ||
|
||
remark().use(plugin) | ||
remark().use(plugin, {example: true}) | ||
remark().use({settings: {commonmark: true}}) | ||
// $ExpectError | ||
remark().use({settings: {doesNotExist: true}}) | ||
// $ExpectError | ||
remark().use(plugin, {doesNotExist: 'true'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"remark": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"callable-types": false, | ||
"max-line-length": false, | ||
"no-redundant-jsdoc": false, | ||
"no-void-expression": false, | ||
"only-arrow-functions": false, | ||
"semicolon": false, | ||
"unified-signatures": false, | ||
"whitespace": false, | ||
"interface-over-type-literal": false, | ||
"no-unnecessary-generics": false | ||
} | ||
} |