Skip to content

feat(checks): Add safety checks for MDX format#19814

Open
gersona wants to merge 6 commits into
WeblateOrg:mainfrom
gersona:19555_mdx_checks
Open

feat(checks): Add safety checks for MDX format#19814
gersona wants to merge 6 commits into
WeblateOrg:mainfrom
gersona:19555_mdx_checks

Conversation

@gersona
Copy link
Copy Markdown
Contributor

@gersona gersona commented May 29, 2026

  • fixes Checks for MDX format #19555
    This only handles the JSX expressions like {propos.name}, assuming the other inline codes are already handled by the Markdown check and/or Auto safe HTML checks

@gersona
Copy link
Copy Markdown
Contributor Author

gersona commented May 29, 2026

@nijel I'm not sure if default_disabled should be set to True as for MarkdownBaseCheck
I also assume this will be included in the 2026.7 release.

@argos-ci
Copy link
Copy Markdown

argos-ci Bot commented May 29, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 9 changed Jun 4, 2026, 5:44 AM

@gersona gersona marked this pull request as ready for review May 29, 2026 17:38
@gersona gersona requested a review from nijel as a code owner May 29, 2026 17:38
Comment thread weblate/formats/base.py Outdated
Comment thread weblate/checks/mdx.py
Comment thread weblate/checks/mdx.py Outdated

def get_jsx_expression_matches(self, text: str):
# matches expressions like {props.name.toUpperCase()}
jsx_expression_pattern = r"\{[^{}]+\}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this is too simple; you can have curly braces inside the expression:

<button onClick={() => {
  console.log("Clicked!");
  setCount(count + 1);
}}>
  Click Me
</button>

<div style={{ color: 'blue', fontSize: '14px' }}>Text</div>

<div>
  {users.map(({ id, name }) => (
    <p key={id}>{name}</p>
  ))}
</div>

PS: I've just quickly Googled for examples, these might be wrong, so first properly evaluate the JSX syntax.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll make changes to handle that.
From what I understand, it's a valid example JSX, but the MDX parser would skip the content inside markups.
But something like the following would be correctly parsed

Test {
    [1, 2, 3].map(
        ({ id }) => (<p key={id}>{id}</p>)
        )
}

@nijel nijel added this to the 2026.7 milestone May 29, 2026
@nijel nijel requested a review from Copilot May 29, 2026 18:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new MDX-specific translation safety check intended to prevent JSX expression changes in .mdx strings, and wires it into the MDX format’s default check flags and documentation.

Changes:

  • Introduces SafeMDXCheck and registers it in the default checks list.
  • Enables the safe-mdx flag for MDX via format defaults and location-based flag inference.
  • Updates tests and autogenerated documentation snippets to reflect the new check/flag.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
weblate/settings_example.py Documents the new check in the example check list.
weblate/formats/tests/test_convert.py Adds an assertion for MDX format default check flags.
weblate/formats/convert.py Adds MDX safe-mdx to format-level check_flags (and a minor typing tweak).
weblate/formats/base.py Adds safe-mdx to location-derived flags for .mdx paths.
weblate/checks/tests/test_flags.py Updates expected location-derived flags for .mdx.
weblate/checks/test_mdx.py Adds unit tests for the new MDX check.
weblate/checks/mdx.py Implements the new SafeMDXCheck.
weblate/checks/defaults.py Registers SafeMDXCheck in the default checks.
docs/snippets/format-features/mdx-features.rst Updates MDX format feature snippet to include the new check.
docs/snippets/checks-autogenerated.rst Adds autogenerated docs section for check-safe-mdx.
docs/snippets/check-flags-autogenerated.rst Adds ignore-safe-mdx to the ignore-flags documentation.
docs/changes.rst Adds a 2026.7 changelog entry describing the new check.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread weblate/checks/mdx.py Outdated
Comment thread weblate/checks/test_mdx.py
Comment thread weblate/checks/test_mdx.py
Comment thread weblate/checks/test_mdx.py Outdated
Comment thread weblate/checks/test_mdx.py Outdated
Comment thread docs/snippets/checks-autogenerated.rst Outdated
Comment thread weblate/checks/mdx.py Outdated
Comment thread weblate/checks/mdx.py
Comment thread docs/snippets/checks-autogenerated.rst Outdated
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.

Checks for MDX format

3 participants