Repository: platers/obsidian-linter (ts)

Issue:
Bug: Spaces are inserted into Inline code blocks after linting when "Space between Chinese and English or numbers" turned on
## Describe the Bug

I put Chinese characters in inline code blocks sometimes, like when I quote a code snippet containing a Chinese string: `filepath = './知识_巴别图书馆.md'`. I found that if I do the linting, spaces would be added between the underscore and backquote, which is not I want. Could you please fix this? Just keep them unchanged in inline code blocks will do.
I turned on the rule "Space between Chinese and English or numbers".

## How to Reproduce

Here are some examples. None of them should add any space. Some of them work fine but some are not.

``` markdown
`test`
`test_case`
`test_case_here`
`test*case`
`test*case*here`
`测试`
`测试_一下`
`测试_一下_吧`
`测试-几个-才行`
`测试*一下`
`测试*一下*你们`
`测试一下**你们**所有人`
`测试this case`
`测试_this_case`
`this_测试-还*可以`
`filepath = './知识_巴别图书馆.md'`
```

## Expected Behavior

Same as input.

## Current Behavior

``` markdown
`test`
`test_case`
`test_case_here`
`test*case`
`test*case*here`
` 测试 `
` 测试 _ 一下 `
` 测试 _ 一下 _ 吧 `
` 测试 - 几个 - 才行 `
` 测试 * 一下 `
` 测试 * 一下 * 你们 `
` 测试一下**你们**所有人 `
` 测试 this case`
` 测试 _this_case`
`this_ 测试 - 还 * 可以 `
`filepath = './知识 _ 巴别图书馆.md'`
```

## Device

- [x] Desktop
- [x] Mobile


Pull request:
Handle Chinese Characters Having Spaces Added in Inline Code
Fixes #378

Changes Made:
- Added test to account for the bug
- Added inline code to the list of ignored types
- Added mdast and ignore types for inline code
- Made sure that the `IgnoreTypes` was converted over to an immutable object with immutable properties

Patch:
diff --git a/src/rules/space-between-chinese-and-english-or-numbers.ts b/src/rules/space-between-chinese-and-english-or-numbers.ts
index f27b9f5..c81d5fe 100644
--- a/src/rules/space-between-chinese-and-english-or-numbers.ts
+++ b/src/rules/space-between-chinese-and-english-or-numbers.ts
@@ -28,7 +28,7 @@ export default class SpaceBetweenChineseAndEnglishOrNumbers extends RuleBuilder<
       return text.replace(head, '$1 $3').replace(tail, '$1 $3');
     };
 
-    let newText = ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.yaml, IgnoreTypes.image, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.italics, IgnoreTypes.bold], text, addSpaceAroundChineseAndEnglish);
+    let newText = ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.yaml, IgnoreTypes.image, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.italics, IgnoreTypes.bold], text, addSpaceAroundChineseAndEnglish);
 
     newText = updateItalicsText(newText, addSpaceAroundChineseAndEnglish);
 
diff --git a/src/utils/ignore-types.ts b/src/utils/ignore-types.ts
index 9706233..6acd2d5 100644
--- a/src/utils/ignore-types.ts
+++ b/src/utils/ignore-types.ts
@@ -11,6 +11,7 @@ export type IgnoreType = {replaceAction: MDAstTypes | RegExp | IgnoreFunction, p
 export const IgnoreTypes: Record<string, IgnoreType> = {
   // mdast node types
   code: {replaceAction: MDAstTypes.Code, placeholder: '{CODE_BLOCK_PLACEHOLDER}'},
+  inlineCode: {replaceAction: MDAstTypes.InlineCode, placeholder: '{INLINE_CODE_BLOCK_PLACEHOLDER}'},
   image: {replaceAction: MDAstTypes.Image, placeholder: '{IMAGE_PLACEHOLDER}'},
   thematicBreak: {replaceAction: MDAstTypes.HorizontalRule, placeholder: '{HORIZONTAL_RULE_PLACEHOLDER}'},
   italics: {replaceAction: MDAstTypes.Italics, placeholder: '{ITALICS_PLACEHOLDER}'},
@@ -25,7 +26,7 @@ export const IgnoreTypes: Record<string, IgnoreType> = {
   obsidianMultiLineComments: {replaceAction: obsidianMultilineCommentRegex, placeholder: '{OBSIDIAN_COMMENT_PLACEHOLDER}'},
   // custom functions
   link: {replaceAction: replaceMarkdownLinks, placeholder: '{REGULAR_LINK_PLACEHOLDER}'},
-};
+} as const;
 
 export function ignoreListOfTypes(ignoreTypes: IgnoreType[], text: string, func: ((text: string) => string)): string {
   let setOfPlaceholders: {placeholder: string, replacedValues: string[]}[] = [];
diff --git a/src/utils/mdast.ts b/src/utils/mdast.ts
index bd1fe17..02c2d64 100644
--- a/src/utils/mdast.ts
+++ b/src/utils/mdast.ts
@@ -15,6 +15,7 @@ export enum MDAstTypes {
   Bold = 'strong',
   ListItem = 'listItem',
   Code = 'code',
+  InlineCode = 'inlineCode',
   Table = 'table',
   Image = 'image',
   List = 'list',


Test patch:
diff --git a/__tests__/space-between-chinese-and-english-or-numbers.test.ts b/__tests__/space-between-chinese-and-english-or-numbers.test.ts
index d489a23..e2efbd8 100644
--- a/__tests__/space-between-chinese-and-english-or-numbers.test.ts
+++ b/__tests__/space-between-chinese-and-english-or-numbers.test.ts
@@ -15,5 +15,45 @@ ruleTest({
         这是一个数学公式 $f(x)=x^2$ 这是一个数学公式
       `,
     },
+    {
+      // accounts for https://github.com/platers/obsidian-linter/issues/378
+      testName: 'Make sure that inline code blocks are not affected',
+      before: dedent`
+        \`test\`
+        \`test_case\`
+        \`test_case_here\`
+        \`test*case\`
+        \`test*case*here\`
+        \`测试\`
+        \`测试_一下\`
+        \`测试_一下_吧\`
+        \`测试-几个-才行\`
+        \`测试*一下\`
+        \`测试*一下*你们\`
+        \`测试一下**你们**所有人\`
+        \`测试this case\`
+        \`测试_this_case\`
+        \`this_测试-还*可以\`
+        \`filepath = './知识_巴别图书馆.md'\`
+      `,
+      after: dedent`
+        \`test\`
+        \`test_case\`
+        \`test_case_here\`
+        \`test*case\`
+        \`test*case*here\`
+        \`测试\`
+        \`测试_一下\`
+        \`测试_一下_吧\`
+        \`测试-几个-才行\`
+        \`测试*一下\`
+        \`测试*一下*你们\`
+        \`测试一下**你们**所有人\`
+        \`测试this case\`
+        \`测试_this_case\`
+        \`this_测试-还*可以\`
+        \`filepath = './知识_巴别图书馆.md'\`
+      `,
+    },
   ],
 });