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

How-to use markdownItPlugins in YAML? #271

Closed
vorburger opened this issue Jan 29, 2024 · 5 comments
Closed

How-to use markdownItPlugins in YAML? #271

vorburger opened this issue Jan 29, 2024 · 5 comments
Labels
question Further information is requested

Comments

@vorburger
Copy link

I use this great project (Thank You!) on https://github.com/enola-dev/enola,

via https://github.com/DavidAnson/vscode-markdownlint and (more importantly) through https://github.com/DavidAnson/markdownlint-cli2#pre-commit for https://pre-commit.com.

I currently use the https://github.com/DavidAnson/markdownlint-cli2#markdownlintyaml-or-markdownlintyml way to configure it, with a .markdownlint.yaml file, which seems to used both by Pre-Commit and VSC - that's great! (And seems better than e.g. configuring only VSC via https://github.com/DavidAnson/vscode-markdownlint#markdownlintcustomrules.)

DavidAnson/markdownlint#121 made me discover https://github.com/theoludwig/markdownlint-rule-relative-links from @theoludwig and I would like to use it - but I can't seem to figure out how to configure plugins in YAML. I've tried adding this, for an "array of array" (with no options):

markdownItPlugins:
  - - markdownlint-rule-relative-links

but it looks like that's just ignored? If I change a link to break it, git add . and then run pre-commit run --all-files it doesn't flag it.

https://github.com/DavidAnson/markdownlint/blob/main/README.md#optionsmarkdownitplugins mentions require but I suspect that's not required in YAML?

@DavidAnson @theoludwig @igor-tsiglyar perhaps you have a suggestion? (I can raise a PR to clarify the doc, once I got it working.)

@DavidAnson DavidAnson transferred this issue from DavidAnson/markdownlint Jan 29, 2024
@DavidAnson
Copy link
Owner

Your syntax seems correct. Here is an example with everything set: https://github.com/DavidAnson/markdownlint-cli2/blob/main/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml

Why do you think it isn't working?

@DavidAnson DavidAnson added the question Further information is requested label Jan 29, 2024
@DavidAnson
Copy link
Owner

Oh, wait, it looks like you may be confusing the two types of configuration files. The fourth bullet point here explains that: https://github.com/DavidAnson/markdownlint-cli2#configuration

@electriquo
Copy link

electriquo commented Jan 29, 2024

@DavidAnson I am using only .markdownlint-cli2.yaml and tweaked .pre-commit-config as follows

- repo: https://github.com/DavidAnson/markdownlint-cli2
  rev: v0.12.1
  hooks:
    - id: markdownlint-cli2
      additional_dependencies:
        - markdownlint-rule-relative-links

and I am getting the error

TypeError: plugin.apply is not a function
    at MarkdownIt.use (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdown-it/dist/index.cjs.js:5432:10)
    at lintInput (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:908:8)
    at markdownlint (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:1003:10)
    at node:internal/util:430:21
    at new Promise (<anonymous>)
    at markdownlint (node:internal/util:416:12)
    at markdownlintPromise (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:1016:10)
    at lintFiles (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:783:16)
    at main (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:1011:29)
    at async /Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:1053:26

Is the error related to markdownlint-cli2?

Since you have mentioned node version

markdownlint-cli2/README.md

Lines 404 to 405 in 82c791e

> Depending on the environment that workflow runs in, it may be necessary to
> [override the version of Node.js used by pre-commit][pre-commit-version].

I have NodeJS already installed https://github.com/pre-commit/pre-commit/blob/73848383f2f4d0fc97b2a769afb6da35610672a8/pre_commit/languages/node.py#L31-L32

$ node --version
v20.11.0

Which is compatible with https://github.com/theoludwig/markdownlint-rule-relative-links/blob/146f904866e30a14faafdf77af1246e54b50792d/README.md?plain=1#L69

@DavidAnson
Copy link
Owner

@vorburger, markdownlint-rule-relative-links is a custom rule, not a markdown-it plugin. It can be configured like so in .markdownlint-cli2.yaml:

customRules:
  - markdownlint-rule-relative-links

You link to a .markdownlint.yaml file, so also make sure you're not editing that file per my earlier comment.

@electriquo, you don't show the configuration you're using, so I can't tell what's going on, but the error above suggests you're making the same mistake.

@electriquo
Copy link

@DavidAnson You're awesome. After your explanation it works for me. Thank you.

@DavidAnson DavidAnson closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants