pawamoy / mkdocs-spellcheck

A spell checker plugin for MkDocs.
https://pawamoy.github.io/mkdocs-spellcheck/
ISC License
15 stars 3 forks source link

feature: Ability to skip files based on globs or regex #20

Closed nfelt14 closed 2 months ago

nfelt14 commented 2 months ago

Is your feature request related to a problem? Please describe.

I have a lot of auto-generated API documentation files that contain lots of words that get flagged as spelling errors, but really should be ignored.

Describe the solution you'd like

I would like to be able to specify a glob or regex to ignore groups of files when spellchecking.

Describe alternatives you've considered

The only workaround is to list each and every file in the skip_files option list, but I am dealing with 600+ files that may need to be ignored.

pawamoy commented 2 months ago

Hey @nfelt14, thanks for the request :slightly_smiling_face:

I agree that it would be nice to be able to ignore files based on globs on regex. Would you like to submit a PR? If you want to go with globs, which I'd prefer, here's how I did it in another project:

    def _expand_inputs(self, inputs: list[str], page_uris: list[str]) -> list[str]:
        expanded: list[str] = []
        for input_file in inputs:
            if "*" in input_file:
                expanded.extend(fnmatch.filter(page_uris, input_file))
            else:
                expanded.append(input_file)
        return expanded

    def on_files(self, files: Files, *, config: MkDocsConfig) -> Files | None:  # noqa: ARG002
        for manpage in self.config.pages:
            manpage["inputs"] = self._expand_inputs(manpage["inputs"], page_uris=list(files.src_uris.keys()))
        return files

This code should be updated to fit mkdocs-spellcheck configuration of course :slightly_smiling_face:

The advantage of this approach is that we don't read the disk, and rather use the file objects collected by MkDocs, therefore supporting dynamically generated files that don't even exist in the docs folder.

nfelt14 commented 2 months ago

If I can find the time to work on it, I will let you know.

nfelt14 commented 2 months ago

@pawamoy I was able to get a PR up for this.

nfelt14 commented 2 months ago

@pawamoy, any idea when a new release with this feature will be available?

pawamoy commented 2 months ago

Later today 👍

pawamoy commented 2 months ago

v1.1.0 released :slightly_smiling_face: