@@ -13,6 +13,7 @@ namespace Microsoft.DocAsCode.MarkdigEngine.Extensions
13
13
using Markdig . Renderers ;
14
14
using Markdig . Renderers . Html ;
15
15
using Microsoft . DocAsCode . Common ;
16
+ using Microsoft . DocAsCode . Plugins ;
16
17
17
18
public class HtmlCodeSnippetRenderer : HtmlObjectRenderer < CodeSnippet >
18
19
{
@@ -236,16 +237,16 @@ public HtmlCodeSnippetRenderer(IMarkdownEngine engine, MarkdownContext context)
236
237
protected override void Write ( HtmlRenderer renderer , CodeSnippet codeSnippet )
237
238
{
238
239
var refFileRelativePath = ( ( RelativePath ) codeSnippet . CodePath ) . BasedOn ( ( RelativePath ) _context . FilePath ) ;
239
- var refPath = Path . Combine ( _context . BasePath , refFileRelativePath . RemoveWorkingFolder ( ) ) ;
240
- if ( ! File . Exists ( refPath ) )
240
+
241
+ if ( ! EnvironmentContext . FileAbstractLayer . Exists ( refFileRelativePath ) )
241
242
{
242
243
string tag = "ERROR CODESNIPPET" ;
243
244
string message = $ "Unable to find { refFileRelativePath } ";
244
245
ExtensionsHelper . GenerateNodeWithCommentWrapper ( renderer , tag , message , codeSnippet . Raw , codeSnippet . Line ) ;
245
246
return ;
246
247
}
247
-
248
- if ( codeSnippet . DedentLength != null && codeSnippet . DedentLength < 0 )
248
+
249
+ if ( codeSnippet . DedentLength != null && codeSnippet . DedentLength < 0 )
249
250
{
250
251
renderer . Write ( $ "<!-- Dedent length { codeSnippet . DedentLength } should be positive. Auto-dedent will be applied. -->\n ") ;
251
252
}
@@ -262,24 +263,23 @@ private string GetContent(CodeSnippet obj)
262
263
var currentFilePath = ( ( RelativePath ) _context . FilePath ) . GetPathFromWorkingFolder ( ) ;
263
264
var refFileRelativePath = ( ( RelativePath ) obj . CodePath ) . BasedOn ( currentFilePath ) ;
264
265
_engine . ReportDependency ( refFileRelativePath ) ;
265
-
266
+
266
267
var refPath = Path . Combine ( _context . BasePath , refFileRelativePath . RemoveWorkingFolder ( ) ) ;
267
- var allLines = File . ReadAllLines ( refPath ) ;
268
+ var allLines = EnvironmentContext . FileAbstractLayer . ReadAllLines ( refFileRelativePath ) ;
268
269
269
270
// code range priority: tag > #L1 > start/end > range > default
270
271
if ( ! string . IsNullOrEmpty ( obj . TagName ) )
271
272
{
272
273
var lang = obj . Language ?? Path . GetExtension ( refPath ) ;
273
- List < CodeSnippetExtrator > extrators ;
274
- if ( ! CodeLanguageExtractors . TryGetValue ( lang , out extrators ) )
274
+ if ( ! CodeLanguageExtractors . TryGetValue ( lang , out List < CodeSnippetExtrator > extrators ) )
275
275
{
276
276
Logger . LogError ( $ "{ lang } is not supported languaging name, alias or extension for parsing code snippet with tag name, you can use line numbers instead") ;
277
277
}
278
278
279
- if ( extrators != null )
279
+ if ( extrators != null )
280
280
{
281
281
var tagWithPrefix = tagPrefix + obj . TagName ;
282
- foreach ( var extrator in extrators )
282
+ foreach ( var extrator in extrators )
283
283
{
284
284
HashSet < int > tagLines = new HashSet < int > ( ) ;
285
285
var tagToCoderangeMapping = extrator . GetAllTags ( allLines , ref tagLines ) ;
0 commit comments