This is an automated email from the ASF dual-hosted git repository.
shazwazza pushed a commit to branch docs-may
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/docs-may by this push:
new d75362d Added plugin to replace env vars in markdown which helps with
automation
d75362d is described below
commit d75362d494117ce37e902fccd5f3ab8a7b45f8be
Author: Shannon <[email protected]>
AuthorDate: Thu May 21 13:55:16 2020 +1000
Added plugin to replace env vars in markdown which helps with automation
---
.../EnvironmentVariableInlineRule.cs | 64 ++++++++++++++++++++++
.../EnvironmentVariableRendererPart.cs | 43 +++++++++++++++
.../LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs | 11 +++-
.../LuceneDocsPlugins/LuceneDocsPlugins.csproj | 6 +-
src/docs/LuceneDocsPlugins/LuceneNoteBlockRule.cs | 4 +-
src/docs/LuceneDocsPlugins/LuceneNoteBlockToken.cs | 9 +++
...dererPart.cs => LuceneNoteTokenRendererPart.cs} | 5 +-
...ererPartProvider.cs => RendererPartProvider.cs} | 6 +-
websites/apidocs/docs.ps1 | 3 +
websites/apidocs/index.md | 6 +-
10 files changed, 144 insertions(+), 13 deletions(-)
diff --git a/src/docs/LuceneDocsPlugins/EnvironmentVariableInlineRule.cs
b/src/docs/LuceneDocsPlugins/EnvironmentVariableInlineRule.cs
new file mode 100644
index 0000000..9082817
--- /dev/null
+++ b/src/docs/LuceneDocsPlugins/EnvironmentVariableInlineRule.cs
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using System;
+using System.Collections.Immutable;
+using System.Text.RegularExpressions;
+using Microsoft.DocAsCode.MarkdownLite;
+
+namespace LuceneDocsPlugins
+{
+ internal static class RegexExtentions
+ {
+ public static string NotEmpty(this Match match, int index1, int index2)
+ {
+ if (match.Groups.Count > index1 &&
!string.IsNullOrEmpty(match.Groups[index1].Value))
+ {
+ return match.Groups[index1].Value;
+ }
+ return match.Groups[index2].Value;
+ }
+ }
+
+ public class EnvironmentVariableInlineRule : IMarkdownRule
+ {
+ public string Name => "EnvVarToken";
+ private static readonly Regex _envVarRegex = new
Regex(@"^\[EnvVar:(\w+?)\]", RegexOptions.Compiled);
+
+ public IMarkdownToken TryMatch(IMarkdownParser parser,
IMarkdownParsingContext context)
+ {
+ var match = _envVarRegex.Match(context.CurrentMarkdown);
+ if (match.Length == 0)
+ {
+ return null;
+ }
+ var envVar = match.Groups[1].Value;
+ var text = Environment.GetEnvironmentVariable(envVar);
+ if (text == null)
+ {
+ return null;
+ }
+ else
+ {
+ var sourceInfo = context.Consume(match.Length);
+ return new MarkdownTextToken(this, parser.Context, text,
sourceInfo);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/docs/LuceneDocsPlugins/EnvironmentVariableRendererPart.cs
b/src/docs/LuceneDocsPlugins/EnvironmentVariableRendererPart.cs
new file mode 100644
index 0000000..f6d5cfa
--- /dev/null
+++ b/src/docs/LuceneDocsPlugins/EnvironmentVariableRendererPart.cs
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+using Microsoft.DocAsCode.Dfm;
+using Microsoft.DocAsCode.MarkdownLite;
+using System.Linq;
+
+namespace LuceneDocsPlugins
+{
+ // TODO: this is actually not needed since we are inserting our own inline
rule, although the docs
+ // claim we need it
https://dotnet.github.io/docfx/tutorial/howto_customize_docfx_flavored_markdown.html
+ // maybe that is only the case for block level items? I cannot quite
figure it out looking at the docfx code
+
+ ///// <summary>
+ ///// Used to replace environment variables tokens with their values
+ ///// </summary>
+ //public sealed class EnvironmentVariableRendererPart :
DfmCustomizedRendererPartBase<IMarkdownRenderer, MarkdownTextToken,
MarkdownInlineContext>
+ //{
+ // public override string Name => "EnvironmentVariableRendererPart";
+
+ // public override bool Match(IMarkdownRenderer renderer,
MarkdownTextToken token, MarkdownInlineContext context)
+ // => true;
+
+ // public override StringBuffer Render(IMarkdownRenderer renderer,
MarkdownTextToken token, MarkdownInlineContext context)
+ // => token.Content;
+ //}
+}
\ No newline at end of file
diff --git a/src/docs/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs
b/src/docs/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs
index 2a3923a..6bfd711 100644
--- a/src/docs/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs
+++ b/src/docs/LuceneDocsPlugins/LuceneDfmEngineCustomizer.cs
@@ -31,9 +31,14 @@ namespace LuceneDocsPlugins
public class LuceneDfmEngineCustomizer : IDfmEngineCustomizer
{
public void Customize(DfmEngineBuilder builder,
IReadOnlyDictionary<string, object> parameters)
- {
- var index = builder.BlockRules.FindIndex(r => r is
MarkdownHeadingBlockRule);
- builder.BlockRules = builder.BlockRules.Insert(index, new
LuceneNoteBlockRule());
+ {
+ // insert inline rule at the top
+ builder.InlineRules = builder.InlineRules.Insert(0, new
EnvironmentVariableInlineRule());
+
+ // insert block rule above header rule. Why? I dunno, that's what
the docs say:
+ //
https://dotnet.github.io/docfx/tutorial/intro_markdown_lite.html#select-token-kind
+ var blockIndex = builder.BlockRules.FindIndex(r => r is
MarkdownHeadingBlockRule);
+ builder.BlockRules = builder.BlockRules.Insert(blockIndex, new
LuceneNoteBlockRule());
}
}
}
diff --git a/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj
b/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj
index 0504197..6564d47 100644
--- a/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj
+++ b/src/docs/LuceneDocsPlugins/LuceneDocsPlugins.csproj
@@ -61,11 +61,13 @@ under the License.
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="EnvironmentVariableInlineRule.cs" />
+ <Compile Include="EnvironmentVariableRendererPart.cs" />
<Compile Include="LuceneDfmEngineCustomizer.cs" />
<Compile Include="LuceneNoteBlockRule.cs" />
<Compile Include="LuceneNoteBlockToken.cs" />
- <Compile Include="LuceneRendererPartProvider.cs" />
- <Compile Include="LuceneTokenRendererPart.cs" />
+ <Compile Include="RendererPartProvider.cs" />
+ <Compile Include="LuceneNoteTokenRendererPart.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/src/docs/LuceneDocsPlugins/LuceneNoteBlockRule.cs
b/src/docs/LuceneDocsPlugins/LuceneNoteBlockRule.cs
index 16d5a99..af3ce3c 100644
--- a/src/docs/LuceneDocsPlugins/LuceneNoteBlockRule.cs
+++ b/src/docs/LuceneDocsPlugins/LuceneNoteBlockRule.cs
@@ -22,6 +22,7 @@ using Microsoft.DocAsCode.MarkdownLite;
namespace LuceneDocsPlugins
{
+
/// <summary>
/// The regex rule to parse out the custom Lucene tokens
/// </summary>
@@ -29,10 +30,11 @@ namespace LuceneDocsPlugins
{
// TODO: I think there's an issue with this regex and multi-line or
something, for example see: DrillDownQuery class
// since this isn't matching it's experimental tag (there's lots of
others too)
- public virtual Regex LabelRegex { get; } = new
Regex("^@lucene\\.(?<notetype>(experimental|internal))$");
+ public virtual Regex LabelRegex { get; } = new
Regex("^@lucene\\.(?<notetype>(experimental|internal))", RegexOptions.Compiled);
public virtual IMarkdownToken TryMatch(IMarkdownParser parser,
IMarkdownParsingContext context)
{
+
var match = LabelRegex.Match(context.CurrentMarkdown);
if (match.Length == 0)
{
diff --git a/src/docs/LuceneDocsPlugins/LuceneNoteBlockToken.cs
b/src/docs/LuceneDocsPlugins/LuceneNoteBlockToken.cs
index 3c80706..d0a4096 100644
--- a/src/docs/LuceneDocsPlugins/LuceneNoteBlockToken.cs
+++ b/src/docs/LuceneDocsPlugins/LuceneNoteBlockToken.cs
@@ -42,4 +42,13 @@ namespace LuceneDocsPlugins
public SourceInfo SourceInfo { get; }
}
+
+ public class EnvironmentVariableBlockToken : IMarkdownToken
+ {
+ public IMarkdownRule Rule { get; }
+
+ public IMarkdownContext Context { get; }
+
+ public SourceInfo SourceInfo { get; }
+ }
}
\ No newline at end of file
diff --git a/src/docs/LuceneDocsPlugins/LuceneTokenRendererPart.cs
b/src/docs/LuceneDocsPlugins/LuceneNoteTokenRendererPart.cs
similarity index 87%
rename from src/docs/LuceneDocsPlugins/LuceneTokenRendererPart.cs
rename to src/docs/LuceneDocsPlugins/LuceneNoteTokenRendererPart.cs
index c89965f..f956ba0 100644
--- a/src/docs/LuceneDocsPlugins/LuceneTokenRendererPart.cs
+++ b/src/docs/LuceneDocsPlugins/LuceneNoteTokenRendererPart.cs
@@ -25,13 +25,14 @@ namespace LuceneDocsPlugins
/// <summary>
/// Used to replace custom Lucene tokens with custom HTML markup
/// </summary>
- public sealed class LuceneTokenRendererPart :
DfmCustomizedRendererPartBase<IMarkdownRenderer, LuceneNoteBlockToken,
MarkdownBlockContext>
+ public sealed class LuceneNoteTokenRendererPart :
DfmCustomizedRendererPartBase<IMarkdownRenderer, LuceneNoteBlockToken,
MarkdownBlockContext>
{
private const string Message = "This is a Lucene.NET {0} API, use at
your own risk";
public override string Name => "LuceneTokenRendererPart";
- public override bool Match(IMarkdownRenderer renderer,
LuceneNoteBlockToken token, MarkdownBlockContext context) => true;
+ public override bool Match(IMarkdownRenderer renderer,
LuceneNoteBlockToken token, MarkdownBlockContext context)
+ => true;
public override StringBuffer Render(IMarkdownRenderer renderer,
LuceneNoteBlockToken token, MarkdownBlockContext context)
=> "<div class=\"lucene-block lucene-" + token.Label.ToLower() +
"\">" + string.Format(Message, token.Label.ToUpper()) + "</div>";
diff --git a/src/docs/LuceneDocsPlugins/LuceneRendererPartProvider.cs
b/src/docs/LuceneDocsPlugins/RendererPartProvider.cs
similarity index 85%
rename from src/docs/LuceneDocsPlugins/LuceneRendererPartProvider.cs
rename to src/docs/LuceneDocsPlugins/RendererPartProvider.cs
index 70bffda..20c17a3 100644
--- a/src/docs/LuceneDocsPlugins/LuceneRendererPartProvider.cs
+++ b/src/docs/LuceneDocsPlugins/RendererPartProvider.cs
@@ -27,11 +27,13 @@ namespace LuceneDocsPlugins
/// Exports our custom renderer via MEF to DocFx
/// </summary>
[Export(typeof(IDfmCustomizedRendererPartProvider))]
- public class LuceneRendererPartProvider :
IDfmCustomizedRendererPartProvider
+ public class RendererPartProvider : IDfmCustomizedRendererPartProvider
{
public IEnumerable<IDfmCustomizedRendererPart>
CreateParts(IReadOnlyDictionary<string, object> parameters)
{
- yield return new LuceneTokenRendererPart();
+ yield return new LuceneNoteTokenRendererPart();
+ //yield return new EnvironmentVariableRendererPart();
}
}
+
}
\ No newline at end of file
diff --git a/websites/apidocs/docs.ps1 b/websites/apidocs/docs.ps1
index c7fc247..1207a63 100644
--- a/websites/apidocs/docs.ps1
+++ b/websites/apidocs/docs.ps1
@@ -116,6 +116,9 @@ $DocFxJsonContent.build.globalMetadata._appTitle = "Apache
Lucene.NET $LuceneNet
$DocFxJsonContent.build.globalMetadata._gitContribute.branch =
"docs/$LuceneNetVersion"
$DocFxJsonContent | ConvertTo-Json -depth 100 | Set-Content $DocFxJson
+# set env vars that will be replaced in Markdown
+$env:LuceneNetVersion = $LuceneNetVersion
+
$DocFxLog = Join-Path -Path $ApiDocsFolder "obj\docfx.log"
if ($?) {
diff --git a/websites/apidocs/index.md b/websites/apidocs/index.md
index 762aa5f..df91de5 100644
--- a/websites/apidocs/index.md
+++ b/websites/apidocs/index.md
@@ -3,16 +3,16 @@ title: Lucene.Net Docs - The documentation website for
Lucene.Net
description: The documentation website for Lucene.Net
---
-Apache Lucene.Net 4.8.0 Documentation
+Apache Lucene.Net [EnvVar:LuceneNetVersion] Documentation
===============
---------------
-Lucene is a .NET full-text search engine. Lucene.NET is not a complete
application,
+Lucene is a _.NET full-text search engine_. Lucene.NET is not a complete
application,
but rather a code library and API that can easily be used to add search
capabilities
to applications.
-This is the official API documentation for <b>Apache Lucene.NET 4.8.0</b>.
+This is the official API documentation for __Apache Lucene.NET
[EnvVar:LuceneNetVersion]__.
## Getting Started