public TextSpan(string spanText, SourceExtent sourceExtent, ParserMode parserMode, TextSpanStyle spanStyle = TextSpanStyle.Normal) : base(parserMode == ParserMode.Full ? MarkdownParser.UnwindMarkdownCharsEscaping(spanText.Trim()) : spanText, sourceExtent, parserMode) { this.Style = spanStyle; }
public HelpSchemaException(SourceExtent extent, string message) : base( String.Format( "{0}:{1} '{2}'\n {3}", extent.Line.Start, extent.Column.Start, GetSnippet(extent.OriginalText), message) ) { }
public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent, ParserMode parserMode) : base(spanText, sourceExtent, parserMode) { this.Uri = uriText; }
public ParagraphSpan(string spanText, SourceExtent sourceExtent) { this.Text = spanText; this.SourceExtent = sourceExtent; }
public ParagraphSpan(string spanText, SourceExtent sourceExtent) { this.Text = spanText; this.SourceExtent = sourceExtent; }
public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent) : base(spanText, sourceExtent) { this.Uri = uriText; }
public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent) : base(spanText, sourceExtent) { this.Uri = uriText; }
private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[3].Value, regexMatch.Groups[2].Value.Length, sourceExtent)); }
private void CreateHardBreakSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new HardBreakSpan( sourceExtent)); }
private void CreateSoftBreakSpan(Match regexMatch, SourceExtent sourceExtent) { // Don't create a span? }
private void CreateHyperlinkSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new HyperlinkSpan( regexMatch.Groups[1].Value, regexMatch.Groups[2].Value, sourceExtent)); }
private void CreateBoldSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new TextSpan( regexMatch.Groups[1].Value, sourceExtent, TextSpanStyle.Bold)); }
private void CreateNormalSpan(string spanText, SourceExtent sourceExtent) { this.StartParagraph(); // TODO: Replace all newlines with spaces? We // might want to add line breaks only when the // user has intentionally typed a hard break string // ( \r\n) // If the span is merely whitespace, don't add it if (!string.IsNullOrWhiteSpace(spanText)) { _currentParagraphSpans.Add( new TextSpan( spanText, sourceExtent)); } }
private void CreateTickCodeBlock(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); _currentDocument.AddChildNode( new CodeBlockNode( regexMatch.Groups[2].Value, sourceExtent)); }
private void CreateUnderlineHeader(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); int headerLevel = regexMatch.Groups[2].Value[0] == '=' ? 1 : 2; _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[1].Value, headerLevel, sourceExtent)); }
private void CreateParagraph(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); this.StartParagraph(); }
public ParagraphSpan(string spanText, SourceExtent sourceExtent, ParserMode parserMode) { this.Text = spanText; this.SourceExtent = sourceExtent; this.ParserMode = parserMode; }
private void ParseDocument() { // This algorithm works by applying each Markdown pattern to the // document string starting at startOffset and finding which match // is nearest to the startOffset. If the match is at a position // greater than startOffset, the starting part of the string is // then treated as a normal text span before the matched section is // converted into its node type. int startOffset = 0; int currentLineNumber = 0; int currentColumnNumber = 0; int lastOffset = 0; while (startOffset < _documentText.Length) { // progress reporting if (_progressCallback != null) { if (lastOffset + _reportByteCount < startOffset) { _progressCallback(startOffset, _documentText.Length); lastOffset = startOffset; } } // Try each of the patterns to find a match Match firstMatch = null; MarkdownPattern firstMatchedPattern = null; foreach (MarkdownPattern markdownPattern in _markdownPatterns) { Match regexMatch = null; // This is a dirty hack to tell avoid hash_headers, if it's not a beginning of a line if (markdownPattern.PatternName == "hash_header") { if (_documentText[startOffset] != '#') { continue; } } if (markdownPattern.TryMatchString(_documentText, startOffset, out regexMatch)) { if (firstMatch == null || firstMatch.Index > regexMatch.Index) { firstMatch = regexMatch; firstMatchedPattern = markdownPattern; if (regexMatch.Index == startOffset) { // no reason to continue break; } } } } if (firstMatch != null) { // Gather all text before this point into a paragraph if (firstMatch.Index > 0) { this.StartParagraph(); // Get the extent of the span text SourceExtent spanExtent = new SourceExtent( _documentText, startOffset, firstMatch.Index, currentLineNumber, currentColumnNumber); this.CreateNormalSpan( spanExtent.OriginalText, spanExtent); // Make sure the line and column number are updated // before calculating the position of the match currentLineNumber = spanExtent.Line.End; currentColumnNumber = spanExtent.Column.End; } // Count the newlines in the entire span SourceExtent matchExtent = new SourceExtent( _documentText, firstMatch.Index, firstMatch.Index + firstMatch.Length, currentLineNumber, currentColumnNumber); // Run the match action for the pattern firstMatchedPattern.MatchAction(firstMatch, matchExtent); // Calculate the next offset, line, and column startOffset = firstMatch.Index + firstMatch.Length; currentLineNumber = matchExtent.Line.End; currentColumnNumber = matchExtent.Column.End; } else { // Get the extent containing the remaining text SourceExtent spanExtent = new SourceExtent( _documentText, startOffset, _documentText.Length, currentLineNumber, currentColumnNumber); // If no match found, treat the rest of the text as a span this.CreateNormalSpan( spanExtent.OriginalText, spanExtent); startOffset = _documentText.Length; } } // Finish any remaining paragraph this.FinishParagraph(); }