Esempio n. 1
0
        /// <summary>
        /// Convert a Markdown element to a Forkdown one.
        /// </summary>
        /// <param name="mdo">Markdown object to convert.</param>
        public static Element ToForkdown(IMarkdownObject mdo)
        {
            Element result = mdo switch {
                MarkdownDocument _ => new Document(),
                HeadingBlock h => new Heading(h),
                ListBlock l => new Listing(l),
                ListItemBlock li => new ListItem(li),
                ParagraphBlock p => new Paragraph(p),
                CustomContainer c => new Section(c),
                CustomContainerInline c => new ExplicitInlineContainer(c),
                CodeInline c => new Code(c),
                FencedCodeBlock c => new CodeBlock(c),
                LinkInline l => new Link(l),
                LiteralInline t => new Text(t),
                LineBreakInline _ => new LineBreak(),
                ThematicBreakBlock _ => new Separator(),
                Tables.Table t => new Table(t),
                Tables.TableRow tr => new TableRow(tr),
                Tables.TableCell tc => new TableCell(tc),
                EmphasisInline e => new Emphasis(e),
                HtmlBlock b => new Html(b),
                _ => new Placeholder(mdo),
            };

            var subs = mdo switch {
                LeafBlock b => b.Inline,
                IEnumerable <MarkdownObject> e => e,
                _ => null
            } ?? Nil.E <MarkdownObject>();
 public void Setup()
 {
     document = new Document();
     // Workaround for a quirk in the migradoc API.
     _          = document.AddSection().Elements;
     pdfBuilder = new PdfBuilder(document, PdfOptions.Default);
     renderer   = new ThematicBreakBlockRenderer();
     hr         = new ThematicBreakBlock(new ThematicBreakParser());
 }
Esempio n. 3
0
        private void Render(ThematicBreakBlock block)
        {
            var style = this.Theme.Separator;

            if (style.BorderSize > 0)
            {
                stack.Children.Add(new BoxView
                {
                    HeightRequest   = style.BorderSize,
                    BackgroundColor = style.BorderColor,
                });
            }
        }
Esempio n. 4
0
        private IEnumerable <View> Render(ThematicBreakBlock block)
        {
            var style = this.Theme.Separator;

            if (style.BorderSize > 0)
            {
                return(new View[] { new BoxView
                                    {
                                        HeightRequest = style.BorderSize,
                                        BackgroundColor = style.BorderColor,
                                    } });
            }
            return(null);
        }
Esempio n. 5
0
 private View Render(ThematicBreakBlock block)
 {
     return(SeparatorTemplate.CreateContent() as View);
 }
Esempio n. 6
0
 public MarkdownSeparator(ThematicBreakBlock thematicBlock)
 {
     AutoSizeAxes     = Axes.Y;
     RelativeSizeAxes = Axes.X;
 }
Esempio n. 7
0
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            var startPosition = processor.Start;
            var line          = processor.Line;

            // 4.1 Thematic breaks
            // A line consisting of 0-3 spaces of indentation, followed by a sequence of three or more matching -, _, or * characters, each followed optionally by any number of spaces
            int  breakCharCount          = 0;
            var  breakChar               = line.CurrentChar;
            bool hasSpacesSinceLastMatch = false;
            bool hasInnerSpaces          = false;
            var  c = breakChar;

            while (c != '\0')
            {
                if (c == breakChar)
                {
                    if (hasSpacesSinceLastMatch)
                    {
                        hasInnerSpaces = true;
                    }

                    breakCharCount++;
                }
                else if (c.IsSpaceOrTab())
                {
                    hasSpacesSinceLastMatch = true;
                }
                else
                {
                    return(BlockState.None);
                }

                c = line.NextChar();
            }

            // If it as less than 3 chars or it is a setex heading and we are already in a paragraph, let the paragraph handle it
            var previousParagraph = processor.CurrentBlock as ParagraphBlock;

            var isSetexHeading = previousParagraph != null && breakChar == '-' && !hasInnerSpaces;

            if (isSetexHeading)
            {
                var parent = previousParagraph !.Parent !;
                if (previousParagraph.Column != processor.Column && (parent is QuoteBlock or ListItemBlock))
                {
                    isSetexHeading = false;
                }
            }

            if (breakCharCount < 3 || isSetexHeading)
            {
                return(BlockState.None);
            }

            // Push a new block
            var thematicBreak = new ThematicBreakBlock(this)
            {
                Column            = processor.Column,
                Span              = new SourceSpan(startPosition, line.End),
                ThematicChar      = breakChar,
                ThematicCharCount = breakCharCount,
                // TODO: should we separate whitespace before/after?
                //BeforeWhitespace = beforeWhitespace,
                //AfterWhitespace = processor.PopBeforeWhitespace(processor.CurrentLineStartPosition),
                Content = new StringSlice(line.Text, processor.TriviaStart, line.End, line.NewLine), //include whitespace for now
            };

            if (processor.TrackTrivia)
            {
                thematicBreak.LinesBefore = processor.UseLinesBefore();
                thematicBreak.NewLine     = processor.Line.NewLine;
            }

            processor.NewBlocks.Push(thematicBreak);
            return(BlockState.BreakDiscard);
        }
Esempio n. 8
0
 protected override MarkdownSeparator CreateSeparator(ThematicBreakBlock thematicBlock) => new OsuMarkdownSeparator();