* improve MFM to html * improve html to MFM * missing semicolon * missing semicolon * fix html to MFM タグのリンクは解除するように * fix bug * misssing semicolon * Update html-to-mfm.ts * Update html-to-mfm.ts
This commit is contained in:
		
							parent
							
								
									d2abe2cd81
								
							
						
					
					
						commit
						ffb345ccb5
					
				
					 1 changed files with 10 additions and 7 deletions
				
			
		| 
						 | 
					@ -33,15 +33,19 @@ export default function(html: string): string {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case 'a':
 | 
								case 'a':
 | 
				
			||||||
				const txt = getText(node);
 | 
									const txt = getText(node);
 | 
				
			||||||
 | 
									const rel = node.attrs.find((x: any) => x.name == 'rel');
 | 
				
			||||||
 | 
									const href = node.attrs.find((x: any) => x.name == 'href');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// ハッシュタグ / hrefがない / txtがURL
 | 
				
			||||||
 | 
									if ((rel && rel.value.match('tag') !== null) || !href || href.value == txt) {
 | 
				
			||||||
 | 
										text += txt;
 | 
				
			||||||
				// メンション
 | 
									// メンション
 | 
				
			||||||
				if (txt.startsWith('@')) {
 | 
									} else if (txt.startsWith('@')) {
 | 
				
			||||||
					const part = txt.split('@');
 | 
										const part = txt.split('@');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (part.length == 2) {
 | 
										if (part.length == 2) {
 | 
				
			||||||
						//#region ホスト名部分が省略されているので復元する
 | 
											//#region ホスト名部分が省略されているので復元する
 | 
				
			||||||
						const href = new URL(node.attrs.find((x: any) => x.name == 'href').value);
 | 
											const acct = txt + '@' + (new URL(href.value)).hostname;
 | 
				
			||||||
						const acct = txt + '@' + href.hostname;
 | 
					 | 
				
			||||||
						text += acct;
 | 
											text += acct;
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
						//#endregion
 | 
											//#endregion
 | 
				
			||||||
| 
						 | 
					@ -49,10 +53,9 @@ export default function(html: string): string {
 | 
				
			||||||
						text += txt;
 | 
											text += txt;
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									// その他
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
				if (node.childNodes) {
 | 
										text += `[${txt}](${href.value})`;
 | 
				
			||||||
					node.childNodes.forEach((n: any) => analyze(n));
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue