[MFM] Improve italic syntax detection
This commit is contained in:
		
							parent
							
								
									501379c82c
								
							
						
					
					
						commit
						42cd7c8a75
					
				
					 3 changed files with 18 additions and 1 deletions
				
			
		|  | @ -5,6 +5,7 @@ unreleased | |||
| ---------- | ||||
| * 返信するときにCWを維持するかどうか設定できるように | ||||
| * 外部サービス認証情報の配信 | ||||
| * イタリック構文の判定の改善 | ||||
| * テーマが反映されないことがある問題を修正 | ||||
| * ホームにフォロワー限定投稿が表示されない問題を修正 | ||||
| * 返信一覧を取得すると非公開投稿も取得されてしまう問題を修正 | ||||
|  |  | |||
|  | @ -224,7 +224,16 @@ const mfm = P.createLanguage({ | |||
| 
 | ||||
| 	//#region Italic
 | ||||
| 	italic: r => | ||||
| 		P.alt(P.regexp(/<i>([\s\S]+?)<\/i>/, 1), P.regexp(/(\*|_)([a-zA-Z0-9]+?[\s\S]*?)\1/, 2)) | ||||
| 		P.alt( | ||||
| 			P.regexp(/<i>([\s\S]+?)<\/i>/, 1), | ||||
| 			P((input, i) => { | ||||
| 				const text = input.substr(i); | ||||
| 				const match = text.match(/^(\*|_)([a-zA-Z0-9]+?[\s\S]*?)\1/); | ||||
| 				if (!match) return P.makeFailure(i, 'not a italic'); | ||||
| 				if (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a italic'); | ||||
| 				return P.makeSuccess(i + match[0].length, match[2]); | ||||
| 			}) | ||||
| 		) | ||||
| 		.map(x => createTree('italic', P.alt( | ||||
| 			r.bold, | ||||
| 			r.strike, | ||||
|  |  | |||
|  | @ -966,6 +966,13 @@ describe('MFM', () => { | |||
| 					text('*foo_'), | ||||
| 				]); | ||||
| 			}); | ||||
| 
 | ||||
| 			it('ignore snake_case string', () => { | ||||
| 				const tokens = analyze('foo_bar_baz'); | ||||
| 				assert.deepStrictEqual(tokens, [ | ||||
| 					text('foo_bar_baz'), | ||||
| 				]); | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue