Repository: prettier/prettier
File: src/language-markdown/printer-markdown.js (JavaScript)

Code before:
          prefix.replaceAll("\\", ""),
        );
      }

      return escapedValue;
    }
    case "whitespace": {
      const { next } = path;

      const proseWrap =
        // leading char that may cause different syntax
        next && /^>|^(?:[*+-]|#{1,6}|\d+[).])$/u.test(next.value)
          ? "never"
          : options.proseWrap;

      return printWhitespace(path, node.value, proseWrap);
    }
    case "emphasis": {
      let style;
      if (isAutolink(node.children[0])) {
        style = options.originalText[node.position.start.offset];
      } else {
        const hasPrevOrNextWord = prevOrNextWord(path); // `1*2*3` is considered emphasis but `1_2_3` is not
        const inStrongAndHasPrevOrNextWord = // `1***2***3` is considered strong emphasis but `1**_2_**3` is not
          path.parent?.type === "strong" &&
          path.callParent((parent) => prevOrNextWord(parent));
        style =
          hasPrevOrNextWord ||
          inStrongAndHasPrevOrNextWord ||
          path.hasAncestor((node) => node.type === "emphasis")
            ? "*"
            : "_";
      }
      return [style, printChildren(path, options, print), style];
    }
    case "strong":
      return ["**", printChildren(path, options, print), "**"];
    case "delete":
      return ["~~", printChildren(path, options, print), "~~"];
    case "inlineCode": {
      const code =
        options.proseWrap === "preserve"
          ? node.value
          : node.value.replaceAll("\n", " ");
      const backtickCount = getMinNotPresentContinuousCount(code, "`");
      const backtickString = "`".repeat(backtickCount || 1);
      const padding =
        code.startsWith("`") ||
        code.endsWith("`") ||
        (/^[\n ]/u.test(code) && /[\n ]$/u.test(code) && /[^\n ]/u.test(code))
          ? " "

Review comment (suggestion):
The logic looks good.


This will be an ESLint error caused by #18038, can you rebase?


We can also do both check in `path.callParent()`

```suggestion
          path.callParent(({node}) => node.type === "strong" prevOrNextWord(path));
```

Code after:
          prefix.replaceAll("\\", ""),
        );
      }

      return escapedValue;
    }
    case "whitespace": {
      const { next } = path;

      const proseWrap =
        // leading char that may cause different syntax
        next && /^>|^(?:[*+-]|#{1,6}|\d+[).])$/u.test(next.value)
          ? "never"
          : options.proseWrap;

      return printWhitespace(path, node.value, proseWrap);
    }
    case "emphasis": {
      let style;
      if (isAutolink(node.children[0])) {
        style = options.originalText[node.position.start.offset];
      } else {
        const hasPrevOrNextWord = prevOrNextWord(path); // `1*2*3` is considered emphasis but `1_2_3` is not
        const inStrongAndHasPrevOrNextWord = // `1***2***3` is considered strong emphasis but `1**_2_**3` is not
          path.callParent(
            ({ node }) => node.type === "strong" && prevOrNextWord(path),
          );
        style =
          hasPrevOrNextWord ||
          inStrongAndHasPrevOrNextWord ||
          path.hasAncestor((node) => node.type === "emphasis")
            ? "*"
            : "_";
      }
      return [style, printChildren(path, options, print), style];
    }
    case "strong":
      return ["**", printChildren(path, options, print), "**"];
    case "delete":
      return ["~~", printChildren(path, options, print), "~~"];
    case "inlineCode": {
      const code =
        options.proseWrap === "preserve"
          ? node.value
          : node.value.replaceAll("\n", " ");
      const backtickCount = getMinNotPresentContinuousCount(code, "`");
      const backtickString = "`".repeat(backtickCount || 1);
      const padding =
        code.startsWith("`") ||
        code.endsWith("`") ||
        (/^[\n ]/u.test(code) && /[\n ]$/u.test(code) && /[^\n ]/u.test(code))