Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update markdown-it-directive to v2.0.4 #6

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"prepare": "husky"
},
"dependencies": {
"markdown-it-directive": "2.0.2"
"markdown-it-directive": "2.0.4"
},
"devDependencies": {
"@diplodoc/lint": "^1.2.0",
Expand Down
12 changes: 2 additions & 10 deletions src/helpers/registrars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,10 @@ function buildInlineParams(args: DirectiveInlineHandlerArgs): InlineDirectivePar
endPos: args.directiveEnd,
};
if (args.attrs !== undefined) {
// @ts-expect-error types fixed in [email protected]
params.attrs = args.attrs;
}
if (args.dests !== undefined) {
params.dests = buildDests(
// @ts-expect-error types fixed in [email protected]
args.dests,
);
params.dests = buildDests(args.dests);
}
if (args.content !== undefined) {
params.content = {
Expand All @@ -226,14 +222,10 @@ function buildLeafBlockParams(args: DirectiveBlockHandlerArgs): LeafBlockDirecti
endLine: args.directiveEndLine,
};
if (args.attrs !== undefined) {
// @ts-expect-error types fixed in [email protected]
params.attrs = args.attrs;
}
if (args.dests !== undefined) {
params.dests = buildDests(
// @ts-expect-error fix in https://github.com/hilookas/markdown-it-directive/pull/8
args.dests,
);
params.dests = buildDests(args.dests);
}
if (args.inlineContent !== undefined) {
params.inlineContent = {
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export type {
*/
export const directiveParser = (): MarkdownIt.PluginSimple => {
return (md) => {
directivePlugin(
// @ts-expect-error – bad types in markdown-it-directive
md,
);
directivePlugin(md);

disableInlineDirectives(md);
};
Expand Down
6 changes: 2 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type MarkdownIt from 'markdown-it';
import type StateBlock from 'markdown-it/lib/rules_block/state_block';
import type StateInline from 'markdown-it/lib/rules_inline/state_inline';
import type {DirectiveAttrs, DirectiveDests as DirectiveDestsOrig} from 'markdown-it-directive';
import type {CONTAINER_KEY, LEAF_BLOCK_KEY} from './const';

export type {StateBlock, StateInline};

// TODO: re-export this types from markdown-it-directive after update to 2.0.3
export type DirectiveAttrs = Record<string, string>;
export type DirectiveDestsOrig = ['link' | 'string', string][];
export type {DirectiveAttrs, DirectiveDestsOrig};

export type DirectiveDests = {
link?: string;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/directive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Directive', () => {
expect(handler).toHaveBeenCalled();
});

it('should throw error when parsing something like inline directive and reference link', () => {
it('should not throw error when parsing something like inline directive and reference link', () => {
/*
Caught a bug that if there is something similar to an inline directive and a reference link,
it will be considered an inline directive and will fail during parsing
Expand All @@ -156,7 +156,7 @@ describe('Directive', () => {
} catch (err) {
// console.error(err);
}
expect(fn).toThrow("Cannot read properties of undefined (reading 'trim')");
expect(fn).not.toThrow();
});

it('should not throw error with disabled parsing of inline directives', () => {
Expand Down