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: add createMarkdown() factory to expose the compiler and parser #649

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quantizor
Copy link
Owner

Alternate branch for #559

Copy link

changeset-bot bot commented Jan 7, 2025

🦋 Changeset detected

Latest commit: ca6818a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
markdown-to-jsx Major

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

Copy link

socket-security bot commented Jan 7, 2025

👍 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.

View full report↗︎

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
Copy link

Report too large to display inline

View full report↗︎

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

This part of the regular expression may cause exponential backtracking on strings starting with '*' and containing many repetitions of '<>'.

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.
Suggested changeset 1
index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/index.tsx b/index.tsx
--- a/index.tsx
+++ b/index.tsx
@@ -235,3 +235,3 @@
 const INLINE_FORMATTING_R =
-  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
+  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
 
EOF
@@ -235,3 +235,3 @@
const INLINE_FORMATTING_R =
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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

This part of the regular expression may cause exponential backtracking on strings starting with '*' and containing many repetitions of '['.

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.
Suggested changeset 1
index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/index.tsx b/index.tsx
--- a/index.tsx
+++ b/index.tsx
@@ -235,3 +235,3 @@
 const INLINE_FORMATTING_R =
-  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
+  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[^*_]+?\4|[^*_])+?)\1/
 
EOF
@@ -235,3 +235,3 @@
const INLINE_FORMATTING_R =
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[^*_]+?\4|[^*_])+?)\1/

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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

This part of the regular expression may cause exponential backtracking on strings starting with '*[](' and containing many repetitions of ')[]('.

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

This part of the regular expression may cause exponential backtracking on strings starting with '*<' and containing many repetitions of '><'.

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.
Suggested changeset 1
index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/index.tsx b/index.tsx
--- a/index.tsx
+++ b/index.tsx
@@ -235,3 +235,3 @@
 const INLINE_FORMATTING_R =
-  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
+  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:[^<]*<[^>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
 
EOF
@@ -235,3 +235,3 @@
const INLINE_FORMATTING_R =
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:[^<]*<[^>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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

This part of the regular expression may cause exponential backtracking on strings starting with '*<>' and containing many repetitions of '<><>'.

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.
Suggested changeset 1
index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/index.tsx b/index.tsx
--- a/index.tsx
+++ b/index.tsx
@@ -235,3 +235,3 @@
 const INLINE_FORMATTING_R =
-  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
+  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:.*?<[^>]*>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
 
EOF
@@ -235,3 +235,3 @@
const INLINE_FORMATTING_R =
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^>]*>(?:.*?<[^>]*>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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

This part of the regular expression may cause exponential backtracking on strings starting with '*<><' and containing many repetitions of '><><'.

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.
Suggested changeset 1
index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/index.tsx b/index.tsx
--- a/index.tsx
+++ b/index.tsx
@@ -235,3 +235,3 @@
 const INLINE_FORMATTING_R =
-  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
+  /^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^<>]*(?:.*?<[^<>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
 
EOF
@@ -235,3 +235,3 @@
const INLINE_FORMATTING_R =
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<.*?>(?:.*?<.*?>)?|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/
/^(([*_])\2|[*_]|~~|==)((?:\[.*?\][([].*?[)\]]|<[^<>]*(?:.*?<[^<>]*>)*|([*_]+|`|~~|==)[\s\S]+?\4|[\s\S])+?)\1/

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant