public void Validate(IMarkdownObject markdownObject) { if (markdownObject is TObject obj) { _validator?.Invoke(obj); } }
/// <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>();
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level) { switch (markdownObject) { case YamlFrontMatterBlock _: // Don't parse YAML Frontmatter break; case ListItemBlock listItemBlock: bool isOrdered = ((ListBlock)listItemBlock.Parent)?.IsOrdered == true; OsuMarkdownListItem childContainer = CreateListItem(listItemBlock, level, isOrdered); container.Add(childContainer); foreach (var single in listItemBlock) { base.AddMarkdownComponent(single, childContainer.Content, level); } break; default: base.AddMarkdownComponent(markdownObject, container, level); break; } }
public static void Transverse <T>(this IMarkdownObject obj, Action <T> action) where T : Inline { if (obj is T lft) { action(lft); } else if (obj is ContainerBlock cblk) { foreach (var item in cblk) { item?.Transverse(action); } } else if (obj is LeafBlock lblk) { lblk.Inline?.Transverse(action); } else if (obj is ContainerInline ctk) { foreach (var item in ctk) { item?.Transverse(action); } } }
public void PreProcess(IMarkdownObject markdownObject) { using (string.IsNullOrEmpty(Scope) ? null : new LoggerPhaseScope(Scope)) { Inner.PreProcess(markdownObject); } }
public IMarkdownObject Rewrite(IMarkdownObject markdownObject) { using (string.IsNullOrEmpty(Scope) ? null : new LoggerPhaseScope(Scope)) { return(Inner.Rewrite(markdownObject)); } }
public CodeBlock(IMarkdownObject mdo) : base(mdo) { if (mdo is FencedCodeBlock cb) { this.Content = cb.Lines.ToString(); } }
public void PreProcess(IMarkdownObject markdownObject) { _preProcess?.Invoke(markdownObject); foreach (var validator in Validators) { validator.PreValidate(markdownObject); } }
public void PostProcess(IMarkdownObject markdownObject) { foreach (var validator in Validators) { validator.PostValidate(markdownObject); } _postProcess?.Invoke(markdownObject); }
public IMarkdownObject Rewrite(IMarkdownObject markdownObject) { foreach (var validator in Validators) { validator.Validate(markdownObject); } return(markdownObject); }
protected override void AddMarkdownComponent(IMarkdownObject markdownObject, FillFlowContainer container, int level) { // hide hidden message in markdown document if (markdownObject is YamlFrontMatterBlock) { return; } base.AddMarkdownComponent(markdownObject, container, level); }
/// <summary> /// Gets or creates the <see cref="HtmlAttributes"/> stored on a <see cref="MarkdownObject"/> /// </summary> /// <param name="obj">The markdown object.</param> /// <returns>The attached html attributes</returns> public static HtmlAttributes GetAttributes(this IMarkdownObject obj) { var attributes = obj.GetData(Key) as HtmlAttributes; if (attributes == null) { attributes = new HtmlAttributes(); obj.SetAttributes(attributes); } return(attributes); }
public static IEnumerable <Tag> Convert(IMarkdownObject markdownObject) { if (markdownObject is HtmlBlock block) { return(Convert(block)); } if (markdownObject is HtmlInline inline) { return(Convert(inline)); } return(null); }
public void Validate(IMarkdownObject markdownObject) { var tags = Tag.Convert(markdownObject); if (tags == null) { return; } foreach (var tag in tags) { foreach (var validator in Validators) { ValidateOne(tag, validator); } } }
public static async Task TransverseAsync <T>(this IMarkdownObject obj, Func <T, Task> action) where T : Inline { if (obj is T lft) { await action(lft); } else if (obj is ContainerBlock cblk) { foreach (var item in cblk) { await item.TransverseAsync(action); } } else if (obj is LeafBlock lblk && lblk.Inline != null) { await lblk.Inline.TransverseAsync(action); }
public override IMarkdownObject Rewrite(IMarkdownObject markdownObject) { if (markdownObject is FencedCodeBlock fencedCode && !string.IsNullOrEmpty(fencedCode.Info)) { var attributes = fencedCode.GetAttributes(); var language = GetLanguage(fencedCode.Info, out bool isInteractive); if (string.IsNullOrEmpty(language) || !isInteractive) { return(markdownObject); } attributes.AddProperty("data-interactive", WebUtility.HtmlEncode(language)); UpdateFencedCodeLanguage(attributes, fencedCode.Info, language); } return(markdownObject); }
public IMarkdownObject Rewrite(IMarkdownObject markdownObject) { if (markdownObject is TabGroupBlock block) { var items = block.Items.ToList(); var firstVisibleTab = ApplyTabVisible(tabSelectionInfo, items); var idAndCountList = GetTabIdAndCountList(items).ToList(); if (idAndCountList.Any(g => g.Item2 > 1)) { Logger.LogWarning($"Duplicate tab id: {string.Join(",", idAndCountList.Where(g => g.Item2 > 1))}."); } var active = GetTabActive(block, tabSelectionInfo, items, firstVisibleTab, idAndCountList); block.ActiveTabIndex = active; block.Items = items.ToImmutableArray(); return(block); } return(markdownObject); }
public override IMarkdownObject Rewrite(IMarkdownObject markdownObject) { if (markdownObject is CodeSnippet codeSnippet) { codeSnippet.Language = GetLanguage(codeSnippet.Language, out bool isInteractive); codeSnippet.IsInteractive = isInteractive; if (isInteractive) { var url = GetGitUrl(codeSnippet); if (!string.IsNullOrEmpty(url)) { codeSnippet.GitUrl = url; } return(codeSnippet); } } return(markdownObject); }
public IMarkdownObject Rewrite(IMarkdownObject markdownObject) { if (markdownObject is HeadingBlock block) { if (block.Inline.Count() <= 2) { return(block); } var id = ParseHeading(block); if (string.IsNullOrEmpty(id)) { return(block); } var attribute = block.GetAttributes(); attribute.Id = id; return(RemoveHtmlTag(block)); } return(markdownObject); }
public IMarkdownObject Rewrite(IMarkdownObject markdownObject) { if (markdownObject is TabGroupBlock block) { var groupId = block.Id; while (true) { if (_dict.TryGetValue(groupId, out int index)) { groupId = $"{groupId}-{index}"; index += 1; block.Id = groupId; return(block); } else { _dict.Add(groupId, 1); return(markdownObject); } } } return(markdownObject); }
public ListItem(IMarkdownObject mdo) : base(mdo) { }
/// <summary> /// Tries the get <see cref="HtmlAttributes"/> stored on a <see cref="MarkdownObject"/>. /// </summary> /// <param name="obj">The markdown object.</param> /// <returns>The attached html attributes or null if not found</returns> public static HtmlAttributes TryGetAttributes(this IMarkdownObject obj) { return(obj.GetData(Key) as HtmlAttributes); }
public Placeholder(IMarkdownObject mdo) : base(mdo) => this.Name = mdo.GetType().Name;
public NotImplementedMarkdown(IMarkdownObject markdownObject) { this.markdownObject = markdownObject; AutoSizeAxes = Axes.Y; }
/// <summary> /// Sets <see cref="HtmlAttributes" /> to the <see cref="MarkdownObject" /> /// </summary> /// <param name="obj">The markdown object.</param> /// <param name="attributes">The attributes to attach.</param> public static void SetAttributes(this IMarkdownObject obj, HtmlAttributes attributes) { obj.SetData(Key, attributes); }
protected Element(IMarkdownObject mdo) : this() { this.Attributes = new ElementAttributes(mdo.GetAttributes(), this); }
public ExplicitInlineContainer(IMarkdownObject mdo) : base(mdo) { }
public void PreValidate(IMarkdownObject markdownObject) { _preAction?.Invoke(markdownObject); }
public void PreProcess(IMarkdownObject markdownObject) { }
public void PostValidate(IMarkdownObject markdownObject) { _postAction?.Invoke(markdownObject); }