feat: strip MDX imports#113
Open
Strokkur424 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In extended markdown syntax (MDX), you can have JS-style import statements at the top of the file. Currently, with
remove-markdown, these are included in the output, which makes post previews basically useless.This PR changes that by adding a regex that checks for import statements and removes these. The regex ensures that the import statement does not contain leading characters and ends in at least one newline (trailing newlines are removed so the content part starts instantly, as if the newline was never there). This is technically more restrictive than the real limitations of JS-style imports, but seemed to me like a respectable limitation.
The regex is kept very simple and does not check for exact import syntax; it primarily just checks for the
importkeyword and any combination of the valid characters.I've added the following test case:
It checks for a few common variants of import statements.
Let me know if there's anything missing or if I should restrict the regex further. Alternatively Allow edits by maintainers is enabled, so the PR can be edited to fix code smells.