mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Showdown: parse single underscores as italics
This commit is contained in:
		| @@ -172,6 +172,7 @@ import { | |||||||
| } from './scripts/secrets.js'; | } from './scripts/secrets.js'; | ||||||
| import { EventEmitter } from './lib/eventemitter.js'; | import { EventEmitter } from './lib/eventemitter.js'; | ||||||
| import { markdownExclusionExt } from './scripts/showdown-exclusion.js'; | import { markdownExclusionExt } from './scripts/showdown-exclusion.js'; | ||||||
|  | import { markdownUnderscoreExt } from './scripts/showdown-underscore.js'; | ||||||
| import { NOTE_MODULE_NAME, initAuthorsNote, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from './scripts/authors-note.js'; | import { NOTE_MODULE_NAME, initAuthorsNote, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from './scripts/authors-note.js'; | ||||||
| import { registerPromptManagerMigration } from './scripts/PromptManager.js'; | import { registerPromptManagerMigration } from './scripts/PromptManager.js'; | ||||||
| import { getRegexedString, regex_placement } from './scripts/extensions/regex/engine.js'; | import { getRegexedString, regex_placement } from './scripts/extensions/regex/engine.js'; | ||||||
| @@ -690,6 +691,7 @@ function reloadMarkdownProcessor(render_formulas = false) { | |||||||
|             parseImgDimensions: true, |             parseImgDimensions: true, | ||||||
|             tables: true, |             tables: true, | ||||||
|             underline: true, |             underline: true, | ||||||
|  |             extensions: [markdownUnderscoreExt()], | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								public/scripts/showdown-underscore.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								public/scripts/showdown-underscore.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | // Showdown extension that replaces words surrounded by singular underscores with <em> tags | ||||||
|  | export const markdownUnderscoreExt = () => { | ||||||
|  |     if (!canUseNegativeLookbehind()) { | ||||||
|  |         console.log('Showdown-underscore extension: Negative lookbehind not supported. Skipping.'); | ||||||
|  |         return []; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return [{ | ||||||
|  |         type: 'lang', | ||||||
|  |         regex: /\b(?<!_)_(?!_)(.*?)(?<!_)_(?!_)\b/g, | ||||||
|  |         replace: '<em>$1</em>', | ||||||
|  |     }]; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | function canUseNegativeLookbehind() { | ||||||
|  |     try { | ||||||
|  |         new RegExp('(?<!_)'); | ||||||
|  |         return true; | ||||||
|  |     } catch (e) { | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user