Skip to content

Commit a997cf1

Browse files
committed
Refactor types to use ConstructNameMap interface
1 parent c012b9a commit a997cf1

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Diff for: complex-types.d.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,44 @@ import type {Literal} from 'mdast'
33
declare module 'mdast-util-from-markdown' {
44
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
55
interface CompileData {
6-
// Register a new field.
6+
/**
7+
* Whether we’re in math (flow).
8+
*/
79
mathFlowInside?: boolean | undefined
810
}
911
}
1012

13+
declare module 'mdast-util-to-markdown' {
14+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
15+
interface ConstructNameMap {
16+
/**
17+
* Math (flow).
18+
*
19+
* ```markdown
20+
* > | $$
21+
* ^^
22+
* > | a
23+
* ^
24+
* > | $$
25+
* ^^
26+
* ```
27+
*/
28+
mathFlow: 'mathFlow'
29+
30+
/**
31+
* Math (flow) meta flag.
32+
*
33+
* ```markdown
34+
* > | $$a
35+
* ^
36+
* | b
37+
* | $$
38+
* ```
39+
*/
40+
mathFlowMeta: 'mathFlowMeta'
41+
}
42+
}
43+
1144
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1245
export interface Math extends Literal {
1346
type: 'math'

Diff for: index.js

-5
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,8 @@ export function mathToMarkdown(options = {}) {
158158

159159
return {
160160
unsafe: [
161-
// @ts-expect-error: To do: use context map.
162161
{character: '\r', inConstruct: ['mathFlowMeta']},
163-
// @ts-expect-error: To do: use context map.
164162
{character: '\r', inConstruct: ['mathFlowMeta']},
165-
// @ts-expect-error: To do: use context map.
166163
single
167164
? {character: '$', inConstruct: ['mathFlowMeta', 'phrasing']}
168165
: {
@@ -182,13 +179,11 @@ export function mathToMarkdown(options = {}) {
182179
function math(node, _, context, safeOptions) {
183180
const raw = node.value || ''
184181
const sequence = '$'.repeat(Math.max(longestStreak(raw, '$') + 1, 2))
185-
// @ts-expect-error: To do: use context map.
186182
const exit = context.enter('mathFlow')
187183
const tracker = track(safeOptions)
188184
let value = tracker.move(sequence)
189185

190186
if (node.meta) {
191-
// @ts-expect-error: To do: use context map.
192187
const subexit = context.enter('mathFlowMeta')
193188
value += tracker.move(
194189
safe(context, node.meta, {

0 commit comments

Comments
 (0)