-
-
Notifications
You must be signed in to change notification settings - Fork 179
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: add createMarkdown() factory to expose the compiler and parser #649
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: ca6818a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
This allows for direct use of the markdown-to-jsx AST if it's preferable for your use case to retain full control over output. refactor: isolate React rendering rules chore: upgrade dependencies refactor: consolidate formatted text rules chore: update dependencies refactor: react 16 refactor: remove top-level compiler export refactor: moving things around chore: update benchmark refactor: improve typings refactor: refactor rules into tuple array, add disable/enableRules feat: add custom rule support forward-port fixes from 7.x
9e8b569
to
ca6818a
Compare
Report too large to display inline |
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to modify the regular expression to remove the ambiguity and nested quantifiers that can cause exponential backtracking. We can achieve this by breaking down the complex pattern into simpler, non-ambiguous parts.
- The original regular expression is designed to match various inline formatting patterns, including bold, italic, strikethrough, and others.
- We will refactor the regular expression to avoid nested quantifiers and ambiguous sub-expressions while preserving the original functionality.
-
Copy modified line R236
@@ -235,3 +235,3 @@ | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
|
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we should replace the .*?
pattern with a more specific pattern that avoids matching an excessive number of characters in an ambiguous way.
- We will replace
.*?
with a pattern that matches any character except for the ones that would cause backtracking issues. - The new pattern will be
[^*_]+?
, which matches one or more characters that are not*
or_
, non-greedily.
-
Copy modified line R236
@@ -235,3 +235,3 @@ | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[^*_]+?\4|[^*_])+?)\1/ | ||
|
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Copilot Autofix AI 3 days ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we should replace the .*?
pattern with a more precise sub-expression that avoids matching an excessive number of characters in an ambiguous manner.
- We will replace the
.*?
pattern with a more specific pattern that matches the intended characters without causing backtracking issues. - The changes will be made to the regular expression on line 236 in the file
index.tsx
. - No additional methods, imports, or definitions are needed to implement the changes.
-
Copy modified line R236
@@ -235,3 +235,3 @@ | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:[^<]*<[^>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
|
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we should replace the .*?
pattern with a more specific pattern that avoids ambiguity. In this case, we can use a negated character class to match any character except the ones that would cause the backtracking issue.
- Replace
.*?
with a negated character class that matches any character except the problematic ones. - Ensure that the modified regular expression maintains the same functionality as the original.
-
Copy modified line R236
@@ -235,3 +235,3 @@ | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:.*?<[^>]*>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
|
const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`) | ||
// https://regexr.com/7u91c | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 3 days ago
To fix the problem, we need to modify the regular expression to remove the ambiguity that causes exponential backtracking. Specifically, we should replace the .*?
pattern with a more precise sub-expression that avoids ambiguity. In this case, we can use a negated character class to match any character except the ones that would cause the backtracking issue.
- Modify the regular expression on line 236 to replace
.*?
with a more specific pattern. - Ensure that the new pattern maintains the original functionality of the regular expression.
-
Copy modified line R236
@@ -235,3 +235,3 @@ | ||
const INLINE_FORMATTING_R = | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^<>]*(?:.*?<[^<>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/ | ||
|
Alternate branch for #559