| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | return [{ |
| 10 | 10 | type: 'langoutput', |
| 11 | 11 | regex: new RegExp('(<code>[\\bs\\S]*?<\\/code>)|(?<!_\\S)_(?!_)(.*[^_\\n]+?)(?<!_)_(?!_)\\bw)', 'g'), |
| 12 | | - replace: '<em>$1</em>', |
| 12 | + replace: function(match, codeContent, italicContent) { |
| 13 | + if (codeContent) { |
| 14 | + // If it's inside <code> tags, return unchanged |
| 15 | + return match; |
| 16 | + } else if (italicContent) { |
| 17 | + // If it's an italic group, apply the replacement |
| 18 | + return '<em>' + italicContent + '</em>'; |
| 19 | + } |
| 20 | + // If none of the conditions are met, return the original match |
| 21 | + return match; |
| 22 | + }, |
| 13 | 23 | }]; |
| 14 | 24 | } catch (e) { |
| 15 | 25 | console.error('Error in Showdown-underscore extension:', e); |