Skip to content

Commit 3e62842

Browse files
authored
🔧 MAINTAIN: Create module exports for internal classes (#11)
Allows creation of Directives and Roles externally. This pushes the exports down into the various folders and exposes some classes to external packages. This is needed for other packages to create new roles/directives without knowing the internal structure of the library.
1 parent eac2cb6 commit 3e62842

File tree

7 files changed

+60
-28
lines changed

7 files changed

+60
-28
lines changed

src/directives/admonitions.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -62,46 +62,47 @@ class BaseAdmonition extends Directive {
6262
}
6363
}
6464

65-
class Admonition extends BaseAdmonition {
65+
export class Admonition extends BaseAdmonition {
6666
public required_arguments = 1
6767
}
6868

69-
class Attention extends BaseAdmonition {
69+
export class Attention extends BaseAdmonition {
7070
public title = "Attention"
7171
}
7272

73-
class Caution extends BaseAdmonition {
73+
export class Caution extends BaseAdmonition {
7474
public title = "Caution"
7575
}
7676

77-
class Danger extends BaseAdmonition {
77+
export class Danger extends BaseAdmonition {
7878
public title = "Danger"
7979
}
8080

81-
class Error extends BaseAdmonition {
81+
export class Error extends BaseAdmonition {
8282
public title = "Error"
8383
}
8484

85-
class Important extends BaseAdmonition {
85+
export class Important extends BaseAdmonition {
8686
public title = "Important"
8787
}
8888

89-
class Hint extends BaseAdmonition {
89+
export class Hint extends BaseAdmonition {
9090
public title = "Hint"
9191
}
92-
class Note extends BaseAdmonition {
92+
93+
export class Note extends BaseAdmonition {
9394
public title = "Note"
9495
}
9596

96-
class SeeAlso extends BaseAdmonition {
97+
export class SeeAlso extends BaseAdmonition {
9798
public title = "See Also"
9899
}
99100

100-
class Tip extends BaseAdmonition {
101+
export class Tip extends BaseAdmonition {
101102
public title = "Tip"
102103
}
103104

104-
class Warning extends BaseAdmonition {
105+
export class Warning extends BaseAdmonition {
105106
public title = "Warning"
106107
}
107108

src/directives/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export { Directive } from "./main"
2+
export { default as directivePlugin } from "./plugin"
3+
export type { IOptions as IDirectiveOptions } from "./types"
4+
5+
export { admonitions } from "./admonitions"
6+
export { code } from "./code"
7+
export { images } from "./images"
8+
export { tables } from "./tables"
9+
export { math } from "./math"
10+
11+
import { admonitions } from "./admonitions"
12+
import { code } from "./code"
13+
import { images } from "./images"
14+
import { tables } from "./tables"
15+
import { math } from "./math"
16+
17+
export const directivesDefault = {
18+
...admonitions,
19+
...images,
20+
...code,
21+
...tables,
22+
...math
23+
}

src/directives/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IOptions } from "./types"
55

66
export default function directivePlugin(md: MarkdownIt, options: IOptions): void {
77
let after = options.directivesAfter || "block"
8-
if (options.replaceFences) {
8+
if (options.replaceFences ?? true) {
99
md.core.ruler.after(after, "fence_to_directive", replaceFences)
1010
after = "fence_to_directive"
1111
}

src/index.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import type MarkdownIt from "markdown-it/lib"
2-
import { admonitions } from "./directives/admonitions"
3-
import { code } from "./directives/code"
4-
import { images } from "./directives/images"
5-
import directivePlugin from "./directives/plugin"
6-
import type { IOptions as IDirectiveOptions } from "./directives/types"
7-
import { tables } from "./directives/tables"
8-
import { roles } from "./roles/main"
9-
import { html } from "./roles/html"
10-
import rolePlugin from "./roles/plugin"
11-
import type { IOptions as IRoleOptions } from "./roles/types"
12-
import { math as mathRole } from "./roles/math"
13-
import { math as mathDirective } from "./directives/math"
2+
import { rolesDefault, Role, rolePlugin, IRoleOptions } from "./roles"
3+
import {
4+
directivesDefault,
5+
Directive,
6+
directivePlugin,
7+
IDirectiveOptions
8+
} from "./directives"
9+
10+
export { rolesDefault, rolePlugin, Role }
11+
export { directivesDefault, directivePlugin, Directive }
1412

1513
/** Allowed options for docutils plugin */
1614
export interface IOptions extends IDirectiveOptions, IRoleOptions {
@@ -23,8 +21,8 @@ const OptionDefaults: IOptions = {
2321
replaceFences: true,
2422
rolesAfter: "inline",
2523
directivesAfter: "block",
26-
directives: { ...admonitions, ...images, ...code, ...tables, ...mathDirective },
27-
roles: { ...roles, ...html, ...mathRole }
24+
directives: directivesDefault,
25+
roles: rolesDefault
2826
}
2927

3028
/**

src/roles/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export { Role, main } from "./main"
2+
export { default as rolePlugin } from "./plugin"
3+
export type { IOptions as IRoleOptions } from "./types"
4+
export { math } from "./math"
5+
6+
import { main } from "./main"
7+
import { math } from "./math"
8+
import { html } from "./html"
9+
10+
export const rolesDefault = { ...main, ...html, ...math }

src/roles/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export class RawRole extends Role {
3535
}
3636
}
3737

38-
export const roles = {
38+
export const main = {
3939
raw: RawRole
4040
}

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
4545

4646
/* Module Resolution Options */
47-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
47+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
4848
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
4949
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
5050
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */

0 commit comments

Comments
 (0)