@@ -69,101 +69,102 @@ function toYouTubeEmbedURL(link: string) {
6969 }
7070}
7171
72- export const Mindmap : QuartzTransformerPlugin < Partial < Options > > = ( userOpts ) => {
73- const opts = { ...defaultOptions , ...userOpts }
72+ const transformer = new Transformer ( [
73+ ...builtInPlugins ,
74+ ] )
7475
75- return {
76- name : "Mindmap" ,
77- markdownPlugins ( ctx ) {
78- const transformer = new Transformer ( [
79- ... builtInPlugins ,
80- ] )
81- const transformOptions : TransformOptions = {
82- strategy : opts . markdownLinkResolution ,
83- allSlugs : ctx . allSlugs ,
76+ function wikilinkReplacement ( currentSlug : FullSlug , transformOptions : TransformOptions ) {
77+ return ( match : RegExpExecArray ) => {
78+ const { link , fragment , displayText , tag } = match . groups !
79+
80+ if ( link ) {
81+ let url = transformLink ( currentSlug , encodeURI ( decode ( link . trim ( ) + ( fragment ? "#" + fragment . trim ( ) : "" ) ) ) , transformOptions )
82+
83+ if ( match [ 1 ] !== "!" ) {
84+ return `<a href=" ${ url } " class="internal"> ${ displayText || link + ( fragment ? "#" + fragment : "" ) } </a>`
8485 }
8586
86- function wikilinkReplacement ( currentSlug : FullSlug ) {
87- return ( match : RegExpExecArray ) => {
88- const { link, fragment, displayText, tag } = match . groups !
89-
90- if ( link ) {
91- let url = transformLink ( currentSlug , encodeURI ( decode ( link . trim ( ) + ( fragment ? "#" + fragment . trim ( ) : "" ) ) ) , transformOptions )
92-
93- if ( match [ 1 ] !== "!" ) {
94- return `<a href="${ url } " class="internal">${ displayText || link + ( fragment ? "#" + fragment : "" ) } </a>`
95- }
96-
97- if ( / \. ( p n g | j p g | j p e g | g i f | b m p | s v g | w e b p ) $ / . test ( link ) ) {
98- if ( fragment ) {
99- url = transformLink ( currentSlug , encodeURI ( decode ( link . trim ( ) ) ) , transformOptions )
100- }
101- const imageEmbedMatch = imageEmbedRegex . exec ( displayText || "" )
102- const width = imageEmbedMatch ?. groups ?. width ? imageEmbedMatch ?. groups ?. width + "px" : "auto"
103- const height = imageEmbedMatch ?. groups ?. height ? imageEmbedMatch ?. groups ?. height + "px" : "auto"
104- return `<img src="${ url } " alt="${ fragment ?? displayText ?? link } " style="height:${ height } ; width:${ width } ; max-width: 640px;" />`
105- } else if ( / \. ( m p 4 | w e b m | o g v | a v i | m o v | f l v | w m v | m k v | m p g | m p e g | m 4 v ) $ / . test ( link ) ) {
106- return `<video src="${ url } " controls></video>`
107- } else if ( / \. ( m p 3 | w a v | m 4 a | o g g | 3 g p | f l a c ) $ / . test ( link ) ) {
108- return `<audio src="${ url } " controls style="width: 640px;"></audio>`
109- } else if ( / \. ( p d f ) $ / . test ( link ) ) {
110- return `<iframe src="${ url } " class="pdf" style="width: 860px;"></iframe>`
111- }
112-
113- return `<a href="${ url } " class="internal">${ displayText || link } </a>`
114- } else if ( tag ) {
115- return `<a href="/tags/${ tag } " class="internal">#${ tag } </a>`
116- }
117- return match [ 0 ]
87+ if ( / \. ( p n g | j p g | j p e g | g i f | b m p | s v g | w e b p ) $ / . test ( link ) ) {
88+ if ( fragment ) {
89+ url = transformLink ( currentSlug , encodeURI ( decode ( link . trim ( ) ) ) , transformOptions )
11890 }
91+ const imageEmbedMatch = imageEmbedRegex . exec ( displayText || "" )
92+ const width = imageEmbedMatch ?. groups ?. width ? imageEmbedMatch ?. groups ?. width + "px" : "auto"
93+ const height = imageEmbedMatch ?. groups ?. height ? imageEmbedMatch ?. groups ?. height + "px" : "auto"
94+ return `<img src="${ url } " alt="${ fragment ?? displayText ?? link } " style="height:${ height } ; width:${ width } ; max-width: 640px;" />`
95+ } else if ( / \. ( m p 4 | w e b m | o g v | a v i | m o v | f l v | w m v | m k v | m p g | m p e g | m 4 v ) $ / . test ( link ) ) {
96+ return `<video src="${ url } " controls></video>`
97+ } else if ( / \. ( m p 3 | w a v | m 4 a | o g g | 3 g p | f l a c ) $ / . test ( link ) ) {
98+ return `<audio src="${ url } " controls style="width: 640px;"></audio>`
99+ } else if ( / \. ( p d f ) $ / . test ( link ) ) {
100+ return `<iframe src="${ url } " class="pdf" style="width: 860px;"></iframe>`
119101 }
120102
121- function ytLinkReplacement ( ) {
122- return ( match : RegExpExecArray ) => {
123- if ( match [ 1 ] ) {
124- const embedUrl = toYouTubeEmbedURL ( match [ 1 ] )
125- if ( embedUrl ) {
126- return `
103+ return `<a href="${ url } " class="internal">${ displayText || link } </a>`
104+ } else if ( tag ) {
105+ return `<a href="/tags/${ tag } " class="internal">#${ tag } </a>`
106+ }
107+ return match [ 0 ]
108+ }
109+ }
110+
111+ function ytLinkReplacement ( ) {
112+ return ( match : RegExpExecArray ) => {
113+ if ( match [ 1 ] ) {
114+ const embedUrl = toYouTubeEmbedURL ( match [ 1 ] )
115+ if ( embedUrl ) {
116+ return `
127117 <iframe
128118 class="external-embed youtube"
129119 allow="fullscreen"
130120 frameborder="0"
131121 src="${ embedUrl } ">
132122 </iframe>
133123 `
134- }
135- }
136- return match [ 0 ]
137- }
138124 }
125+ }
126+ return match [ 0 ]
127+ }
128+ }
139129
140- function calloutReplacement ( ) {
141- return ( match : RegExpExecArray ) => {
142- const { type, remain } = match . groups !
130+ function calloutReplacement ( ) {
131+ return ( match : RegExpExecArray ) => {
132+ const { type, remain } = match . groups !
143133
144- if ( type ) {
145- const typeClass = canonicalizeCallout ( type . toLowerCase ( ) )
146- const contents = remain . replace ( / < b r \s * \/ ? > / g, "" )
147- return `
134+ if ( type ) {
135+ const typeClass = canonicalizeCallout ( type . toLowerCase ( ) )
136+ const contents = remain . replace ( / < b r \s * \/ ? > / g, "" )
137+ return `
148138 <blockquote class="callout ${ typeClass } " data-callout="${ typeClass } " style="max-width: 640px; width: auto;">
149139 <div class="callout-title">
150140 <div class="callout-icon"></div>
151141 <div class="callout-title-inner"><p>${ type } </p></div>
152142 </div>
153143 ${ contents ?
154- `
144+ `
155145 <div class="callout-content">
156146 <div class="callout-content-inner">
157147 <p>${ contents } </p>
158148 </div>
159149 </div>
160150 `
161- : "" }
151+ : "" }
162152 </blockquote>
163153 `
164- }
165- return match [ 0 ]
166- }
154+ }
155+ return match [ 0 ]
156+ }
157+ }
158+
159+ export const Mindmap : QuartzTransformerPlugin < Partial < Options > > = ( userOpts ) => {
160+ const opts = { ...defaultOptions , ...userOpts }
161+
162+ return {
163+ name : "Mindmap" ,
164+ markdownPlugins ( ctx ) {
165+ const transformOptions : TransformOptions = {
166+ strategy : opts . markdownLinkResolution ,
167+ allSlugs : ctx . allSlugs ,
167168 }
168169
169170 function processMindmapFile ( file : any , transformer : Transformer , slug : FullSlug ) {
@@ -173,18 +174,18 @@ export const Mindmap: QuartzTransformerPlugin<Partial<Options>> = (userOpts) =>
173174 node . content = replaceMatches (
174175 node . content ,
175176 wikilinkRegex ,
176- wikilinkReplacement ( slug )
177- )
178- node . content = replaceMatches (
179- node . content ,
180- youtubeImageRegex ,
181- ytLinkReplacement ( )
182- )
183- node . content = replaceMatches (
184- node . content ,
185- calloutRegex ,
186- calloutReplacement ( )
177+ wikilinkReplacement ( slug , transformOptions )
187178 )
179+ // node.content = replaceMatches(
180+ // node.content,
181+ // youtubeImageRegex,
182+ // ytLinkReplacement()
183+ // )
184+ // node.content = replaceMatches(
185+ // node.content,
186+ // calloutRegex,
187+ // calloutReplacement()
188+ // )
188189 } ) ( root )
189190
190191 file . data . mindmap = root
0 commit comments