public override BlockState TryOpen(BlockProcessor processor) { var slice = processor.Line; var column = processor.Column; var sourcePosition = processor.Start; if (processor.IsCodeIndent || !ExtensionsHelper.MatchStart(ref slice, ":::")) { return(BlockState.None); } ExtensionsHelper.SkipSpaces(ref slice); var extensionName = "triple-colon"; ITripleColonExtensionInfo extension; IDictionary <string, string> attributes; HtmlAttributes htmlAttributes; IDictionary <string, string> renderProperties; Action <string> logError = (string message) => _context.LogError( $"invalid-{extensionName}", $"Invalid {extensionName} on line {processor.LineIndex}. \"{slice.Text}\" is invalid. {message}", null, line: processor.LineIndex); if (!TryMatchIdentifier(ref slice, out extensionName) || !_extensions.TryGetValue(extensionName, out extension) || !extension.TryValidateAncestry(processor.CurrentContainer, logError) || !TryMatchAttributes(ref slice, out attributes, extensionName, extension.SelfClosing, logError) || !extension.TryProcessAttributes(attributes, out htmlAttributes, out renderProperties, logError)) { return(BlockState.None); } var block = new TripleColonBlock(this) { Closed = false, Column = column, Line = processor.LineIndex, Span = new SourceSpan(sourcePosition, slice.End), Extension = extension, RenderProperties = renderProperties }; if (htmlAttributes != null) { block.SetData(typeof(HtmlAttributes), htmlAttributes); } processor.NewBlocks.Push(block); if (extension.SelfClosing) { return(BlockState.BreakDiscard); } return(BlockState.ContinueDiscard); }
public override BlockState TryOpen(BlockProcessor processor) { var slice = processor.Line; var sourcePosition = processor.Start; if (processor.IsCodeIndent || !ExtensionsHelper.MatchStart(ref slice, ":::")) { return(BlockState.None); } ExtensionsHelper.SkipSpaces(ref slice); var extensionName = "triple-colon"; Action <string> logError = (string message) => _context.LogError( $"invalid-{extensionName}", $"{message}", null, line: processor.LineIndex); Action <string> logWarning = (string message) => _context.LogWarning( $"invalid-{extensionName}", $"{message}", null, line: processor.LineIndex); var block = new TripleColonBlock(this) { Closed = false, Column = processor.Column, Line = processor.LineIndex, Span = new SourceSpan(sourcePosition, slice.End), }; if (!TryMatchIdentifier(ref slice, out extensionName) || !_extensions.TryGetValue(extensionName, out var extension) || !extension.TryValidateAncestry(processor.CurrentContainer, logError) || !TryMatchAttributes(ref slice, out var attributes, extensionName, extension.SelfClosing, logError) || !extension.TryProcessAttributes(attributes, out var htmlAttributes, out var renderProperties, logError, logWarning, block)) { return(BlockState.None); } block.Extension = extension; block.Attributes = attributes; block.RenderProperties = renderProperties; if (htmlAttributes != null) { block.SetData(typeof(HtmlAttributes), htmlAttributes); } processor.NewBlocks.Push(block); if (extension.GetType() == typeof(ImageExtension) && htmlAttributes != null && ImageExtension.RequiresClosingTripleColon(attributes)) { block.EndingTripleColons = true; return(BlockState.ContinueDiscard); } if (extension.SelfClosing) { return(BlockState.BreakDiscard); } return(BlockState.ContinueDiscard); }