mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	Merge pull request #3897 from contributor/feature/ZipExportDocumentTitle
zip export/import improvements
This commit is contained in:
		
						commit
						0ab18e3069
					
				@ -248,6 +248,7 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
 | 
				
			|||||||
        if (noteMeta.format === 'html') {
 | 
					        if (noteMeta.format === 'html') {
 | 
				
			||||||
            if (!content.substr(0, 100).toLowerCase().includes("<html")) {
 | 
					            if (!content.substr(0, 100).toLowerCase().includes("<html")) {
 | 
				
			||||||
                const cssUrl = `${"../".repeat(noteMeta.notePath.length - 1)}style.css`;
 | 
					                const cssUrl = `${"../".repeat(noteMeta.notePath.length - 1)}style.css`;
 | 
				
			||||||
 | 
					                const htmlTitle = utils.escapeHtml(title);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // <base> element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809
 | 
					                // <base> element will make sure external links are openable - https://github.com/zadam/trilium/issues/1289#issuecomment-704066809
 | 
				
			||||||
                content = `<html>
 | 
					                content = `<html>
 | 
				
			||||||
@ -256,10 +257,11 @@ async function exportToZip(taskContext, branch, format, res, setHeaders = true)
 | 
				
			|||||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
				
			||||||
    <link rel="stylesheet" href="${cssUrl}">
 | 
					    <link rel="stylesheet" href="${cssUrl}">
 | 
				
			||||||
    <base target="_parent">
 | 
					    <base target="_parent">
 | 
				
			||||||
 | 
					    <title data-trilium-title>${htmlTitle}</title>
 | 
				
			||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body>
 | 
					<body>
 | 
				
			||||||
  <div class="content">
 | 
					  <div class="content">
 | 
				
			||||||
      <h1>${utils.escapeHtml(title)}</h1>
 | 
					      <h1 data-trilium-h1>${htmlTitle}</h1>
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
      <div class="ck-content">${content}</div>
 | 
					      <div class="ck-content">${content}</div>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
@ -415,7 +417,7 @@ ${markdownContent}`;
 | 
				
			|||||||
    const rootMeta = getNoteMeta(branch, { notePath: [] }, existingFileNames);
 | 
					    const rootMeta = getNoteMeta(branch, { notePath: [] }, existingFileNames);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const metaFile = {
 | 
					    const metaFile = {
 | 
				
			||||||
        formatVersion: 1,
 | 
					        formatVersion: 2,
 | 
				
			||||||
        appVersion: packageInfo.version,
 | 
					        appVersion: packageInfo.version,
 | 
				
			||||||
        files: [ rootMeta ]
 | 
					        files: [ rootMeta ]
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
				
			|||||||
@ -240,6 +240,8 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
 | 
				
			|||||||
            return /^(?:[a-z]+:)?\/\//i.test(url);
 | 
					            return /^(?:[a-z]+:)?\/\//i.test(url);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        content = removeTrilumTags(content);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        content = content.replace(/<h1>([^<]*)<\/h1>/gi, (match, text) => {
 | 
					        content = content.replace(/<h1>([^<]*)<\/h1>/gi, (match, text) => {
 | 
				
			||||||
            if (noteTitle.trim() === text.trim()) {
 | 
					            if (noteTitle.trim() === text.trim()) {
 | 
				
			||||||
                return ""; // remove whole H1 tag
 | 
					                return ""; // remove whole H1 tag
 | 
				
			||||||
@ -325,6 +327,18 @@ async function importZip(taskContext, fileBuffer, importRootNote) {
 | 
				
			|||||||
        return content;
 | 
					        return content;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function removeTrilumTags(content) {
 | 
				
			||||||
 | 
					        const tagsToRemove = [
 | 
				
			||||||
 | 
					            '<h1 data-trilium-h1>([^<]*)<\/h1>',
 | 
				
			||||||
 | 
					            '<title data-trilium-title>([^<]*)<\/title>'
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        for (const tag of tagsToRemove) { 
 | 
				
			||||||
 | 
					            let re = new RegExp(tag, "gi");
 | 
				
			||||||
 | 
					            content = content.replace(re, '');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return content;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function processNoteContent(noteMeta, type, mime, content, noteTitle, filePath) {
 | 
					    function processNoteContent(noteMeta, type, mime, content, noteTitle, filePath) {
 | 
				
			||||||
        if (noteMeta?.format === 'markdown'
 | 
					        if (noteMeta?.format === 'markdown'
 | 
				
			||||||
            || (!noteMeta && taskContext.data.textImportedAsText && ['text/markdown', 'text/x-markdown'].includes(mime))) {
 | 
					            || (!noteMeta && taskContext.data.textImportedAsText && ['text/markdown', 'text/x-markdown'].includes(mime))) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user