Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public HelpSchemaException(SourceExtent extent, string message)
     : base(
     String.Format(
         "{0}:{1} '{2}'\n {3}",
         extent.Line.Start, 
         extent.Column.Start, 
         GetSnippet(extent.OriginalText), 
         message)
     )
 {
 }
Ejemplo n.º 3
0
 public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent, ParserMode parserMode)
     : base(spanText, sourceExtent, parserMode)
 {
     this.Uri = uriText;
 }
Ejemplo n.º 4
0
 public ParagraphSpan(string spanText, SourceExtent sourceExtent)
 {
     this.Text = spanText;
     this.SourceExtent = sourceExtent;
 }
Ejemplo n.º 5
0
 public ParagraphSpan(string spanText, SourceExtent sourceExtent)
 {
     this.Text         = spanText;
     this.SourceExtent = sourceExtent;
 }
Ejemplo n.º 6
0
 public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent)
     : base(spanText, sourceExtent)
 {
     this.Uri = uriText;
 }
Ejemplo n.º 7
0
 public HyperlinkSpan(string spanText, string uriText, SourceExtent sourceExtent)
     : base(spanText, sourceExtent)
 {
     this.Uri = uriText;
 }
Ejemplo n.º 8
0
        private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent)
        {
            this.FinishParagraph();

            _currentDocument.AddChildNode(
                new HeadingNode(
                    regexMatch.Groups[3].Value,
                    regexMatch.Groups[2].Value.Length,
                    sourceExtent));
        }
Ejemplo n.º 9
0
        private void CreateHardBreakSpan(Match regexMatch, SourceExtent sourceExtent)
        {
            this.StartParagraph();

            _currentParagraphSpans.Add(
                new HardBreakSpan(
                    sourceExtent));
        }
Ejemplo n.º 10
0
 private void CreateSoftBreakSpan(Match regexMatch, SourceExtent sourceExtent)
 {
     // Don't create a span?
 }
Ejemplo n.º 11
0
        private void CreateHyperlinkSpan(Match regexMatch, SourceExtent sourceExtent)
        {
            this.StartParagraph();

            _currentParagraphSpans.Add(
                new HyperlinkSpan(
                    regexMatch.Groups[1].Value,
                    regexMatch.Groups[2].Value,
                    sourceExtent));
        }
Ejemplo n.º 12
0
        private void CreateBoldSpan(Match regexMatch, SourceExtent sourceExtent)
        {
            this.StartParagraph();

            _currentParagraphSpans.Add(
                new TextSpan(
                    regexMatch.Groups[1].Value,
                    sourceExtent,
                    TextSpanStyle.Bold));
        }
Ejemplo n.º 13
0
        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));
            }
        }
Ejemplo n.º 14
0
        private void CreateTickCodeBlock(Match regexMatch, SourceExtent sourceExtent)
        {
                this.FinishParagraph();

                _currentDocument.AddChildNode(
                    new CodeBlockNode(
                        regexMatch.Groups[2].Value,
                        sourceExtent));
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
 private void CreateParagraph(Match regexMatch, SourceExtent sourceExtent)
 {
     this.FinishParagraph();
     this.StartParagraph();
 }
Ejemplo n.º 17
0
 public ParagraphSpan(string spanText, SourceExtent sourceExtent, ParserMode parserMode)
 {
     this.Text         = spanText;
     this.SourceExtent = sourceExtent;
     this.ParserMode   = parserMode;
 }
Ejemplo n.º 18
0
        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();
        }