mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	chore(share): bring back syntax highlight
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Checks / main (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Checks / main (push) Has been cancelled
				
			This commit is contained in:
		
							parent
							
								
									12df6a0d6e
								
							
						
					
					
						commit
						14b8d0a47e
					
				| @ -36,6 +36,7 @@ | |||||||
|     "@triliumnext/commons": "workspace:*", |     "@triliumnext/commons": "workspace:*", | ||||||
|     "@triliumnext/express-partial-content": "workspace:*", |     "@triliumnext/express-partial-content": "workspace:*", | ||||||
|     "@triliumnext/turndown-plugin-gfm": "workspace:*", |     "@triliumnext/turndown-plugin-gfm": "workspace:*", | ||||||
|  |     "@triliumnext/highlightjs": "workspace:*", | ||||||
|     "@types/archiver": "6.0.3", |     "@types/archiver": "6.0.3", | ||||||
|     "@types/better-sqlite3": "7.6.13", |     "@types/better-sqlite3": "7.6.13", | ||||||
|     "@types/cls-hooked": "4.3.9", |     "@types/cls-hooked": "4.3.9", | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| import { parse, HTMLElement, TextNode } from "node-html-parser"; | import { parse, HTMLElement, TextNode, Options } from "node-html-parser"; | ||||||
| import shaca from "./shaca/shaca.js"; | import shaca from "./shaca/shaca.js"; | ||||||
| import assetPath, { assetUrlFragment } from "../services/asset_path.js"; | import assetPath, { assetUrlFragment } from "../services/asset_path.js"; | ||||||
| import shareRoot from "./share_root.js"; | import shareRoot from "./share_root.js"; | ||||||
| @ -14,6 +14,7 @@ import ejs from "ejs"; | |||||||
| import log from "../services/log.js"; | import log from "../services/log.js"; | ||||||
| import { join } from "path"; | import { join } from "path"; | ||||||
| import { readFileSync } from "fs"; | import { readFileSync } from "fs"; | ||||||
|  | import { highlightAuto } from "@triliumnext/highlightjs"; | ||||||
| 
 | 
 | ||||||
| const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`; | const shareAdjustedAssetPath = isDev ? assetPath : `../${assetPath}`; | ||||||
| const templateCache: Map<string, string> = new Map(); | const templateCache: Map<string, string> = new Map(); | ||||||
| @ -264,7 +265,10 @@ function renderIndex(result: Result) { | |||||||
| 
 | 
 | ||||||
| function renderText(result: Result, note: SNote | BNote) { | function renderText(result: Result, note: SNote | BNote) { | ||||||
|     if (typeof result.content !== "string") return; |     if (typeof result.content !== "string") return; | ||||||
|     const document = parse(result.content || ""); |     const parseOpts: Partial<Options> = { | ||||||
|  |         blockTextElements: {} | ||||||
|  |     } | ||||||
|  |     const document = parse(result.content || "", parseOpts); | ||||||
| 
 | 
 | ||||||
|     // Process include notes.
 |     // Process include notes.
 | ||||||
|     for (const includeNoteEl of document.querySelectorAll("section.include-note")) { |     for (const includeNoteEl of document.querySelectorAll("section.include-note")) { | ||||||
| @ -277,7 +281,7 @@ function renderText(result: Result, note: SNote | BNote) { | |||||||
|         const includedResult = getContent(note); |         const includedResult = getContent(note); | ||||||
|         if (typeof includedResult.content !== "string") continue; |         if (typeof includedResult.content !== "string") continue; | ||||||
| 
 | 
 | ||||||
|         const includedDocument = parse(includedResult.content).childNodes; |         const includedDocument = parse(includedResult.content, parseOpts).childNodes; | ||||||
|         if (includedDocument) { |         if (includedDocument) { | ||||||
|             includeNoteEl.replaceWith(...includedDocument); |             includeNoteEl.replaceWith(...includedDocument); | ||||||
|         } |         } | ||||||
| @ -286,6 +290,7 @@ function renderText(result: Result, note: SNote | BNote) { | |||||||
|     result.isEmpty = document.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0; |     result.isEmpty = document.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0; | ||||||
| 
 | 
 | ||||||
|     if (!result.isEmpty) { |     if (!result.isEmpty) { | ||||||
|  |         // Process attachment links.
 | ||||||
|         for (const linkEl of document.querySelectorAll("a")) { |         for (const linkEl of document.querySelectorAll("a")) { | ||||||
|             const href = linkEl.getAttribute("href"); |             const href = linkEl.getAttribute("href"); | ||||||
| 
 | 
 | ||||||
| @ -299,6 +304,13 @@ function renderText(result: Result, note: SNote | BNote) { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // Apply syntax highlight.
 | ||||||
|  |         for (const codeEl of document.querySelectorAll("pre code")) { | ||||||
|  |             const highlightResult = highlightAuto(codeEl.innerText); | ||||||
|  |             codeEl.innerHTML = highlightResult.value; | ||||||
|  |             codeEl.classList.add("hljs"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         result.content = document.innerHTML ?? ""; |         result.content = document.innerHTML ?? ""; | ||||||
| 
 | 
 | ||||||
|         if (note.hasLabel("shareIndex")) { |         if (note.hasLabel("shareIndex")) { | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import setupMermaid from "./modules/mermaid"; | |||||||
| import setupMath from "./modules/math"; | import setupMath from "./modules/math"; | ||||||
| import api from "./modules/api"; | import api from "./modules/api"; | ||||||
| import "boxicons/css/boxicons.min.css"; | import "boxicons/css/boxicons.min.css"; | ||||||
|  | import "highlight.js/styles/default.css"; | ||||||
| 
 | 
 | ||||||
| function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) { | function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) { | ||||||
|     try { |     try { | ||||||
|  | |||||||
							
								
								
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							| @ -480,6 +480,9 @@ importers: | |||||||
|       '@triliumnext/express-partial-content': |       '@triliumnext/express-partial-content': | ||||||
|         specifier: workspace:* |         specifier: workspace:* | ||||||
|         version: link:../../packages/express-partial-content |         version: link:../../packages/express-partial-content | ||||||
|  |       '@triliumnext/highlightjs': | ||||||
|  |         specifier: workspace:* | ||||||
|  |         version: link:../../packages/highlightjs | ||||||
|       '@triliumnext/turndown-plugin-gfm': |       '@triliumnext/turndown-plugin-gfm': | ||||||
|         specifier: workspace:* |         specifier: workspace:* | ||||||
|         version: link:../../packages/turndown-plugin-gfm |         version: link:../../packages/turndown-plugin-gfm | ||||||
| @ -15103,6 +15106,8 @@ snapshots: | |||||||
|       '@ckeditor/ckeditor5-core': 47.1.0 |       '@ckeditor/ckeditor5-core': 47.1.0 | ||||||
|       '@ckeditor/ckeditor5-utils': 47.1.0 |       '@ckeditor/ckeditor5-utils': 47.1.0 | ||||||
|       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) |       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) | ||||||
|  |     transitivePeerDependencies: | ||||||
|  |       - supports-color | ||||||
| 
 | 
 | ||||||
|   '@ckeditor/ckeditor5-code-block@47.1.0(patch_hash=2361d8caad7d6b5bddacc3a3b4aa37dbfba260b1c1b22a450413a79c1bb1ce95)': |   '@ckeditor/ckeditor5-code-block@47.1.0(patch_hash=2361d8caad7d6b5bddacc3a3b4aa37dbfba260b1c1b22a450413a79c1bb1ce95)': | ||||||
|     dependencies: |     dependencies: | ||||||
| @ -15355,6 +15360,8 @@ snapshots: | |||||||
|       '@ckeditor/ckeditor5-utils': 47.1.0 |       '@ckeditor/ckeditor5-utils': 47.1.0 | ||||||
|       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) |       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) | ||||||
|       es-toolkit: 1.39.5 |       es-toolkit: 1.39.5 | ||||||
|  |     transitivePeerDependencies: | ||||||
|  |       - supports-color | ||||||
| 
 | 
 | ||||||
|   '@ckeditor/ckeditor5-editor-multi-root@47.1.0': |   '@ckeditor/ckeditor5-editor-multi-root@47.1.0': | ||||||
|     dependencies: |     dependencies: | ||||||
| @ -15377,6 +15384,8 @@ snapshots: | |||||||
|       '@ckeditor/ckeditor5-table': 47.1.0 |       '@ckeditor/ckeditor5-table': 47.1.0 | ||||||
|       '@ckeditor/ckeditor5-utils': 47.1.0 |       '@ckeditor/ckeditor5-utils': 47.1.0 | ||||||
|       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) |       ckeditor5: 47.1.0(patch_hash=8331a09d41443b39ea1c784daaccfeb0da4f9065ed556e7de92e9c77edd9eb41) | ||||||
|  |     transitivePeerDependencies: | ||||||
|  |       - supports-color | ||||||
| 
 | 
 | ||||||
|   '@ckeditor/ckeditor5-emoji@47.1.0': |   '@ckeditor/ckeditor5-emoji@47.1.0': | ||||||
|     dependencies: |     dependencies: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran