MarkdigExtensions.Query
1.0.7
dotnet add package MarkdigExtensions.Query --version 1.0.7
NuGet\Install-Package MarkdigExtensions.Query -Version 1.0.7
<PackageReference Include="MarkdigExtensions.Query" Version="1.0.7" />
<PackageVersion Include="MarkdigExtensions.Query" Version="1.0.7" />
<PackageReference Include="MarkdigExtensions.Query" />
paket add MarkdigExtensions.Query --version 1.0.7
#r "nuget: MarkdigExtensions.Query, 1.0.7"
#:package MarkdigExtensions.Query@1.0.7
#addin nuget:?package=MarkdigExtensions.Query&version=1.0.7
#tool nuget:?package=MarkdigExtensions.Query&version=1.0.7
MarkdigExtensions.Query ๐๐
MarkdigExtensions.Query is a powerful, jQuery-style query engine for traversing, filtering, and manipulating Markdown documents in .NET. Built on top of the Markdig Markdown parser, it provides an expressive API for searching and transforming Markdown nodes with CSS-like selectors and familiar LINQ-style chaining.
๐ Features
- ๐ CSS-style Selectors: Query blocks and inlines with tags (
h1
,link
,table
), attributes, wildcards, and combinators. - ๐งฉ Chaining & Filtering: Use
.Where()
,.Select()
,.NextUntil()
, and more for precise control. - โก Pseudo-Selectors: Supports
first-child
,last-child
,even
,odd
,nth-child(n)
. - ๐ฌ Text & HTML Access: Easily get
.InnerText
,.InnerHtml
,.ToMarkdown()
from any node. - ๐ง Node Metadata: Use
.Attr()
to inspect node details likehref
,level
, orisImage
. - ๐งต Sibling & Linear Traversals: Navigate using
NextUntil
,PrevUntil
, orBetween
.
๐ฆ Installation
Install from NuGet:
dotnet add package MarkdigExtensions.Query
๐ ๏ธ Getting Started
using Markdig;
using MarkdigExtensions.Query;
// Parse a Markdown document
var markdown = """
# Welcome to the Test Suite
This document is **bold** and .
---
## Next Section
""";
var doc = Markdown.Parse(markdown);
// Query all heading blocks
var headings = doc.QueryBlocks("h1, h2");
// Get text from the first heading
var title = headings.First().InnerText; // "Welcome to the Test Suite"
// Find all paragraphs between H1 and HR
var section = doc.QueryBlock("h1")?.NextUntil("hr");
๐ Selector Syntax
Selector | Description |
---|---|
h1 |
Matches all level 1 headings |
link[href] |
Matches links with an href attribute |
heading > strong |
Matches strong text directly inside headings |
image, link |
Matches either image or link elements |
* |
Matches any block or inline node |
Pseudo-classes:
first-child
last-child
even
odd
nth-child(n)
๐ง API Overview
Query Methods
document.QueryBlocks("selector")
Returns IEnumerable<MarkdownNode>
MarkdownNode Access
node.InnerText // Clean text content
node.InnerHtml // HTML rendering
node.ToMarkdown() // Original markdown
node.Attr("href") // e.g., link URL
node.Attr() // Dictionary of attributes
Traversal
node.NextUntil("selector", includeStart: false, includeEnd: false, blockOnly: true)
node.PrevUntil("selector")
node.Between(startNode, endNode)
๐ง Advanced Examples
Group all paragraphs between two headings
var intro = doc
.QueryBlock("h1")
?.NextUntil("h2", includeStart: false, includeEnd: false);
Select all emphasized text inside a paragraph
var emphasis = doc.QueryBlock("paragraph emphasis");
Wildcard + pseudo-class combo
var firstOfEach = doc.QueryBlock("*:first-child");
โ Use Cases
- Build markdown content editors or analyzers
- Wrap sections between headings
- Validate document structure
- Extract or transform specific content programmatically
๐ Links
Thanks for using MarkdigExtensions.Query! Enjoy writing powerful, expressive markdown transformations โ just like jQuery for documents.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Markdig (>= 0.41.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MarkdigExtensions.Query:
Package | Downloads |
---|---|
VeeFriends.WikiImporter
VeeFriends Wiki Importer - A .NET library for automating the import of character data from ClickUp, enhanced with AI and media integrations. |
GitHub repositories
This package is not used by any popular GitHub repositories.