mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	Merge pull request #9 from domchristie/tables_with_no_heading_row
Keep tables with no definitive heading row
This commit is contained in:
		
						commit
						22f423429c
					
				@ -32,7 +32,12 @@ rules.tableRow = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rules.table = {
 | 
					rules.table = {
 | 
				
			||||||
  filter: 'table',
 | 
					  // Only convert tables with a heading row.
 | 
				
			||||||
 | 
					  // Tables with no heading row are kept using `keep` (see below).
 | 
				
			||||||
 | 
					  filter: function (node) {
 | 
				
			||||||
 | 
					    return node.nodeName === 'TABLE' && isHeadingRow(node.rows[0])
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  replacement: function (content) {
 | 
					  replacement: function (content) {
 | 
				
			||||||
    // Ensure there are no blank lines
 | 
					    // Ensure there are no blank lines
 | 
				
			||||||
    content = content.replace('\n\n', '\n')
 | 
					    content = content.replace('\n\n', '\n')
 | 
				
			||||||
@ -85,5 +90,8 @@ function cell (content, node) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function tables (turndownService) {
 | 
					export default function tables (turndownService) {
 | 
				
			||||||
 | 
					  turndownService.keep(function (node) {
 | 
				
			||||||
 | 
					    return node.nodeName === 'TABLE' && !isHeadingRow(node.rows[0])
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
  for (var key in rules) turndownService.addRule(key, rules[key])
 | 
					  for (var key in rules) turndownService.addRule(key, rules[key])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -151,6 +151,10 @@
 | 
				
			|||||||
<div class="case" data-name="empty rows">
 | 
					<div class="case" data-name="empty rows">
 | 
				
			||||||
  <div class="input">
 | 
					  <div class="input">
 | 
				
			||||||
    <table>
 | 
					    <table>
 | 
				
			||||||
 | 
					      <thead>
 | 
				
			||||||
 | 
					        <td>Heading 1</td>
 | 
				
			||||||
 | 
					        <td>Heading 2</td>
 | 
				
			||||||
 | 
					      </thead>
 | 
				
			||||||
      <tbody>
 | 
					      <tbody>
 | 
				
			||||||
        <tr>
 | 
					        <tr>
 | 
				
			||||||
          <td>Row 1</td>
 | 
					          <td>Row 1</td>
 | 
				
			||||||
@ -167,7 +171,9 @@
 | 
				
			|||||||
      </tbody>
 | 
					      </tbody>
 | 
				
			||||||
    </table>
 | 
					    </table>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
<pre class="expected">| Row 1 | Row 1 |
 | 
					<pre class="expected">| Heading 1 | Heading 2 |
 | 
				
			||||||
 | 
					| --- | --- |
 | 
				
			||||||
 | 
					| Row 1 | Row 1 |
 | 
				
			||||||
| Row 3 | Row 3 |</pre>
 | 
					| Row 3 | Row 3 |</pre>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -233,23 +239,6 @@
 | 
				
			|||||||
| Content |</pre>
 | 
					| Content |</pre>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div class="case" data-name="th in first row">
 | 
					 | 
				
			||||||
  <div class="input">
 | 
					 | 
				
			||||||
    <table>
 | 
					 | 
				
			||||||
      <tr>
 | 
					 | 
				
			||||||
        <th>Heading</th>
 | 
					 | 
				
			||||||
        <td>Not a heading</td>
 | 
					 | 
				
			||||||
      </tr>
 | 
					 | 
				
			||||||
      <tr>
 | 
					 | 
				
			||||||
        <td>Heading</td>
 | 
					 | 
				
			||||||
        <td>Not a heading</td>
 | 
					 | 
				
			||||||
      </tr>
 | 
					 | 
				
			||||||
    </table>
 | 
					 | 
				
			||||||
  </div>
 | 
					 | 
				
			||||||
  <pre class="expected">| Heading | Not a heading |
 | 
					 | 
				
			||||||
| Heading | Not a heading |</pre>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<div class="case" data-name="heading cells in both thead and tbody">
 | 
					<div class="case" data-name="heading cells in both thead and tbody">
 | 
				
			||||||
  <div class="input">
 | 
					  <div class="input">
 | 
				
			||||||
    <table>
 | 
					    <table>
 | 
				
			||||||
@ -273,6 +262,32 @@
 | 
				
			|||||||
| --- |</pre>
 | 
					| --- |</pre>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div class="case" data-name="non-definitive heading row (not converted)">
 | 
				
			||||||
 | 
					  <div class="input">
 | 
				
			||||||
 | 
					    <table>
 | 
				
			||||||
 | 
					      <tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr>
 | 
				
			||||||
 | 
					      <tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr>
 | 
				
			||||||
 | 
					    </table>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					  <pre class="expected"><table><tbody><tr><td>Row 1 Cell 1</td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 Cell 2</td></tr></tbody></table></pre>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<div class="case" data-name="non-definitive heading row with th (not converted)">
 | 
				
			||||||
 | 
					  <div class="input">
 | 
				
			||||||
 | 
					    <table>
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <th>Heading</th>
 | 
				
			||||||
 | 
					        <td>Not a heading</td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <td>Heading</td>
 | 
				
			||||||
 | 
					        <td>Not a heading</td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					    </table>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					  <pre class="expected"><table><tbody><tr><th>Heading</th><td>Not a heading</td></tr><tr><td>Heading</td><td>Not a heading</td></tr></tbody></table></pre>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div class="case" data-name="highlighted code block with html">
 | 
					<div class="case" data-name="highlighted code block with html">
 | 
				
			||||||
  <div class="input">
 | 
					  <div class="input">
 | 
				
			||||||
    <div class="highlight highlight-text-html-basic">
 | 
					    <div class="highlight highlight-text-html-basic">
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user