mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	Fixed handling of tables with empty headers
This commit is contained in:
		
							parent
							
								
									54f84c12fd
								
							
						
					
					
						commit
						1452200c79
					
				
							
								
								
									
										10
									
								
								build_for_test.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								build_for_test.sh
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | ||||
| #!/bin/bash | ||||
| ROOT_DIR=/mnt/d/Web/www/joplin | ||||
| CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||||
| set -e | ||||
| npm run build | ||||
| # rsync -a ./dist/ $ROOT_DIR/ElectronClient/app/node_modules/joplin-turndown-plugin-gfm/dist/ | ||||
| # rsync -a ./lib/ $ROOT_DIR/ElectronClient/app/node_modules/joplin-turndown-plugin-gfm/lib/ | ||||
| rm -rf $ROOT_DIR/CliClient/node_modules/joplin-turndown-plugin-gfm | ||||
| ln -s "$CURRENT_DIR" $ROOT_DIR/CliClient/node_modules/joplin-turndown-plugin-gfm | ||||
| $ROOT_DIR/CliClient/run_test.sh HtmlToMd | ||||
| @ -49,16 +49,20 @@ rules.table = { | ||||
|   replacement: function (content, node) { | ||||
|     if (tableShouldBeSkipped(node)) return content; | ||||
| 
 | ||||
|     // Ensure there are no blank lines
 | ||||
|     content = content.replace(/\n+/g, '\n') | ||||
| 
 | ||||
|     // If table has no heading, add an empty one so as to get a valid Markdown table
 | ||||
|     var firstRow = node.rows.length ? node.rows[0] : null | ||||
|     var columnCount = tableColCount(node); //firstRow ? firstRow.childNodes.length : 0
 | ||||
|     var secondLine = content.split('\n'); | ||||
|     if (secondLine.length >= 2) secondLine = secondLine[1] | ||||
|     var secondLineIsDivider = secondLine.indexOf('| ---') === 0 | ||||
|      | ||||
|     var columnCount = tableColCount(node); | ||||
|     var emptyHeader = '' | ||||
|     if (columnCount && !isHeadingRow(firstRow)) { | ||||
|     if (columnCount && !secondLineIsDivider) { | ||||
|       emptyHeader = '|' + '     |'.repeat(columnCount) + '\n' + '|' + ' --- |'.repeat(columnCount) | ||||
|     } | ||||
| 
 | ||||
|     // Ensure there are no blank lines
 | ||||
|     content = content.replace(/\n+/g, '\n') | ||||
|     return '\n\n' + emptyHeader + content + '\n\n' | ||||
|   } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Laurent Cozic
						Laurent Cozic