-
Notifications
You must be signed in to change notification settings - Fork 36
ARR: Validate camera-ready against TeX/Markdown #3001
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
Draft
haroldrubio
wants to merge
10
commits into
master
Choose a base branch
from
fix/arr-tex-markdown
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9a7908f
Add validation test
haroldrubio 73ae482
Rework tests
haroldrubio 9431a2d
Add await queue edit
haroldrubio 794fbc4
Merge branch 'master' into fix/arr-tex-markdown
haroldrubio bf64130
Merge branch 'master' into fix/arr-tex-markdown
haroldrubio b023c98
Fix tests and move process functions to files
haroldrubio 23b2c51
Merge branch 'master' into fix/arr-tex-markdown
haroldrubio 2b97e16
Add additional test from Copilot comments
haroldrubio 7a2c4d3
Merge branch 'master' into fix/arr-tex-markdown
haroldrubio fd44458
Merge branch 'master' into fix/arr-tex-markdown
haroldrubio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| async function process(client, edit, invitation) { | ||
| client.throwErrors = true; | ||
| const { invitations } = await client.getInvitations({ id: invitation.invitations[0] }); | ||
| const metaInvitation = invitations[0]; | ||
| const script = metaInvitation.content.revision_preprocess_script.value; | ||
| eval(`var process = ${script}`); | ||
| await process(client, edit, invitation); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| async function process(client, edit, invitation) { | ||
| client.throwErrors = true; | ||
|
|
||
| const texRules = [ | ||
| { name: 'TeX environment', regex: /\\begin\{[^}\n]+\}[\s\S]*?\\end\{[^}\n]+\}/ }, | ||
| { name: 'TeX command', regex: /\\[A-Za-z]+(?:\*)?\b/ }, | ||
| { name: 'TeX escaped symbol', regex: /\\[%&#_$^{}]/ }, | ||
| { name: 'TeX display math', regex: /(^|[^\\])\$\$[\s\S]+?\$\$/ }, | ||
| { name: 'TeX inline math', regex: /(^|[^\\])\$(?:[^$\n]|\\\$)+\$/ }, | ||
| { name: 'TeX math \\(...\\)', regex: /\\\([\s\S]+?\\\)/ }, | ||
|
haroldrubio marked this conversation as resolved.
|
||
| { name: 'TeX math \\[...\\]', regex: /\\\[[\s\S]+?\\\]/ } | ||
| ]; | ||
|
|
||
| const markdownRules = [ | ||
| { name: 'Markdown link', regex: /\[[^\]\n]+\]\([^)]+\)/ }, | ||
| { name: 'Markdown autolink', regex: /<https?:\/\/[^>\s]+>/i }, | ||
| { name: 'Markdown fenced code', regex: /```[\s\S]+?```/ }, | ||
| { name: 'Markdown code span', regex: /`[^`\n]+`/ }, | ||
| { name: 'Markdown emphasis (*)', regex: /(^|[^\w])\*{1,3}[^*\n]+\*{1,3}(?=$|[^\w])/ }, | ||
| { name: 'Markdown emphasis (_)', regex: /(^|[^\w])_{1,2}[^_\n]+_{1,2}(?=$|[^\w])/ } | ||
| ]; | ||
|
|
||
| const normalize = (value) => typeof value === 'string' | ||
| ? value.replace(/\r\n?/g, '\n').trim() | ||
| : ''; | ||
|
|
||
| const findViolation = (text, rules) => { | ||
| for (const rule of rules) { | ||
| const match = text.match(rule.regex); | ||
| if (match) { | ||
| return { | ||
| rule: rule.name, | ||
| snippet: match[0].replace(/\s+/g, ' ').trim().slice(0, 80) | ||
| }; | ||
| } | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| for (const field of ['title', 'abstract']) { | ||
| const value = normalize(edit.note?.content?.[field]?.value); | ||
| if (!value) { | ||
| continue; | ||
| } | ||
|
|
||
| const texViolation = findViolation(value, texRules); | ||
| if (texViolation) { | ||
| return Promise.reject(new OpenReviewError({ | ||
| name: 'Error', | ||
| message: `${field} cannot contain TeX markup (${texViolation.rule}). Detected: ${texViolation.snippet}` | ||
| })); | ||
| } | ||
|
|
||
| const markdownViolation = findViolation(value, markdownRules); | ||
| if (markdownViolation) { | ||
| return Promise.reject(new OpenReviewError({ | ||
| name: 'Error', | ||
| message: `${field} cannot contain Markdown markup (${markdownViolation.rule}). Detected: ${markdownViolation.snippet}` | ||
| })); | ||
| } | ||
| } | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.