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

feat: enable inline directives by default #9

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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ All of parameters groups – `[]`, `()`, `{}` – are optional, but their order
- `()` – used for something like required identifier (id, url, etc.);
- `{}` – used to pass optional named arguments / attributes / `key=value` pairs.

> Note: inline directives disabled by default. You can enable them using `enableInlineDirectives()` helper.

## Helpers

### Enable or disable some of directive types
Expand Down
12 changes: 0 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type MarkdownIt from 'markdown-it';

import directivePlugin from 'markdown-it-directive';

import {disableInlineDirectives} from './helpers';

export {
enableBlockDirectives,
enableInlineDirectives,
Expand Down Expand Up @@ -33,18 +31,8 @@ export type {
InlineDirectiveHandler,
} from './types';

// eslint-disable-next-line valid-jsdoc
/**
* Inline directives are disabled by default.
*
* They will be enabled after this error is fixed: https://github.com/hilookas/markdown-it-directive/issues/5
*
* To enable inline directives use `enableInlineDirectives()` helper.
*/
export const directiveParser = (): MarkdownIt.PluginSimple => {
return (md) => {
directivePlugin(md);

disableInlineDirectives(md);
};
};
7 changes: 3 additions & 4 deletions tests/src/directive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
directiveParser,
disableBlockDirectives,
disableInlineDirectives,
enableInlineDirectives,
registerContainerDirective,
registerInlineDirective,
registerLeafBlockDirective,
Expand All @@ -20,14 +19,14 @@ import {

const html = (text: string, {plugins}: {plugins?: MarkdownIt.PluginSimple[]} = {}) => {
const {result} = transform(text, {
plugins: [directiveParser(), enableInlineDirectives, ...(plugins || [])],
plugins: [directiveParser(), ...(plugins || [])],
});

return result.html;
};

describe('Directive', () => {
it('should not parse inline directive by default', () => {
it.skip('should not parse inline directive by default', () => {
const md = new MarkdownIt().use(directiveParser());
const inlineHandler = jest.fn(() => false);
const leafHandler = jest.fn(() => false);
Expand Down Expand Up @@ -518,7 +517,7 @@ describe('Directive', () => {

describe('tokenizeInlineContent', () => {
it('should parse content in inline directive', () => {
const md = new MarkdownIt().use(directiveParser()).use(enableInlineDirectives);
const md = new MarkdownIt().use(directiveParser());
registerInlineDirective(md, 'inl', (state, params) => {
if (!params.content) {
return false;
Expand Down