mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	feat(export/markdown): add support for todos
This commit is contained in:
		@@ -37,6 +37,7 @@
 | 
				
			|||||||
*   Basic Touch Bar support for macOS.
 | 
					*   Basic Touch Bar support for macOS.
 | 
				
			||||||
*   [Support Bearer Token](https://github.com/TriliumNext/Notes/issues/1701)
 | 
					*   [Support Bearer Token](https://github.com/TriliumNext/Notes/issues/1701)
 | 
				
			||||||
*   The tab bar is now scrollable when there are many tabs by @SiriusXT
 | 
					*   The tab bar is now scrollable when there are many tabs by @SiriusXT
 | 
				
			||||||
 | 
					*   Markdown export: support todo lists
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 🌍 Internationalization
 | 
					## 🌍 Internationalization
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -321,4 +321,25 @@ describe("Markdown export", () => {
 | 
				
			|||||||
        expect(markdownExportService.toMarkdown(html)).toBe(expected);
 | 
					        expect(markdownExportService.toMarkdown(html)).toBe(expected);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it("exports todo lists properly", () => {
 | 
				
			||||||
 | 
					        const html = trimIndentation/*html*/`\
 | 
				
			||||||
 | 
					            <ul class="todo-list">
 | 
				
			||||||
 | 
					                <li>
 | 
				
			||||||
 | 
					                    <label class="todo-list__label">
 | 
				
			||||||
 | 
					                        <input type="checkbox" checked="checked" disabled="disabled"><span class="todo-list__label__description">Hello</span>
 | 
				
			||||||
 | 
					                    </label>
 | 
				
			||||||
 | 
					                </li>
 | 
				
			||||||
 | 
					                <li>
 | 
				
			||||||
 | 
					                    <label class="todo-list__label">
 | 
				
			||||||
 | 
					                        <input type="checkbox" disabled="disabled"><span class="todo-list__label__description">World</span>
 | 
				
			||||||
 | 
					                    </label>
 | 
				
			||||||
 | 
					                </li>
 | 
				
			||||||
 | 
					            </ul>
 | 
				
			||||||
 | 
					        `;
 | 
				
			||||||
 | 
					        const expected = trimIndentation`\
 | 
				
			||||||
 | 
					            - [x] Hello
 | 
				
			||||||
 | 
					            - [ ] World`;
 | 
				
			||||||
 | 
					        expect(markdownExportService.toMarkdown(html)).toBe(expected);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -230,7 +230,11 @@ function buildListItemFilter(): Rule {
 | 
				
			|||||||
                var start = parent.getAttribute('start')
 | 
					                var start = parent.getAttribute('start')
 | 
				
			||||||
                var index = Array.prototype.indexOf.call(parent.children, node)
 | 
					                var index = Array.prototype.indexOf.call(parent.children, node)
 | 
				
			||||||
                prefix = (start ? Number(start) + index : index + 1) + '.  '
 | 
					                prefix = (start ? Number(start) + index : index + 1) + '.  '
 | 
				
			||||||
 | 
					            } else if (parent.classList.contains("todo-list")) {
 | 
				
			||||||
 | 
					                const isChecked = node.querySelector("input[type=checkbox]:checked");
 | 
				
			||||||
 | 
					                prefix = (isChecked ? "- [x] " : "- [ ] ");
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const result = prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '');
 | 
					            const result = prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '');
 | 
				
			||||||
            return result;
 | 
					            return result;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user