Skip to content

feat: add no-space-in-emphasis rule #403

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Pixel998
Copy link
Contributor

@Pixel998 Pixel998 commented Jun 2, 2025

Prerequisites checklist

What is the purpose of this pull request?

This PR implements the no-space-in-emphasis rule to disallow spaces around emphasis markers.

What changes did you make? (Give an overview)

Implemented the no-space-in-emphasis rule, along with documentation and tests.

Related Issues

Fixes #378

Is there anything you'd like reviewers to focus on?

@Pixel998 Pixel998 marked this pull request as draft June 2, 2025 14:24
@lumirlumir lumirlumir linked an issue Jun 3, 2025 that may be closed by this pull request
1 task
@lumirlumir lumirlumir added this to Triage Jun 3, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 3, 2025
@lumirlumir lumirlumir mentioned this pull request Jun 5, 2025
1 task
@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jun 10, 2025
@snitin315
Copy link
Contributor

@Pixel998 Make sure to mark it as ready for review once done, the team doesn't pay attention to draft PRs.

@snitin315
Copy link
Contributor

@Pixel998 Are you still working on this?

@Pixel998 Pixel998 marked this pull request as ready for review June 22, 2025 05:38

## Background

In Markdown, emphasis (bold and italic) is created using asterisks (`*`) or underscores (`_`), and strikethrough is created using tildes (`~`). The emphasis markers must be directly adjacent to the text they're emphasizing, with no spaces between the markers and the text. When spaces are present, the emphasis is not rendered correctly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In Markdown, emphasis (bold and italic) is created using asterisks (`*`) or underscores (`_`), and strikethrough is created using tildes (`~`). The emphasis markers must be directly adjacent to the text they're emphasizing, with no spaces between the markers and the text. When spaces are present, the emphasis is not rendered correctly.
In Markdown, emphasis (bold and italic) is created using asterisks (`*`) or underscores (`_`), and a strikethrough is created using tildes (`~`). The emphasis markers must be directly adjacent to the text they're emphasizing, with no spaces between the markers and the text. When spaces are present, the emphasis is not rendered correctly.

@snitin315
Copy link
Contributor

snitin315 commented Jun 23, 2025

We have false negatives in case of nested emphasis:

<!-- eslint markdown/no-space-in-emphasis: "error" -->

_ **bold** _ // no error

This is * italic with __ bold __ markdown * // No error reported

This is *italic with __ bold __ markdown* // Reports error for bold emphasis as expected

Comment on lines +265 to +277
{
code: "Broken * emphasis * with spaces",
output: "Broken *emphasis* with spaces",
errors: [
{
messageId: "spaceInEmphasis",
line: 1,
column: 8,
endLine: 1,
endColumn: 20,
},
],
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Markdownlint reports two errors in this case, separate for both prefix & suffix highlighting exactly where the whitespace is instead of highlighting the whole text. Should we do the same? It's better in case of long paragraphs.

Screenshot 2025-06-23 at 2 41 54 PM

@snitin315
Copy link
Contributor

Following is an edge case, I'm not sure if we want to solve for it in the initial version.

**** bold **** // No error, 

Comment on lines +16 to +19
/**
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
* NoSpaceInEmphasisRuleDefinition
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
* NoSpaceInEmphasisRuleDefinition
*/
/**
* @typedef {import("../types.ts").MarkdownRuleDefinition<{ RuleOptions: []; }>}
* NoSpaceInEmphasisRuleDefinition
*/

Could you merge the main branch and update the code to use the @import JSDoc syntax as shown in the ongoing changes in https://github.com/eslint/markdown/pull/367/files?

You can refer to the following image as a guide:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Implementing
Development

Successfully merging this pull request may close these issues.

New Rule: no-space-in-emphasis
3 participants