Skip to content

Conversation

@xvzhifeng
Copy link

正则匹配时会清除掉\n导致原本能够正确替换到代码片段的正则失效。

const contentWithoutCode = source
            .replace(/^[^#]+\n/g, '')
            .replace(/(?:[^\n#]+)#+\s([^#\n]+)\n*/g, '') // 匹配行内出现 # 号的情况
            .replace(/^#\s[^#\n]*\n+/, '')
            .replace(/```[^`\n]*\n+[^```]+```\n*/g, '')
            .replace(/`([^`\n]+)`/g, '$1')
            .replace(/\*\*?([^*\n]+)\*\*?/g, '$1')
            .replace(/__?([^_\n]+)__?/g, '$1')
            .trim();

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.

1 participant