Improve indentation for doc comments
Doc comments are now split at their source, as a first step in normalizing their indentation between VS and MD.
This commit is contained in:
parent
d126d25215
commit
c1cb70d215
4 changed files with 50 additions and 38 deletions
|
@ -389,29 +389,29 @@ namespace Bind
|
||||||
if (!docfiles.ContainsKey(docfile))
|
if (!docfiles.ContainsKey(docfile))
|
||||||
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
||||||
|
|
||||||
string doc = null;
|
var docs = new List<string>();
|
||||||
if (docfiles.ContainsKey(docfile))
|
if (docfiles.ContainsKey(docfile))
|
||||||
{
|
{
|
||||||
doc = Processor.ProcessFile(docfiles[docfile]);
|
docs.AddRange(Processor.ProcessFile(docfiles[docfile]));
|
||||||
}
|
}
|
||||||
if (doc == null)
|
if (docs.Count == 0)
|
||||||
{
|
{
|
||||||
doc = "/// <summary></summary>";
|
docs.Add("/// <summary></summary>");
|
||||||
}
|
}
|
||||||
|
|
||||||
int summary_start = doc.IndexOf("<summary>") + "<summary>".Length;
|
int summary_start = docs[0].IndexOf("<summary>") + "<summary>".Length;
|
||||||
string warning = "[deprecated: v{0}]";
|
string warning = "[deprecated: v{0}]";
|
||||||
string category = "[requires: {0}]";
|
string category = "[requires: {0}]";
|
||||||
if (f.Deprecated)
|
if (f.Deprecated)
|
||||||
{
|
{
|
||||||
warning = String.Format(warning, f.DeprecatedVersion);
|
warning = String.Format(warning, f.DeprecatedVersion);
|
||||||
doc = doc.Insert(summary_start, warning);
|
docs[0] = docs[0].Insert(summary_start, warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
||||||
{
|
{
|
||||||
category = String.Format(category, f.Category);
|
category = String.Format(category, f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
else if (!String.IsNullOrEmpty(f.Version))
|
else if (!String.IsNullOrEmpty(f.Version))
|
||||||
{
|
{
|
||||||
|
@ -419,10 +419,13 @@ namespace Bind
|
||||||
category = String.Format(category, "v" + f.Version);
|
category = String.Format(category, "v" + f.Version);
|
||||||
else
|
else
|
||||||
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.WriteLine(doc);
|
foreach (var doc in docs)
|
||||||
|
{
|
||||||
|
sw.WriteLine(doc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -696,29 +696,29 @@ typedef const char* GLstring;
|
||||||
if (!docfiles.ContainsKey(docfile))
|
if (!docfiles.ContainsKey(docfile))
|
||||||
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
||||||
|
|
||||||
string doc = null;
|
var docs = new List<string>();
|
||||||
if (docfiles.ContainsKey(docfile))
|
if (docfiles.ContainsKey(docfile))
|
||||||
{
|
{
|
||||||
doc = Processor.ProcessFile(docfiles[docfile]);
|
docs.AddRange(Processor.ProcessFile(docfiles[docfile]));
|
||||||
}
|
}
|
||||||
if (doc == null)
|
if (docs.Count == 0)
|
||||||
{
|
{
|
||||||
doc = "/// <summary></summary>";
|
docs.Add("/// <summary></summary>");
|
||||||
}
|
}
|
||||||
|
|
||||||
int summary_start = doc.IndexOf("<summary>") + "<summary>".Length;
|
int summary_start = docs[0].IndexOf("<summary>") + "<summary>".Length;
|
||||||
string warning = "[deprecated: v{0}]";
|
string warning = "[deprecated: v{0}]";
|
||||||
string category = "[requires: {0}]";
|
string category = "[requires: {0}]";
|
||||||
if (f.Deprecated)
|
if (f.Deprecated)
|
||||||
{
|
{
|
||||||
warning = String.Format(warning, f.DeprecatedVersion);
|
warning = String.Format(warning, f.DeprecatedVersion);
|
||||||
doc = doc.Insert(summary_start, warning);
|
docs[0] = docs[0].Insert(summary_start, warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
||||||
{
|
{
|
||||||
category = String.Format(category, f.Category);
|
category = String.Format(category, f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
else if (!String.IsNullOrEmpty(f.Version))
|
else if (!String.IsNullOrEmpty(f.Version))
|
||||||
{
|
{
|
||||||
|
@ -726,10 +726,13 @@ typedef const char* GLstring;
|
||||||
category = String.Format(category, "v" + f.Version);
|
category = String.Format(category, "v" + f.Version);
|
||||||
else
|
else
|
||||||
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.WriteLine(doc);
|
foreach (var doc in docs)
|
||||||
|
{
|
||||||
|
sw.WriteLine(doc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Bind
|
||||||
static readonly XslCompiledTransform xslt = new XslCompiledTransform();
|
static readonly XslCompiledTransform xslt = new XslCompiledTransform();
|
||||||
static readonly XmlReaderSettings settings = new XmlReaderSettings();
|
static readonly XmlReaderSettings settings = new XmlReaderSettings();
|
||||||
|
|
||||||
string Text;
|
string[] Text;
|
||||||
string LastFile;
|
string LastFile;
|
||||||
|
|
||||||
public DocProcessor(string transform_file)
|
public DocProcessor(string transform_file)
|
||||||
|
@ -29,19 +29,21 @@ namespace Bind
|
||||||
// found in the <!-- eqn: :--> comments in the docs.
|
// found in the <!-- eqn: :--> comments in the docs.
|
||||||
// Todo: Some simple MathML tags do not include comments, find a solution.
|
// Todo: Some simple MathML tags do not include comments, find a solution.
|
||||||
// Todo: Some files include more than 1 function - find a way to map these extra functions.
|
// Todo: Some files include more than 1 function - find a way to map these extra functions.
|
||||||
public string ProcessFile(string file)
|
public string[] ProcessFile(string file)
|
||||||
{
|
{
|
||||||
|
string text;
|
||||||
|
|
||||||
if (LastFile == file)
|
if (LastFile == file)
|
||||||
return Text;
|
return Text;
|
||||||
|
|
||||||
LastFile = file;
|
LastFile = file;
|
||||||
Text = File.ReadAllText(file);
|
text = File.ReadAllText(file);
|
||||||
|
|
||||||
Match m = remove_mathml.Match(Text);
|
Match m = remove_mathml.Match(text);
|
||||||
while (m.Length > 0)
|
while (m.Length > 0)
|
||||||
{
|
{
|
||||||
string removed = Text.Substring(m.Index, m.Length);
|
string removed = text.Substring(m.Index, m.Length);
|
||||||
Text = Text.Remove(m.Index, m.Length);
|
text = text.Remove(m.Index, m.Length);
|
||||||
int equation = removed.IndexOf("eqn");
|
int equation = removed.IndexOf("eqn");
|
||||||
if (equation > 0)
|
if (equation > 0)
|
||||||
{
|
{
|
||||||
|
@ -60,24 +62,25 @@ namespace Bind
|
||||||
}
|
}
|
||||||
|
|
||||||
string eqn_substring = removed.Substring(eqn_start, eqn_end);
|
string eqn_substring = removed.Substring(eqn_start, eqn_end);
|
||||||
Text = Text.Insert(m.Index, "<![CDATA[" + eqn_substring + "]]>");
|
text = text.Insert(m.Index, "<![CDATA[" + eqn_substring + "]]>");
|
||||||
}
|
}
|
||||||
|
|
||||||
next:
|
next:
|
||||||
m = remove_mathml.Match(Text);
|
m = remove_mathml.Match(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlReader doc = null;
|
XmlReader doc = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// The pure XmlReader is ~20x faster than the XmlTextReader.
|
// The pure XmlReader is ~20x faster than the XmlTextReader.
|
||||||
doc = XmlReader.Create(new StringReader(Text), settings);
|
doc = XmlReader.Create(new StringReader(text), settings);
|
||||||
//doc = new XmlTextReader(new StringReader(text));
|
//doc = new XmlTextReader(new StringReader(text));
|
||||||
|
|
||||||
using (StringWriter sw = new StringWriter())
|
using (StringWriter sw = new StringWriter())
|
||||||
{
|
{
|
||||||
xslt.Transform(doc, null, sw);
|
xslt.Transform(doc, null, sw);
|
||||||
Text = sw.ToString().TrimEnd('\r', '\n');
|
Text = sw.ToString().Split(new char[] { '\r', '\n' },
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
return Text;
|
return Text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +88,7 @@ namespace Bind
|
||||||
{
|
{
|
||||||
Console.WriteLine(e.ToString());
|
Console.WriteLine(e.ToString());
|
||||||
Console.WriteLine(doc.ToString());
|
Console.WriteLine(doc.ToString());
|
||||||
return String.Empty;
|
return new string[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,29 +347,29 @@ namespace Bind
|
||||||
if (!docfiles.ContainsKey(docfile))
|
if (!docfiles.ContainsKey(docfile))
|
||||||
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
docfile = Settings.FunctionPrefix + f.TrimmedName.TrimEnd(numbers) + ".xml";
|
||||||
|
|
||||||
string doc = null;
|
var docs = new List<string>();
|
||||||
if (docfiles.ContainsKey(docfile))
|
if (docfiles.ContainsKey(docfile))
|
||||||
{
|
{
|
||||||
doc = Processor.ProcessFile(docfiles[docfile]);
|
docs.AddRange(Processor.ProcessFile(docfiles[docfile]));
|
||||||
}
|
}
|
||||||
if (doc == null)
|
if (docs.Count == 0)
|
||||||
{
|
{
|
||||||
doc = "/// <summary></summary>";
|
docs.Add("/// <summary></summary>");
|
||||||
}
|
}
|
||||||
|
|
||||||
int summary_start = doc.IndexOf("<summary>") + "<summary>".Length;
|
int summary_start = docs[0].IndexOf("<summary>") + "<summary>".Length;
|
||||||
string warning = "[deprecated: v{0}]";
|
string warning = "[deprecated: v{0}]";
|
||||||
string category = "[requires: {0}]";
|
string category = "[requires: {0}]";
|
||||||
if (f.Deprecated)
|
if (f.Deprecated)
|
||||||
{
|
{
|
||||||
warning = String.Format(warning, f.DeprecatedVersion);
|
warning = String.Format(warning, f.DeprecatedVersion);
|
||||||
doc = doc.Insert(summary_start, warning);
|
docs[0] = docs[0].Insert(summary_start, warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
if (f.Extension != "Core" && !String.IsNullOrEmpty(f.Category))
|
||||||
{
|
{
|
||||||
category = String.Format(category, f.Category);
|
category = String.Format(category, f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
else if (!String.IsNullOrEmpty(f.Version))
|
else if (!String.IsNullOrEmpty(f.Version))
|
||||||
{
|
{
|
||||||
|
@ -377,10 +377,13 @@ namespace Bind
|
||||||
category = String.Format(category, "v" + f.Version);
|
category = String.Format(category, "v" + f.Version);
|
||||||
else
|
else
|
||||||
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
category = String.Format(category, "v" + f.Version + " and " + f.Category);
|
||||||
doc = doc.Insert(summary_start, category);
|
docs[0] = docs[0].Insert(summary_start, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.WriteLine(doc);
|
foreach (var doc in docs)
|
||||||
|
{
|
||||||
|
sw.WriteLine(doc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue