mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	[MFM] Better hashtag detection
This commit is contained in:
		
							parent
							
								
									10fb399588
								
							
						
					
					
						commit
						c58027e521
					
				
					 2 changed files with 3 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -162,7 +162,7 @@ const mfm = P.createLanguage({
 | 
			
		|||
			let hashtag = match[1];
 | 
			
		||||
			hashtag = hashtag.substr(0, getTrailingPosition(hashtag));
 | 
			
		||||
			if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
 | 
			
		||||
			if (!['\n', ' ', ' ', '(', '「', null, undefined].includes(input[i - 1])) return P.makeFailure(i, 'require space before "#"');
 | 
			
		||||
			if (input[i - 1] != null && input[i - 1].match(/[a-z0-9]/i)) return P.makeFailure(i, 'not a hashtag');
 | 
			
		||||
			return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
 | 
			
		||||
		}),
 | 
			
		||||
	//#endregion
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -187,9 +187,9 @@ describe('Text', () => {
 | 
			
		|||
			});
 | 
			
		||||
 | 
			
		||||
			it('with text (zenkaku)', () => {
 | 
			
		||||
				const tokens = analyze('こんにちは #世界');
 | 
			
		||||
				const tokens = analyze('こんにちは#世界');
 | 
			
		||||
				assert.deepEqual([
 | 
			
		||||
					text('こんにちは '),
 | 
			
		||||
					text('こんにちは'),
 | 
			
		||||
					node('hashtag', { hashtag: '世界' })
 | 
			
		||||
				], tokens);
 | 
			
		||||
			});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue