我可以使用正则表达式将这些示例转换为降价吗?

Can I use a regular expression to convert these examples to markdown?

我一直致力于 google docs to markdown converter to convert post written in google docs to something that can be easily used within jekyll. Unfortunately, google docs has some foibles that make conversion non-trivial. For example, kramdown emphasis 要求通过强调标记 "surrounded" 强调文本,其中:

Surrounded means that the starting delimiter must not be followed by a space and that the stopping delimiter must not be preceded by a space.

另一方面,在 google 文档中,可以强调空格,这将生成 kramdown 无法解析的输出。

*em * 会产生 *em *,而不是 em.

我写了一个正则表达式来匹配和替换这个不正确的强调,但我被困在一个极端的情况下。

/(\*+)(\s*\b)([^\*]*)(\b\s*)(\*+)/g 将正确匹配(因此允许替换下面的每个重点区域):

*** Strong italic text ***, and even just *strong text *, when rendered in * Markdown*, doesn't like *spaces * around the boundaries of the stars.

但在单词中有强调时会哽咽。

* You can see it also within the li**n**es here. *

(匹配现在以 "lines" 中的 *s 结束,并且不会在终止 * 之前捕获 " "s。)

这一切在 regexr 上都很清楚。

如何编辑正则表达式以正确处理这种特殊情况,即忽略(正确)嵌入单词中的 *s?

看来你想要这样的东西。

\B(\*+)(\s*)(?:\b\*+\b|[^*\s]|\s(?=\w))*(\s*)(\*+)\B

DEMO