forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempting to modify the markdig markdown engine to process special t…
…ags inside the triple-slash comments ... but can't get it to work so will revert back to dfm, just keeping this here for history
- Loading branch information
Showing
21 changed files
with
386 additions
and
142 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Markdig.Parsers; | ||
using Markdig.Syntax; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalBlock : LeafBlock | ||
{ | ||
public string MatchType { get; } | ||
|
||
public LuceneExperimentalBlock(BlockParser parser, string matchType) : base(parser) | ||
{ | ||
MatchType = matchType; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalBlockParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Markdig.Parsers; | ||
using Markdig.Syntax.Inlines; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
//TODO: Make an inline parser and see if that works | ||
|
||
public class LuceneExperimentalBlockParser : BlockParser | ||
{ | ||
|
||
public LuceneExperimentalBlockParser() | ||
{ | ||
OpeningCharacters = new[] { '@' }; | ||
} | ||
|
||
public override BlockState TryOpen(BlockProcessor processor) | ||
{ | ||
if (processor.IsCodeIndent) | ||
{ | ||
return BlockState.None; | ||
} | ||
|
||
var line = processor.Line; | ||
|
||
var matchType = TagMatcher.GetMatch(line); | ||
|
||
if (matchType == null) | ||
return BlockState.None; | ||
|
||
var luceneExperimentalBlock = new LuceneExperimentalBlock(this, matchType); | ||
|
||
processor.NewBlocks.Push(luceneExperimentalBlock); | ||
|
||
return BlockState.BreakDiscard; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalBlockRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Html; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalBlockRenderer : HtmlObjectRenderer<LuceneExperimentalBlock> | ||
{ | ||
private const string Message = "This is a Lucene.NET {0} API, use at your own risk"; | ||
|
||
protected override void Write(HtmlRenderer renderer, LuceneExperimentalBlock inclusion) | ||
{ | ||
renderer.Write("<div class=\"lucene-block lucene-" + inclusion.MatchType.ToLower() + "\">" + string.Format(Message, inclusion.MatchType.ToUpper()) + "</div>"); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalInline.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Markdig.Syntax.Inlines; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalInline : LeafInline | ||
{ | ||
public string MatchType { get; } | ||
|
||
public LuceneExperimentalInline(string matchType) | ||
{ | ||
MatchType = matchType; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalInlineParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Markdig.Helpers; | ||
using Markdig.Parsers; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalInlineParser : InlineParser | ||
{ | ||
public LuceneExperimentalInlineParser() | ||
{ | ||
OpeningCharacters = new[] { '@' }; | ||
} | ||
|
||
public override bool Match(InlineProcessor processor, ref StringSlice slice) | ||
{ | ||
var matchType = TagMatcher.GetMatch(slice); | ||
|
||
if (matchType == null) | ||
return false; | ||
|
||
var luceneExperimentalInline = new LuceneExperimentalInline(matchType); | ||
|
||
processor.Inline = luceneExperimentalInline; | ||
return true; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalInlineRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Markdig.Renderers; | ||
using Markdig.Renderers.Html; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalInlineRenderer : HtmlObjectRenderer<LuceneExperimentalInline> | ||
{ | ||
private const string Message = "This is a Lucene.NET {0} API, use at your own risk"; | ||
|
||
protected override void Write(HtmlRenderer renderer, LuceneExperimentalInline inclusion) | ||
{ | ||
renderer.Write("<div class=\"lucene-block lucene-" + inclusion.MatchType.ToLower() + "\">" + string.Format(Message, inclusion.MatchType.ToUpper()) + "</div>"); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneExperimentalMarkdownExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Markdig; | ||
using Markdig.Renderers; | ||
using Microsoft.DocAsCode.MarkdigEngine.Extensions; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneExperimentalMarkdownExtension : IMarkdownExtension | ||
{ | ||
public void Setup(MarkdownPipelineBuilder pipeline) | ||
{ | ||
pipeline.BlockParsers.Insert(0, new LuceneExperimentalBlockParser()); | ||
pipeline.InlineParsers.Insert(0, new LuceneExperimentalInlineParser()); | ||
|
||
//pipeline.BlockParsers.AddIfNotAlready<LuceneExperimentalBlockParser>(); | ||
//pipeline.InlineParsers.AddIfNotAlready<LuceneExperimentalInlineParser>(); | ||
} | ||
|
||
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) | ||
{ | ||
if (!(renderer is HtmlRenderer htmlRenderer)) return; | ||
|
||
if (!htmlRenderer.ObjectRenderers.Contains<LuceneExperimentalBlockRenderer>()) | ||
{ | ||
htmlRenderer.ObjectRenderers.Insert(0, new LuceneExperimentalBlockRenderer()); | ||
} | ||
|
||
if (!htmlRenderer.ObjectRenderers.Contains<LuceneExperimentalInlineRenderer>()) | ||
{ | ||
htmlRenderer.ObjectRenderers.Insert(0, new LuceneExperimentalInlineRenderer()); | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneMarkdigExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Markdig; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public static class LuceneMarkdigExtensions | ||
{ | ||
public static MarkdownPipelineBuilder UseLuceneExperimental(this MarkdownPipelineBuilder pipeline) | ||
{ | ||
var extensions = pipeline.Extensions; | ||
if (!extensions.Contains<LuceneExperimentalMarkdownExtension>()) | ||
{ | ||
extensions.Insert(0, new LuceneExperimentalMarkdownExtension()); | ||
} | ||
return pipeline; | ||
} | ||
|
||
public static MarkdownPipeline UseLuceneExperimental(this MarkdownPipeline pipeline) | ||
{ | ||
var extensions = pipeline.Extensions; | ||
if (!extensions.Contains<LuceneExperimentalMarkdownExtension>()) | ||
{ | ||
extensions.Insert(0, new LuceneExperimentalMarkdownExtension()); | ||
} | ||
return pipeline; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneMarkdigServiceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Composition; | ||
using Microsoft.DocAsCode.MarkdigEngine; | ||
using Microsoft.DocAsCode.Plugins; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
[Export("markdig-custom", typeof(IMarkdownServiceProvider))] | ||
public class LuceneMarkdigServiceProvider : IMarkdownServiceProvider | ||
{ | ||
[Import] | ||
public ICompositionContainer Container { get; set; } | ||
|
||
public IMarkdownService CreateMarkdownService(MarkdownServiceParameters parameters) | ||
{ | ||
return new LuceneMarkdownService(parameters, this.Container); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneMarkdownService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Markdig; | ||
using Microsoft.DocAsCode.Common; | ||
using Microsoft.DocAsCode.MarkdigEngine; | ||
using Microsoft.DocAsCode.MarkdigEngine.Extensions; | ||
using Microsoft.DocAsCode.Plugins; | ||
|
||
namespace LuceneDocsPlugins | ||
{ | ||
public class LuceneMarkdownService : MarkdigMarkdownService, IMarkdownService | ||
{ | ||
public LuceneMarkdownService(MarkdownServiceParameters parameters, ICompositionContainer container = null) | ||
: base(parameters, container) | ||
{ | ||
} | ||
|
||
string IMarkdownService.Name => "markdig-custom"; | ||
|
||
MarkupResult IMarkdownService.Markup(string content, string filePath) | ||
{ | ||
return this.Markup(content, filePath, false); | ||
} | ||
|
||
MarkupResult IMarkdownService.Markup(string content, string filePath, bool enableValidation) | ||
{ | ||
if (content == null) | ||
throw new ArgumentNullException(nameof(content)); | ||
if (filePath == null) | ||
throw new ArgumentException("file path can't be null or empty."); | ||
|
||
//TODO: Need to use reflection here because of how docfx is structured right now | ||
var markdownPipeline = (MarkdownPipeline)ReflectionHelper.CallMethod(this, "CreateMarkdownPipeline", false, enableValidation); | ||
//Add our extesions directly to the MarkdownPipeline (they don't need to be added to the MarkdownPipelineBuilder | ||
markdownPipeline.UseLuceneExperimental(); | ||
|
||
using (InclusionContext.PushFile((RelativePath)filePath)) | ||
return new MarkupResult() | ||
{ | ||
Html = Markdown.ToHtml(content, markdownPipeline), | ||
Dependency = InclusionContext.Dependencies.Select(file => (string)(RelativePath)file).ToImmutableArray() | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.