本文整理汇总了C#中RenderState.WarningSuppressComment方法的典型用法代码示例。如果您正苦于以下问题:C# RenderState.WarningSuppressComment方法的具体用法?C# RenderState.WarningSuppressComment怎么用?C# RenderState.WarningSuppressComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RenderState
的用法示例。
在下文中一共展示了RenderState.WarningSuppressComment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: processLinkElement
private async Task<Errorable> processLinkElement(RenderState st)
{
// A 'cms-link' is translated directly into an anchor tag with the 'path' attribute
// translated and canonicalized into an absolute 'href' attribute, per system
// configuration. All other attributes are copied to the anchor tag as-is.
// e.g.:
// <cms-link path="/absolute/path" ...>contents</cms-link>
// becomes:
// <a href="/content/absolute/path" ...>contents</a>
// if the CMS requests are "mounted" to the /content/ root URL path.
// Either relative or absolute paths are allowed for 'path':
// <cms-link path="../../hello/world" target="_blank">Link text.</cms-link>
// <cms-link path="/hello/world" target="_blank">Link text.</cms-link>
// Set the current element depth so we know where to read up to on error:
int knownDepth = st.Reader.Depth;
bool isEmpty = st.Reader.IsEmptyElement;
if (!st.Reader.HasAttributes)
{
st.Error("cms-link has no attributes");
goto errored;
}
bool foundPath = false;
st.Writer.Append("<a");
st.Reader.MoveToFirstAttribute();
do
{
string value = st.Reader.Value;
if (st.Reader.LocalName == "path")
{
foundPath = true;
// Get the canonicalized blob path (from either absolute or relative):
var abspath = PathObjectModel.ParseBlobPath(value);
CanonicalBlobPath path = abspath.Collapse(abs => abs.Canonicalize(), rel => (st.Item.TreeBlobPath.Path.Tree + rel).Canonicalize());
// TODO: apply the reverse-mount prefix path from the system configuration,
// or just toss the CanonicalBlobPath over to a provider implementation and
// it can give us the final absolute URL path.
st.Writer.AppendFormat(" href=\"{0}\"", path);
continue;
}
// Append the normal attribute:
st.Writer.AppendFormat(" {0}={2}{1}{2}", st.Reader.LocalName, value, st.Reader.QuoteChar);
} while (st.Reader.MoveToNextAttribute());
// Jump back to the element node from the attributes:
st.Reader.MoveToElement();
if (!foundPath)
{
// Issue a warning and append an "href='#'" attribute:
st.WarningSuppressComment("expected 'path' attribute on 'cms-link' element was not found");
st.Writer.Append(" href=\"#\"");
}
// Self-close the <a /> if the <cms-link /> is empty:
if (isEmpty)
{
st.Writer.Append(" />");
return Errorable.NoErrors;
}
// Copy the inner contents and close out the </a>.
st.Writer.Append(">");
var err = await st.CopyElementChildren("cms-link").ConfigureAwait(continueOnCapturedContext: false);
if (err.HasErrors) return err.Errors;
st.Writer.Append("</a>");
return Errorable.NoErrors;
errored:
// Skip to the end of the cms-link element:
if (!isEmpty)
while (st.Reader.Read() && st.Reader.Depth > knownDepth) { }
return Errorable.NoErrors;
}