File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed
Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -102,10 +102,7 @@ export interface ViewerProps {
102102 /**
103103 * Customize the default sanitize schema
104104 *
105- * Defaults to GitHub style sanitation except:
106- *
107- * 1. `className` is allowed
108- * 2. `id` is kept as is without clobbering
105+ * Defaults to GitHub style sanitation except the `className` property is allowed
109106 *
110107 * https://github.com/syntax-tree/hast-util-sanitize/blob/main/lib/github.json
111108 */
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ export function getProcessor({
2727
2828 let schema = JSON . parse ( schemaStr ) as Schema ;
2929 schema . attributes ! [ '*' ] . push ( 'className' ) ; // Add className
30- schema . clobber = schema . clobber ! . filter ( ( vs ) => vs !== 'id' ) ; // Keep id as is
3130 if ( sanitize ) schema = sanitize ( schema ) ;
3231
3332 p = p . use ( rehypeSanitize , schema ) ;
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import type { BytemdPlugin , ViewerProps } from ' ./types' ;
3- import { tick , onDestroy } from ' svelte' ;
3+ import { tick , onDestroy , onMount } from ' svelte' ;
44 import { getProcessor } from ' ./utils' ;
55
66 export let value: ViewerProps [' value' ] = ' ' ;
1717 cbs .forEach ((cb ) => cb && cb ());
1818 }
1919
20+ onMount (() => {
21+ el .addEventListener (' click' , (e ) => {
22+ const $ = e .target as HTMLElement ;
23+ if ($ .tagName !== ' A' ) return ;
24+
25+ const href = $ .getAttribute (' href' );
26+ if (! href ?.startsWith (' #' )) return ;
27+
28+ el .querySelector (' #user-content-' + href .slice (1 ))?.scrollIntoView ();
29+ });
30+ });
31+
2032 onDestroy (off );
2133 $ : result = getProcessor ({ plugins , sanitize }).processSync (value );
2234 $ : if (result && plugins ) {
You can’t perform that action at this time.
0 commit comments