Compare commits
	
		
			1 Commits
		
	
	
		
			v0.3.4
			...
			43e15a90a9
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 43e15a90a9 | 
							
								
								
									
										33
									
								
								src/embed.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/embed.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | |||||||
|  |  | ||||||
|  | import type { marked } from 'marked'; | ||||||
|  | import { MarkdownOptions } from './render'; | ||||||
|  |  | ||||||
|  | export interface EmbedToken extends marked.Tokens.Generic { | ||||||
|  | 	media_type: string; | ||||||
|  | 	href: string; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function embed_ext(renderer: marked.Renderer, opts: MarkdownOptions) : marked.TokenizerExtension & marked.RendererExtension { | ||||||
|  | 	return { | ||||||
|  | 		name: 'embed', | ||||||
|  | 		level: 'inline', | ||||||
|  | 		start: (src) => src.match(/\{&/)?.index, | ||||||
|  | 		tokenizer(src, tokens) { | ||||||
|  | 			const rule = /^\{&\s+([^\s]+):\s*([^\s]+)\s+&\}/; | ||||||
|  | 			const match = rule.exec(src); | ||||||
|  |  | ||||||
|  | 			if (match) { | ||||||
|  | 				return { | ||||||
|  | 					type: 'embed', | ||||||
|  | 					raw: match[0], | ||||||
|  | 					media_type: match[1], | ||||||
|  | 					href: match[2], | ||||||
|  | 					tokens: [ ] | ||||||
|  | 				}; | ||||||
|  | 			} | ||||||
|  | 		}, | ||||||
|  | 		renderer(token: EmbedToken) { | ||||||
|  | 			return `<embed type="${token.media_type}" src="${token.href}"></embed>`; | ||||||
|  | 		} | ||||||
|  | 	}; | ||||||
|  | } | ||||||
| @@ -9,5 +9,6 @@ export function sanitize_html(html: string, custom_elements?: CustomElementHandl | |||||||
| 	const dom_purify = createDOMPurify(window as any as Window); | 	const dom_purify = createDOMPurify(window as any as Window); | ||||||
| 	return dom_purify.sanitize(html, { | 	return dom_purify.sanitize(html, { | ||||||
| 		CUSTOM_ELEMENT_HANDLING: custom_elements, | 		CUSTOM_ELEMENT_HANDLING: custom_elements, | ||||||
|  | 		ADD_TAGS: [ 'embed', 'object', 'video', 'audio', 'iframe' ], | ||||||
| 	}); | 	}); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import { footnote_list_ext, footnote_ref_ext } from './footnotes'; | |||||||
| import { description_list_ext } from './description-list'; | import { description_list_ext } from './description-list'; | ||||||
| import { resolve_async_bindings } from './async-steps'; | import { resolve_async_bindings } from './async-steps'; | ||||||
| import { base_url_walk_tokens } from './base-url'; | import { base_url_walk_tokens } from './base-url'; | ||||||
|  | import { embed_ext } from './embed'; | ||||||
|  |  | ||||||
| export interface MarkdownOptions { | export interface MarkdownOptions { | ||||||
| 	base_url?: string; | 	base_url?: string; | ||||||
| @@ -64,6 +65,7 @@ function setup_marked(options: MarkdownOptions, marked_options: marked.MarkedOpt | |||||||
| 			description_list_ext(marked_options.renderer, options), | 			description_list_ext(marked_options.renderer, options), | ||||||
| 			section_ext(marked_options.renderer, options), | 			section_ext(marked_options.renderer, options), | ||||||
| 			icon_ext(marked_options.renderer, options), | 			icon_ext(marked_options.renderer, options), | ||||||
|  | 			embed_ext(marked_options.renderer, options), | ||||||
| 			...(options.extensions || [ ]).map((ext) => { | 			...(options.extensions || [ ]).map((ext) => { | ||||||
| 				return ext(marked_options.renderer, options); | 				return ext(marked_options.renderer, options); | ||||||
| 			}), | 			}), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user