Skip to content

Commit efb0b00

Browse files
committed
Attempting to modify the markdig markdown engine to process special tags inside the triple-slash comments ... but can't get it to work so will revert back to dfm, just keeping this here for history
1 parent 7ca803a commit efb0b00

21 files changed

+386
-142
lines changed

‎src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎src/docs/LuceneDocsPlugins/LuceneDocsPlugins/LuceneDocsPlugins.csproj‎

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<DebugSymbols>true</DebugSymbols>
2121
<DebugType>full</DebugType>
2222
<Optimize>false</Optimize>
23-
<OutputPath>bin\Debug\</OutputPath>
23+
<OutputPath>..\..\..\..\websites\apidocs\lucenetemplate\plugins\</OutputPath>
2424
<DefineConstants>DEBUG;TRACE</DefineConstants>
2525
<ErrorReport>prompt</ErrorReport>
2626
<WarningLevel>4</WarningLevel>
@@ -37,20 +37,32 @@
3737
<Reference Include="HtmlAgilityPack, Version=1.4.9.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
3838
<HintPath>..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll</HintPath>
3939
</Reference>
40-
<Reference Include="Microsoft.DocAsCode.Common, Version=2.24.0.0, Culture=neutral, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Microsoft.DocAsCode.Common.2.24.0\lib\net461\Microsoft.DocAsCode.Common.dll</HintPath>
40+
<Reference Include="Markdig, Version=0.15.1.0, Culture=neutral, processorArchitecture=MSIL">
41+
<HintPath>..\packages\Markdig.0.15.1\lib\net40\Markdig.dll</HintPath>
4242
</Reference>
43-
<Reference Include="Microsoft.DocAsCode.Dfm, Version=2.24.0.0, Culture=neutral, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Microsoft.DocAsCode.Dfm.2.24.0\lib\net461\Microsoft.DocAsCode.Dfm.dll</HintPath>
43+
<Reference Include="Microsoft.DocAsCode.Common, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
44+
<HintPath>..\packages\Microsoft.DocAsCode.Common.2.38.1\lib\net461\Microsoft.DocAsCode.Common.dll</HintPath>
4545
</Reference>
46-
<Reference Include="Microsoft.DocAsCode.MarkdownLite, Version=2.24.0.0, Culture=neutral, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Microsoft.DocAsCode.MarkdownLite.2.24.0\lib\net461\Microsoft.DocAsCode.MarkdownLite.dll</HintPath>
46+
<Reference Include="Microsoft.DocAsCode.Dfm, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Microsoft.DocAsCode.Dfm.2.38.1\lib\net461\Microsoft.DocAsCode.Dfm.dll</HintPath>
4848
</Reference>
49-
<Reference Include="Microsoft.DocAsCode.Plugins, Version=2.24.0.0, Culture=neutral, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Microsoft.DocAsCode.Plugins.2.24.0\lib\net461\Microsoft.DocAsCode.Plugins.dll</HintPath>
49+
<Reference Include="Microsoft.DocAsCode.MarkdigEngine, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
50+
<HintPath>..\packages\Microsoft.DocAsCode.MarkdigEngine.2.38.1\lib\net461\Microsoft.DocAsCode.MarkdigEngine.dll</HintPath>
5151
</Reference>
52-
<Reference Include="Microsoft.DocAsCode.YamlSerialization, Version=2.24.0.0, Culture=neutral, processorArchitecture=MSIL">
53-
<HintPath>..\packages\Microsoft.DocAsCode.YamlSerialization.2.24.0\lib\net461\Microsoft.DocAsCode.YamlSerialization.dll</HintPath>
52+
<Reference Include="Microsoft.DocAsCode.MarkdigEngine.Extensions, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
53+
<HintPath>..\packages\Microsoft.DocAsCode.MarkdigEngine.Extensions.2.38.1\lib\net461\Microsoft.DocAsCode.MarkdigEngine.Extensions.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Microsoft.DocAsCode.MarkdigEngine.Validators, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
56+
<HintPath>..\packages\Microsoft.DocAsCode.MarkdigEngine.Validators.2.38.1\lib\net461\Microsoft.DocAsCode.MarkdigEngine.Validators.dll</HintPath>
57+
</Reference>
58+
<Reference Include="Microsoft.DocAsCode.MarkdownLite, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
59+
<HintPath>..\packages\Microsoft.DocAsCode.MarkdownLite.2.38.1\lib\net461\Microsoft.DocAsCode.MarkdownLite.dll</HintPath>
60+
</Reference>
61+
<Reference Include="Microsoft.DocAsCode.Plugins, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
62+
<HintPath>..\packages\Microsoft.DocAsCode.Plugins.2.38.1\lib\net461\Microsoft.DocAsCode.Plugins.dll</HintPath>
63+
</Reference>
64+
<Reference Include="Microsoft.DocAsCode.YamlSerialization, Version=2.38.1.0, Culture=neutral, processorArchitecture=MSIL">
65+
<HintPath>..\packages\Microsoft.DocAsCode.YamlSerialization.2.38.1\lib\net461\Microsoft.DocAsCode.YamlSerialization.dll</HintPath>
5466
</Reference>
5567
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
5668
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -76,23 +88,34 @@
7688
<HintPath>..\packages\System.Composition.TypedParts.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll</HintPath>
7789
</Reference>
7890
<Reference Include="System.Core" />
91+
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
92+
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
93+
</Reference>
94+
<Reference Include="System.Web" />
7995
<Reference Include="System.Xml.Linq" />
8096
<Reference Include="System.Data.DataSetExtensions" />
8197
<Reference Include="Microsoft.CSharp" />
8298
<Reference Include="System.Data" />
8399
<Reference Include="System.Net.Http" />
84100
<Reference Include="System.Xml" />
85-
<Reference Include="YamlDotNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
86-
<HintPath>..\packages\YamlDotNet.Signed.4.1.0\lib\net35\YamlDotNet.dll</HintPath>
101+
<Reference Include="YamlDotNet, Version=4.2.2.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
102+
<HintPath>..\packages\YamlDotNet.Signed.4.2.2\lib\net35\YamlDotNet.dll</HintPath>
87103
</Reference>
88104
</ItemGroup>
89105
<ItemGroup>
90-
<Compile Include="LuceneDfmEngineCustomizer.cs" />
91-
<Compile Include="LuceneNoteBlockRule.cs" />
92-
<Compile Include="LuceneNoteBlockToken.cs" />
93-
<Compile Include="LuceneRendererPartProvider.cs" />
94-
<Compile Include="LuceneTokenRendererPart.cs" />
106+
<Compile Include="LuceneExperimentalBlock.cs" />
107+
<Compile Include="LuceneExperimentalBlockParser.cs" />
108+
<Compile Include="LuceneExperimentalBlockRenderer.cs" />
109+
<Compile Include="LuceneExperimentalInline.cs" />
110+
<Compile Include="LuceneExperimentalInlineParser.cs" />
111+
<Compile Include="LuceneExperimentalInlineRenderer.cs" />
112+
<Compile Include="LuceneExperimentalMarkdownExtension.cs" />
113+
<Compile Include="LuceneMarkdigExtensions.cs" />
114+
<Compile Include="LuceneMarkdownService.cs" />
115+
<Compile Include="LuceneMarkdigServiceProvider.cs" />
95116
<Compile Include="Properties\AssemblyInfo.cs" />
117+
<Compile Include="ReflectionHelper.cs" />
118+
<Compile Include="TagMatcher.cs" />
96119
</ItemGroup>
97120
<ItemGroup>
98121
<None Include="packages.config" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Markdig.Parsers;
2+
using Markdig.Syntax;
3+
4+
namespace LuceneDocsPlugins
5+
{
6+
public class LuceneExperimentalBlock : LeafBlock
7+
{
8+
public string MatchType { get; }
9+
10+
public LuceneExperimentalBlock(BlockParser parser, string matchType) : base(parser)
11+
{
12+
MatchType = matchType;
13+
}
14+
}
15+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Markdig.Parsers;
2+
using Markdig.Syntax.Inlines;
3+
4+
namespace LuceneDocsPlugins
5+
{
6+
//TODO: Make an inline parser and see if that works
7+
8+
public class LuceneExperimentalBlockParser : BlockParser
9+
{
10+
11+
public LuceneExperimentalBlockParser()
12+
{
13+
OpeningCharacters = new[] { '@' };
14+
}
15+
16+
public override BlockState TryOpen(BlockProcessor processor)
17+
{
18+
if (processor.IsCodeIndent)
19+
{
20+
return BlockState.None;
21+
}
22+
23+
var line = processor.Line;
24+
25+
var matchType = TagMatcher.GetMatch(line);
26+
27+
if (matchType == null)
28+
return BlockState.None;
29+
30+
var luceneExperimentalBlock = new LuceneExperimentalBlock(this, matchType);
31+
32+
processor.NewBlocks.Push(luceneExperimentalBlock);
33+
34+
return BlockState.BreakDiscard;
35+
}
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Markdig.Renderers;
2+
using Markdig.Renderers.Html;
3+
4+
namespace LuceneDocsPlugins
5+
{
6+
public class LuceneExperimentalBlockRenderer : HtmlObjectRenderer<LuceneExperimentalBlock>
7+
{
8+
private const string Message = "This is a Lucene.NET {0} API, use at your own risk";
9+
10+
protected override void Write(HtmlRenderer renderer, LuceneExperimentalBlock inclusion)
11+
{
12+
renderer.Write("<div class=\"lucene-block lucene-" + inclusion.MatchType.ToLower() + "\">" + string.Format(Message, inclusion.MatchType.ToUpper()) + "</div>");
13+
}
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Markdig.Syntax.Inlines;
2+
3+
namespace LuceneDocsPlugins
4+
{
5+
public class LuceneExperimentalInline : LeafInline
6+
{
7+
public string MatchType { get; }
8+
9+
public LuceneExperimentalInline(string matchType)
10+
{
11+
MatchType = matchType;
12+
}
13+
}
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Markdig.Helpers;
2+
using Markdig.Parsers;
3+
4+
namespace LuceneDocsPlugins
5+
{
6+
public class LuceneExperimentalInlineParser : InlineParser
7+
{
8+
public LuceneExperimentalInlineParser()
9+
{
10+
OpeningCharacters = new[] { '@' };
11+
}
12+
13+
public override bool Match(InlineProcessor processor, ref StringSlice slice)
14+
{
15+
var matchType = TagMatcher.GetMatch(slice);
16+
17+
if (matchType == null)
18+
return false;
19+
20+
var luceneExperimentalInline = new LuceneExperimentalInline(matchType);
21+
22+
processor.Inline = luceneExperimentalInline;
23+
return true;
24+
}
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Markdig.Renderers;
2+
using Markdig.Renderers.Html;
3+
4+
namespace LuceneDocsPlugins
5+
{
6+
public class LuceneExperimentalInlineRenderer : HtmlObjectRenderer<LuceneExperimentalInline>
7+
{
8+
private const string Message = "This is a Lucene.NET {0} API, use at your own risk";
9+
10+
protected override void Write(HtmlRenderer renderer, LuceneExperimentalInline inclusion)
11+
{
12+
renderer.Write("<div class=\"lucene-block lucene-" + inclusion.MatchType.ToLower() + "\">" + string.Format(Message, inclusion.MatchType.ToUpper()) + "</div>");
13+
}
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Markdig;
2+
using Markdig.Renderers;
3+
using Microsoft.DocAsCode.MarkdigEngine.Extensions;
4+
5+
namespace LuceneDocsPlugins
6+
{
7+
public class LuceneExperimentalMarkdownExtension : IMarkdownExtension
8+
{
9+
public void Setup(MarkdownPipelineBuilder pipeline)
10+
{
11+
pipeline.BlockParsers.Insert(0, new LuceneExperimentalBlockParser());
12+
pipeline.InlineParsers.Insert(0, new LuceneExperimentalInlineParser());
13+
14+
//pipeline.BlockParsers.AddIfNotAlready<LuceneExperimentalBlockParser>();
15+
//pipeline.InlineParsers.AddIfNotAlready<LuceneExperimentalInlineParser>();
16+
}
17+
18+
public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
19+
{
20+
if (!(renderer is HtmlRenderer htmlRenderer)) return;
21+
22+
if (!htmlRenderer.ObjectRenderers.Contains<LuceneExperimentalBlockRenderer>())
23+
{
24+
htmlRenderer.ObjectRenderers.Insert(0, new LuceneExperimentalBlockRenderer());
25+
}
26+
27+
if (!htmlRenderer.ObjectRenderers.Contains<LuceneExperimentalInlineRenderer>())
28+
{
29+
htmlRenderer.ObjectRenderers.Insert(0, new LuceneExperimentalInlineRenderer());
30+
}
31+
}
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Markdig;
2+
3+
namespace LuceneDocsPlugins
4+
{
5+
public static class LuceneMarkdigExtensions
6+
{
7+
public static MarkdownPipelineBuilder UseLuceneExperimental(this MarkdownPipelineBuilder pipeline)
8+
{
9+
var extensions = pipeline.Extensions;
10+
if (!extensions.Contains<LuceneExperimentalMarkdownExtension>())
11+
{
12+
extensions.Insert(0, new LuceneExperimentalMarkdownExtension());
13+
}
14+
return pipeline;
15+
}
16+
17+
public static MarkdownPipeline UseLuceneExperimental(this MarkdownPipeline pipeline)
18+
{
19+
var extensions = pipeline.Extensions;
20+
if (!extensions.Contains<LuceneExperimentalMarkdownExtension>())
21+
{
22+
extensions.Insert(0, new LuceneExperimentalMarkdownExtension());
23+
}
24+
return pipeline;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)