@@ -190,11 +190,11 @@ void AppendSnippet(string key1)
190190 line . Current = builder . ToString ( ) ;
191191 }
192192
193- void AppendWebSnippet ( string url , string snippetKey )
193+ void AppendWebSnippet ( string url , string snippetKey , string ? viewUrl = null )
194194 {
195195 builder . Clear ( ) ;
196196 var indentedAppendLine = CreateIndentedAppendLine ( line . LeadingWhitespace ) ;
197- ProcessWebSnippetLine ( indentedAppendLine , missingSnippets , usedSnippets , url , snippetKey , line ) ;
197+ ProcessWebSnippetLine ( indentedAppendLine , missingSnippets , usedSnippets , url , snippetKey , viewUrl , line ) ;
198198 builder . TrimEnd ( ) ;
199199 line . Current = builder . ToString ( ) ;
200200 }
@@ -205,9 +205,9 @@ void AppendWebSnippet(string url, string snippetKey)
205205 continue ;
206206 }
207207
208- if ( SnippetKey . ExtractWebSnippet ( line , out var url , out var snippetKey ) )
208+ if ( SnippetKey . ExtractWebSnippet ( line , out var url , out var snippetKey , out var viewUrl ) )
209209 {
210- AppendWebSnippet ( url , snippetKey ) ;
210+ AppendWebSnippet ( url , snippetKey , viewUrl ) ;
211211 continue ;
212212 }
213213
@@ -230,9 +230,9 @@ void AppendWebSnippet(string url, string snippetKey)
230230 continue ;
231231 }
232232
233- if ( SnippetKey . ExtractStartCommentWebSnippet ( line , out url , out snippetKey ) )
233+ if ( SnippetKey . ExtractStartCommentWebSnippet ( line , out url , out snippetKey , out viewUrl ) )
234234 {
235- AppendWebSnippet ( url , snippetKey ) ;
235+ AppendWebSnippet ( url , snippetKey , viewUrl ) ;
236236
237237 index ++ ;
238238
@@ -312,9 +312,12 @@ void ProcessSnippetLine(Action<string> appendLine, List<MissingSnippet> missings
312312 appendLine ( "<!-- endSnippet -->" ) ;
313313 }
314314
315- void ProcessWebSnippetLine ( Action < string > appendLine , List < MissingSnippet > missings , List < Snippet > used , string url , string snippetKey , Line line )
315+ void ProcessWebSnippetLine ( Action < string > appendLine , List < MissingSnippet > missings , List < Snippet > used , string url , string snippetKey , string ? viewUrl , Line line )
316316 {
317- appendLine ( $ "<!-- web-snippet: { url } #{ snippetKey } -->") ;
317+ var commentText = viewUrl == null
318+ ? $ "<!-- web-snippet: { url } #{ snippetKey } -->"
319+ : $ "<!-- web-snippet: { url } #{ snippetKey } { viewUrl } -->";
320+ appendLine ( commentText ) ;
318321 // Download file content
319322 try
320323 {
@@ -343,9 +346,21 @@ void ProcessWebSnippetLine(Action<string> appendLine, List<MissingSnippet> missi
343346 appendLine ( "<!-- endSnippet -->" ) ;
344347 return ;
345348 }
346- appendSnippets ( snippetKey , [ found ] , appendLine ) ;
349+ // Create new snippet with viewUrl if provided
350+ var snippetToAppend = viewUrl == null
351+ ? found
352+ : Snippet . Build (
353+ language : found . Language ,
354+ startLine : found . StartLine ,
355+ endLine : found . EndLine ,
356+ value : found . Value ,
357+ key : found . Key ,
358+ path : found . Path ,
359+ expressiveCode : found . ExpressiveCode ,
360+ viewUrl : viewUrl ) ;
361+ appendSnippets ( snippetKey , [ snippetToAppend ] , appendLine ) ;
347362 appendLine ( "<!-- endSnippet -->" ) ;
348- used . Add ( found ) ;
363+ used . Add ( snippetToAppend ) ;
349364 }
350365 catch
351366 {
0 commit comments