<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Takahiro Sato</title>
    <description>The latest articles on Forem by Takahiro Sato (@harehare).</description>
    <link>https://forem.com/harehare</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F42641%2F46167df6-346a-4305-8613-e432f7295a7e.jpeg</url>
      <title>Forem: Takahiro Sato</title>
      <link>https://forem.com/harehare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/harehare"/>
    <language>en</language>
    <item>
      <title>Compose Your Markdown Workflow: mq Subcommands + Unix Pipes</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sat, 14 Feb 2026 14:01:49 +0000</pubDate>
      <link>https://forem.com/harehare/compose-your-markdown-workflow-mq-subcommands-unix-pipes-37ph</link>
      <guid>https://forem.com/harehare/compose-your-markdown-workflow-mq-subcommands-unix-pipes-37ph</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fht8wd4ptq6nk4a64ozie.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fht8wd4ptq6nk4a64ozie.gif" alt=" " width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Piping mq Subcommands Together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;mq&lt;/a&gt; is a jq-like CLI for Markdown. Beyond its query engine, mq comes with a set of external subcommands:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Subcommand&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mq conv&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Convert Excel, PDF, Word, HTML, etc. to Markdown&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mq edit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Terminal-based Markdown editor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mq view&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Markdown viewer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mq task&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Markdown-based task runner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mq tui&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Interactive TUI for trying queries&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;They all work with stdin/stdout, so you can pipe them together.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Few Examples
&lt;/h2&gt;

&lt;p&gt;Pull headers out of an Excel file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq conv report.xlsx | mq edit | mq &lt;span class="s1"&gt;'.h'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extract h2s from a Word doc and open them in the editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq conv meeting-notes.docx | mq &lt;span class="s1"&gt;'.h2'&lt;/span&gt; | mq edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Grab headings from a web page and view them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; https://mqlang.org | mq &lt;span class="nt"&gt;-I&lt;/span&gt; html &lt;span class="s1"&gt;'select(.h1 || .h2)'&lt;/span&gt; | mq view
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Merge multiple files with separators:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;-S&lt;/span&gt; &lt;span class="s1"&gt;'"---"'&lt;/span&gt; &lt;span class="s1"&gt;'identity'&lt;/span&gt; chapter1.md chapter2.md chapter3.md | mq view
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each subcommand has a single job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mq conv  → convert to Markdown
mq       → query and transform
mq edit  → edit
mq view  → display
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Custom Subcommands
&lt;/h2&gt;

&lt;p&gt;Drop an executable named &lt;code&gt;mq-*&lt;/code&gt; into &lt;code&gt;~/.mq/bin/&lt;/code&gt; or your &lt;code&gt;PATH&lt;/code&gt;, and it becomes a subcommand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="nt"&gt;--list&lt;/span&gt;  &lt;span class="c"&gt;# see all available subcommands&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;mq&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq_conv" rel="noopener noreferrer"&gt;mq conv&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq_edit" rel="noopener noreferrer"&gt;mq edit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq_task" rel="noopener noreferrer"&gt;mq task&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq_tui" rel="noopener noreferrer"&gt;mq tui&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq_view" rel="noopener noreferrer"&gt;mq view&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>cli</category>
      <category>productivity</category>
      <category>rust</category>
    </item>
    <item>
      <title>mx: Turn Your Documentation into Executable Tasks</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Fri, 10 Oct 2025 14:17:57 +0000</pubDate>
      <link>https://forem.com/harehare/mx-turn-your-documentation-into-executable-tasks-58g7</link>
      <guid>https://forem.com/harehare/mx-turn-your-documentation-into-executable-tasks-58g7</guid>
      <description>&lt;p&gt;mx is a task runner that executes code blocks directly from Markdown files based on section titles.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2For316lbak5ew1569xk9d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2For316lbak5ew1569xk9d.gif" alt="demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is mx?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mx&lt;/code&gt; is a command-line task runner that treats your Markdown files as executable documentation. Instead of maintaining separate task scripts and documentation, you can keep everything in one place—typically your &lt;code&gt;README.md&lt;/code&gt;—and execute tasks directly from there.&lt;/p&gt;

&lt;p&gt;Built on top of &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;mq&lt;/a&gt;, a jq-like command-line tool for Markdown processing, mx parses your Markdown documents and executes the code blocks within specific sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why mx?
&lt;/h2&gt;

&lt;p&gt;Traditional task runners require you to maintain separate files from your documentation. With mx, your documentation &lt;em&gt;is&lt;/em&gt; your task runner. This approach offers several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single source of truth&lt;/strong&gt;: No synchronization issues between docs and scripts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Self-documenting&lt;/strong&gt;: Your tasks include their own documentation naturally&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discoverable&lt;/strong&gt;: New team members can find and understand tasks easily&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-language support&lt;/strong&gt;: Automatically detects and executes code in different languages&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero configuration&lt;/strong&gt;: Works out of the box, with optional customization&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick Start
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;The fastest way to install mx is using the installation script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; https://raw.githubusercontent.com/harehare/mx/refs/heads/main/bin/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, if you have Rust installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/harehare/mx.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Usage
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;README.md&lt;/code&gt; with some tasks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Build&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
cargo build --release
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Test&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
cargo test
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Deploy&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
./scripts/deploy.sh production
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;List available tasks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run a specific task:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx Build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! mx will execute the bash code block under the "Build" section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Multi-Language Runtime Support
&lt;/h3&gt;

&lt;p&gt;One of mx's most powerful features is its ability to automatically detect and execute code blocks in different programming languages. Simply specify the language in your code block, and mx will use the appropriate runtime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Python Analysis&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;python
import pandas as pd
df = pd.read_csv('data.csv')
print(df.describe())
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Node.js Build&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;javascript
const esbuild = require('esbuild');
esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'dist/bundle.js',
});
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Go Benchmark&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;go
package main
import (
    "fmt"
    "time"
)
func main() {
    start := time.Now()
    // Your code here
    fmt.Printf("Execution time: %v&lt;span class="se"&gt;\n&lt;/span&gt;", time.Since(start))
}
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Ruby Script&lt;/span&gt;

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;ruby
require 'json'
data = JSON.parse(File.read('config.json'))
puts "Config loaded: #{data.keys.join(', ')}"
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run any of these with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx &lt;span class="s2"&gt;"Python Analysis"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Node.js Build"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Go Benchmark"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Ruby Script"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;mx automatically uses the correct runtime for each language—no need to specify or configure anything!&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Configurable Runtimes
&lt;/h3&gt;

&lt;p&gt;While mx works out of the box with sensible defaults, you can customize runtime environments to match your needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates an &lt;code&gt;mx.toml&lt;/code&gt; configuration file where you can specify custom runtimes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;heading_level&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="nn"&gt;[runtimes]&lt;/span&gt;
&lt;span class="py"&gt;bash&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"bash"&lt;/span&gt;
&lt;span class="py"&gt;sh&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"sh"&lt;/span&gt;
&lt;span class="py"&gt;python&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"python3"&lt;/span&gt;
&lt;span class="py"&gt;ruby&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ruby"&lt;/span&gt;
&lt;span class="py"&gt;node&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"node"&lt;/span&gt;
&lt;span class="py"&gt;javascript&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"node"&lt;/span&gt;
&lt;span class="py"&gt;js&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"node"&lt;/span&gt;
&lt;span class="py"&gt;php&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"php"&lt;/span&gt;
&lt;span class="py"&gt;perl&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"perl"&lt;/span&gt;

&lt;span class="nn"&gt;[runtimes.go]&lt;/span&gt;
&lt;span class="py"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"go run"&lt;/span&gt;
&lt;span class="py"&gt;execution_mode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"file"&lt;/span&gt;

&lt;span class="nn"&gt;[runtimes.mq]&lt;/span&gt;
&lt;span class="py"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"mq"&lt;/span&gt;
&lt;span class="py"&gt;execution_mode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"arg"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Simple Runtime Configuration
&lt;/h4&gt;

&lt;p&gt;For most languages, you can use a simple string format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[runtimes]&lt;/span&gt;
&lt;span class="py"&gt;python&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"pypy3"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This uses the default execution mode (&lt;code&gt;stdin&lt;/code&gt;), where code is passed via standard input.&lt;/p&gt;

&lt;h4&gt;
  
  
  Advanced Runtime Configuration
&lt;/h4&gt;

&lt;p&gt;Some languages require different execution modes. You can specify these using the detailed configuration format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[runtimes.go]&lt;/span&gt;
&lt;span class="py"&gt;command&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"go run"&lt;/span&gt;
&lt;span class="py"&gt;execution_mode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"file"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Available Execution Modes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;stdin&lt;/code&gt;&lt;/strong&gt; (default): Code is passed via standard input (works for Python, Ruby, Node.js, etc.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;file&lt;/code&gt;&lt;/strong&gt;: Code is written to a temporary file and the file path is passed as an argument (required for Go)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;arg&lt;/code&gt;&lt;/strong&gt;: Code is passed directly as a command-line argument (used for specialized tools like mq)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This flexibility means you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use different Python versions (python3.11, pypy, etc.)&lt;/li&gt;
&lt;li&gt;Switch between Node.js and Deno&lt;/li&gt;
&lt;li&gt;Use custom interpreters or compilers&lt;/li&gt;
&lt;li&gt;Configure the appropriate execution mode for each language&lt;/li&gt;
&lt;li&gt;Add support for any language with a CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Executable Documentation
&lt;/h3&gt;

&lt;p&gt;mx turns your documentation into a living, executable artifact. Instead of documenting commands that might become outdated, you document runnable tasks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Setup Development Environment&lt;/span&gt;

Install all dependencies and initialize the database.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
&lt;span class="gh"&gt;# Install npm dependencies&lt;/span&gt;
npm install

&lt;span class="gh"&gt;# Setup database&lt;/span&gt;
npx prisma migrate dev

&lt;span class="gh"&gt;# Generate API client&lt;/span&gt;
npm run generate:api
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Start Development Server&lt;/span&gt;

Runs the application in development mode with hot reloading enabled.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
npm run dev
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Run Tests with Coverage&lt;/span&gt;

Executes the full test suite and generates a coverage report.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
npm run test:coverage
open coverage/index.html
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your documentation is always in sync with what actually runs, because they're the same thing!&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Use Case: Polyglot Projects
&lt;/h2&gt;

&lt;p&gt;mx really shines in projects that use multiple programming languages. Here's an example from a typical web application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Setup&lt;/span&gt;

Install all dependencies across the stack.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;bash
npm install
pip install -r requirements.txt
go mod download
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Frontend Build&lt;/span&gt;

Bundle and optimize the React application.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;javascript
const esbuild = require('esbuild');
esbuild.build({
  entryPoints: ['frontend/src/index.tsx'],
  bundle: true,
  minify: true,
  outfile: 'dist/app.js',
}).catch(() =&amp;gt; process.exit(1));
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Backend Test&lt;/span&gt;

Run the Python backend test suite.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;python
import pytest
import sys

result = pytest.main(['-v', 'tests/'])
sys.exit(result)
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Data Migration&lt;/span&gt;

Execute Go-based database migration.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;go
package main
import (
    "database/sql"
    "log"
    _ "github.com/lib/pq"
)
func main() {
    db, err := sql.Open("postgres", "...")
    if err != nil {
        log.Fatal(err)
    }
    // Migration logic here
}
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;

&lt;span class="gu"&gt;## Generate API Docs&lt;/span&gt;

Create API documentation from OpenAPI spec.

&lt;span class="se"&gt;\`\`\`&lt;/span&gt;ruby
require 'yaml'
require 'erb'

spec = YAML.load_file('openapi.yaml')
template = ERB.new(File.read('docs/template.erb'))
File.write('docs/api.html', template.result(binding))
&lt;span class="se"&gt;\`\`\`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With mx, you can run all these tasks seamlessly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx Setup
mx &lt;span class="s2"&gt;"Frontend Build"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Backend Test"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Data Migration"&lt;/span&gt;
mx &lt;span class="s2"&gt;"Generate API Docs"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each task automatically uses the appropriate runtime based on the code block language!&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Multiple Documentation Files
&lt;/h3&gt;

&lt;p&gt;Organize complex projects with multiple task files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx &lt;span class="nt"&gt;-f&lt;/span&gt; docs/deployment.md &lt;span class="s2"&gt;"Deploy to Production"&lt;/span&gt;
mx &lt;span class="nt"&gt;-f&lt;/span&gt; docs/maintenance.md &lt;span class="s2"&gt;"Database Backup"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Custom Heading Levels
&lt;/h3&gt;

&lt;p&gt;Prefer using &lt;code&gt;###&lt;/code&gt; for tasks? Configure it in &lt;code&gt;mx.toml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;heading_level&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Task Discovery
&lt;/h3&gt;

&lt;p&gt;New to a project? List all available tasks to see what you can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mx
&lt;span class="c"&gt;# or&lt;/span&gt;
mx list &lt;span class="nt"&gt;--file&lt;/span&gt; docs/tasks.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Cases
&lt;/h2&gt;

&lt;p&gt;mx is perfect for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Open Source Projects&lt;/strong&gt;: Make it easy for contributors to discover and run common tasks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polyglot Microservices&lt;/strong&gt;: Manage tasks across services written in different languages&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Sites&lt;/strong&gt;: Keep your documentation examples executable and tested&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Onboarding&lt;/strong&gt;: New developers learn about and run tasks from one place&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD Workflows&lt;/strong&gt;: Document deployment procedures that can be executed locally or in pipelines&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Science&lt;/strong&gt;: Combine Python analysis, R scripts, and bash data processing in one place&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Current Status
&lt;/h2&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Note&lt;/strong&gt;: mx is currently under active development. While it's functional and usable, the API and features may change as the project evolves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contributing
&lt;/h2&gt;

&lt;p&gt;mx is open source and welcomes contributions! Check out the &lt;a href="https://github.com/harehare/mx" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Report issues&lt;/li&gt;
&lt;li&gt;Suggest features&lt;/li&gt;
&lt;li&gt;Submit pull requests&lt;/li&gt;
&lt;li&gt;Star the project ⭐&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;mx brings together documentation and automation in a natural way. By treating Markdown as executable documentation and providing seamless multi-language runtime support, it eliminates the gap between what you document and what you actually run.&lt;/p&gt;

&lt;p&gt;If you're working on projects that use multiple programming languages and want your documentation to stay in sync with your actual workflows, give mx a try!&lt;/p&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;del&gt;&lt;a href="https://github.com/harehare/mx" rel="noopener noreferrer"&gt;https://github.com/harehare/mx&lt;/a&gt;&lt;/del&gt; &lt;a href="https://github.com/harehare/mq-task" rel="noopener noreferrer"&gt;https://github.com/harehare/mq-task&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;mq (underlying parser): &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;https://github.com/harehare/mq&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;License: MIT&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>productivity</category>
      <category>markdown</category>
      <category>cli</category>
      <category>rust</category>
    </item>
    <item>
      <title>Processing Markdown in Python with mq</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sun, 27 Jul 2025 13:29:53 +0000</pubDate>
      <link>https://forem.com/harehare/processing-markdown-in-python-with-mq-2al5</link>
      <guid>https://forem.com/harehare/processing-markdown-in-python-with-mq-2al5</guid>
      <description>&lt;p&gt;The &lt;a href="https://pypi.org/project/markdown-query/" rel="noopener noreferrer"&gt;&lt;code&gt;markdown-query&lt;/code&gt;&lt;/a&gt; package brings the functionality of the mq Markdown processor to Python. &lt;a href="https://mqlang.org" rel="noopener noreferrer"&gt;mq&lt;/a&gt; uses a jq-like syntax to filter, transform, and extract data from Markdown documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;markdown-query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;The primary interface is the &lt;code&gt;run()&lt;/code&gt; function, which takes three parameters: a query string, markdown content, and optional configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;

&lt;span class="n"&gt;markdown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;# Title

This is a paragraph.

## Section

- Item 1
- Item 2

``javascript
console.log(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;);
``
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

&lt;span class="c1"&gt;# Extract all headings
&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.h1 || .h2)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# ['# Title', '## Section']
&lt;/span&gt;
&lt;span class="c1"&gt;# Get heading text without markdown formatting
&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.h1 || .h2) | to_text()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# ['Title', 'Section']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Working with Different Input Formats
&lt;/h2&gt;

&lt;p&gt;The library supports multiple input formats through the Options class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;

&lt;span class="c1"&gt;# Process HTML input
&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;h1&amp;gt;Title&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;Content&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Item&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InputFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTML&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.h1 | upcase()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# ['# TITLE']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Available input formats:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;InputFormat.MARKDOWN&lt;/code&gt; (default)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;InputFormat.HTML&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;InputFormat.MDX&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;InputFormat.TEXT&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Query Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Extract Code Blocks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Get all code blocks
&lt;/span&gt;&lt;span class="n"&gt;code_blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.code)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Get code block content as text
&lt;/span&gt;&lt;span class="n"&gt;code_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.code) | to_text()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Filter by Content
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Find headings containing specific text
&lt;/span&gt;&lt;span class="n"&gt;headings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;select(.h1 || .h2) | select(test(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Section&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Extract list items
&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.[] | to_text()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Transform Content
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Convert headings to uppercase
&lt;/span&gt;&lt;span class="n"&gt;upper_headings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.h1, .h2) | upcase()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Replace text in paragraphs
&lt;/span&gt;&lt;span class="n"&gt;modified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;select(.paragraph) | gsub(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;paragraph&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Accessing Result Data
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;run()&lt;/code&gt; function returns an &lt;code&gt;MQResult&lt;/code&gt; object with a &lt;code&gt;values&lt;/code&gt; list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.h1)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Access all values
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Access individual items
&lt;/span&gt;&lt;span class="n"&gt;first_heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;           &lt;span class="c1"&gt;# Text content
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;markdown_type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# MarkdownType enum
&lt;/span&gt;
&lt;span class="c1"&gt;# Iterate over results
&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Type: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;markdown_type&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, Text: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration with Other Tools
&lt;/h2&gt;

&lt;p&gt;The library works well with other Python markdown processing tools:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;markitdown&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;MarkItDown&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;

&lt;span class="c1"&gt;# Convert web pages to markdown, then process with mq
&lt;/span&gt;&lt;span class="n"&gt;markitdown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MarkItDown&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;markitdown&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Extract specific content
&lt;/span&gt;&lt;span class="n"&gt;code_samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.code | to_text()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text_content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;all_links&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.link | to_html()&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text_content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuration Options
&lt;/h2&gt;

&lt;p&gt;The Options class provides additional configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input_format&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;InputFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTML&lt;/span&gt;
&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;list_style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ListStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PLUS&lt;/span&gt;      &lt;span class="c1"&gt;# Use + for lists
&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;link_title_style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TitleSurroundStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SINGLE&lt;/span&gt;
&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;link_url_style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UrlSurroundStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ANGLE&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;select(.list)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Error Handling
&lt;/h2&gt;

&lt;p&gt;Queries that fail will raise a &lt;code&gt;PyRuntimeError&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;invalid_query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;RuntimeError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Query failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;The library is built on Rust and compiled to native code, providing fast processing for large markdown files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Interactive Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=harehare.vscode-mq" rel="noopener noreferrer"&gt;VSCode Extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://pypi.org/project/markdown-query/" rel="noopener noreferrer"&gt;&lt;code&gt;markdown-query&lt;/code&gt;&lt;/a&gt; package provides a straightforward way to apply mq's markdown processing capabilities in Python applications, from simple content extraction to complex document transformations.&lt;/p&gt;

</description>
      <category>python</category>
      <category>markdown</category>
      <category>cli</category>
      <category>ai</category>
    </item>
    <item>
      <title>Markdown Processing in AI Applications with mq-mcp</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sun, 13 Jul 2025 10:17:43 +0000</pubDate>
      <link>https://forem.com/harehare/markdown-processing-in-ai-applications-with-mq-mcp-cnl</link>
      <guid>https://forem.com/harehare/markdown-processing-in-ai-applications-with-mq-mcp-cnl</guid>
      <description>&lt;p&gt;AI assistants frequently work with Markdown content from documentation, blogs, and technical articles. Processing this content programmatically requires extracting specific elements, transforming structure, and filtering based on criteria. The Model Context Protocol (MCP) provides a standardized way for AI systems to access external tools and data sources.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mq-mcp&lt;/code&gt; combines the Markdown processing capabilities of the &lt;code&gt;mq&lt;/code&gt; tool with MCP, allowing AI assistants to perform content analysis through a standard interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model Context Protocol Integration
&lt;/h2&gt;

&lt;p&gt;MCP enables AI assistants to interact with external tools using JSON-RPC 2.0. &lt;code&gt;mq-mcp&lt;/code&gt; implements an MCP server that exposes four primary tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;html_to_markdown&lt;/code&gt;&lt;/strong&gt;: Converts HTML to Markdown with optional query processing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;extract_markdown&lt;/code&gt;&lt;/strong&gt;: Processes Markdown content using mq queries&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;available_functions&lt;/code&gt;&lt;/strong&gt;: Lists all available mq functions with descriptions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;available_selectors&lt;/code&gt;&lt;/strong&gt;: Returns available element selectors&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuration Setup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Claude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Desktop&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"mq"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/path/to/mq"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Claude Code&lt;/span&gt;
claude mcp add mq-mcp &lt;span class="nt"&gt;--&lt;/span&gt; mq mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Content Processing Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Extracting Code Blocks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"# API Reference&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;```

javascript&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;const api = require('./api');&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;

```&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;```

python&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;import api&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;

```"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".code(&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;javascript&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;)"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Filtering Headings
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"# Main Title&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;## Section A&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;### Subsection&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;## Section B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"select(or(.h1, .h2))"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Link Extraction
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"See [API docs](./api.md) and [external guide](https://example.com/guide)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".link | select(startsWith(&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;./&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;))"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced Processing
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Transform&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;text&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"# getting started&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;## basic usage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".h | upcase()"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Filter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;conditions&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"```

bash&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;npm install&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;

```&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;```

bash&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;yarn add&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;

```"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".code | select(contains(&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;npm&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;))"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HTML to Markdown Conversion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;html_to_markdown&lt;/code&gt; function provides comprehensive HTML processing with optional query filtering. This enables AI systems to extract structured content from web pages, documentation sites, and HTML-based content.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic HTML Conversion
&lt;/h3&gt;

&lt;p&gt;Convert HTML to clean Markdown format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"html"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;div&amp;gt;&amp;lt;h1&amp;gt;API Documentation&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;This describes the REST API endpoints.&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;GET /users&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;POST /users&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# API Documentation&lt;/span&gt;

This describes the REST API endpoints.
&lt;span class="p"&gt;
-&lt;/span&gt; GET /users
&lt;span class="p"&gt;-&lt;/span&gt; POST /users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complex HTML Structure Processing
&lt;/h3&gt;

&lt;p&gt;Handle nested HTML with tables and formatted content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"html"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;article&amp;gt;&amp;lt;header&amp;gt;&amp;lt;h1&amp;gt;Database Schema&amp;lt;/h1&amp;gt;&amp;lt;/header&amp;gt;&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Column&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;id&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;INTEGER&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;name&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;VARCHAR&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;footer&amp;gt;&amp;lt;p&amp;gt;Updated: 2024&amp;lt;/p&amp;gt;&amp;lt;/footer&amp;gt;&amp;lt;/article&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"select(or(.h1, .table))"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Database Schema&lt;/span&gt;

| Column | Type    |
| ------ | ------- |
| id     | INTEGER |
| name   | VARCHAR |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Web Scraping Integration
&lt;/h3&gt;

&lt;p&gt;Extract content from live web pages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"html"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;div class='documentation'&amp;gt;&amp;lt;h2&amp;gt;Installation&amp;lt;/h2&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;npm install package&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;h2&amp;gt;Usage&amp;lt;/h2&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;const pkg = require('package');&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nodes | .code | first()"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This extracts only the installation code block, filtering out usage examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML Element Mapping
&lt;/h3&gt;

&lt;p&gt;The conversion process maps HTML elements to Markdown equivalents:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;HTML Element&lt;/th&gt;
&lt;th&gt;Markdown Output&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; - &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#&lt;/code&gt; - &lt;code&gt;######&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Header levels preserved&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Text blocks&lt;/td&gt;
&lt;td&gt;Paragraph spacing maintained&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;-&lt;/code&gt;, &lt;code&gt;1.&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;List structure preserved&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;table&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Pipe tables&lt;/td&gt;
&lt;td&gt;Column alignment detected&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;code&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;`code`&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Inline code formatting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;code blocks&lt;/td&gt;
&lt;td&gt;Code blocks with language detection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;blockquote&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Quote block formatting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;[text](url)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Links with titles preserved&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;![alt](src)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Images with alt text&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Processing Pipeline
&lt;/h3&gt;

&lt;p&gt;The HTML to Markdown conversion follows this sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;HTML Parsing&lt;/strong&gt;: DOM tree construction from input HTML&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structure Analysis&lt;/strong&gt;: Identify semantic elements and nesting&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Markdown Generation&lt;/strong&gt;: Convert elements to Markdown syntax&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Query Processing&lt;/strong&gt;: Apply mq queries to resulting structure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output Formatting&lt;/strong&gt;: Return filtered and formatted content&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Install the mq CLI tool which includes the MCP server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using Cargo&lt;/span&gt;
cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/harehare/mq.git mq-cli

&lt;span class="c"&gt;# Using Homebrew&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;harehare/tap/mq

&lt;span class="c"&gt;# Direct binary download&lt;/span&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://github.com/harehare/mq/releases/latest/download/mq-linux-x86_64 &lt;span class="nt"&gt;-o&lt;/span&gt; mq
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x mq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration Benefits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structured Processing&lt;/strong&gt;: jq-like queries enable precise content extraction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Format Flexibility&lt;/strong&gt;: Handles both HTML and Markdown inputs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discovery Features&lt;/strong&gt;: Built-in function and selector documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;mq Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/" rel="noopener noreferrer"&gt;MCP Specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;mq Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://claude.ai/docs/mcp" rel="noopener noreferrer"&gt;Claude Desktop MCP Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>markdown</category>
      <category>rust</category>
    </item>
    <item>
      <title>Efficient HTML to Markdown Conversion for LLM Input with mq-crawler</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sat, 05 Jul 2025 15:13:30 +0000</pubDate>
      <link>https://forem.com/harehare/efficient-html-to-markdown-conversion-for-llm-input-with-mq-crawler-4e2b</link>
      <guid>https://forem.com/harehare/efficient-html-to-markdown-conversion-for-llm-input-with-mq-crawler-4e2b</guid>
      <description>&lt;p&gt;LLM applications require clean, structured input data. Web content often contains HTML markup, navigation elements, and irrelevant content that degrades LLM performance. Converting HTML to clean Markdown while extracting only relevant content remains a common challenge.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mq-crawler&lt;/code&gt; addresses this by combining web crawling with HTML-to-Markdown conversion and content filtering through mq queries.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsffijzcvldl3uofrm833.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsffijzcvldl3uofrm833.gif" alt="demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Single Binary Deployment
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq-crawler&lt;/code&gt; (distributed as &lt;code&gt;mqcr&lt;/code&gt;) is a standalone binary. The single executable includes the complete web crawler, HTML parser, Markdown converter, and mq-lang query processor. This eliminates dependency management and environment setup issues common with multi-component solutions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Download and run immediately - no installation required&lt;/span&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://github.com/harehare/mq/releases/latest/download/mqcr-linux-x86_64 &lt;span class="nt"&gt;-o&lt;/span&gt; mqcr
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x mqcr
./mqcr https://docs.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Core Functionality
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq-crawler&lt;/code&gt; crawls websites, converts HTML to Markdown, and processes content with mq-lang queries. The tool respects robots.txt, implements rate limiting, and supports concurrent processing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Basic crawling with markdown output&lt;/span&gt;
mqcr https://docs.example.com

&lt;span class="c"&gt;# Extract specific content sections&lt;/span&gt;
mqcr &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s1"&gt;'.h2 | select(contains("API"))'&lt;/span&gt; https://docs.example.com

&lt;span class="c"&gt;# Parallel crawling with 4 workers&lt;/span&gt;
mqcr &lt;span class="nt"&gt;-c&lt;/span&gt; 4 &lt;span class="nt"&gt;-o&lt;/span&gt; ./output https://docs.example.com

&lt;span class="c"&gt;# Crawl only the specified URL (no recursion)&lt;/span&gt;
mqcr &lt;span class="nt"&gt;--depth&lt;/span&gt; 0 https://docs.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HTML to Markdown Conversion
&lt;/h2&gt;

&lt;p&gt;The conversion process handles complex HTML structures:&lt;/p&gt;

&lt;h3&gt;
  
  
  Table Processing
&lt;/h3&gt;

&lt;p&gt;HTML tables convert to properly formatted Markdown tables with column alignment detection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Input HTML&lt;/span&gt;
&amp;lt;table&amp;gt;
  &amp;lt;&lt;span class="nb"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;lt;th&amp;gt;Method&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Endpoint&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;
  &amp;lt;&lt;span class="nb"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;lt;td&amp;gt;GET&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;/api/users&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;List &lt;span class="nb"&gt;users&lt;/span&gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;

&lt;span class="c"&gt;# Output Markdown&lt;/span&gt;
| Method | Endpoint   | Description |
| &lt;span class="nt"&gt;------&lt;/span&gt; | &lt;span class="nt"&gt;----------&lt;/span&gt; | &lt;span class="nt"&gt;-----------&lt;/span&gt; |
| GET    | /api/users | List &lt;span class="nb"&gt;users&lt;/span&gt;  |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Concurrent Processing
&lt;/h2&gt;

&lt;p&gt;The crawler supports parallel processing for efficiency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Process multiple pages concurrently&lt;/span&gt;
mqcr &lt;span class="nt"&gt;-c&lt;/span&gt; 8 &lt;span class="nt"&gt;--crawl-delay&lt;/span&gt; 1.0 https://docs.example.com

&lt;span class="c"&gt;# Configure timeouts for different operations&lt;/span&gt;
mqcr &lt;span class="nt"&gt;--page-load-timeout&lt;/span&gt; 30 &lt;span class="nt"&gt;--script-timeout&lt;/span&gt; 10 &lt;span class="nt"&gt;--implicit-timeout&lt;/span&gt; 5 https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Timeout options control different aspects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--page-load-timeout&lt;/code&gt;: Full page loading (default: 30s)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--script-timeout&lt;/code&gt;: JavaScript execution (default: 10s)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--implicit-timeout&lt;/code&gt;: Element finding (default: 5s)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Content Filtering with mq Queries
&lt;/h2&gt;

&lt;p&gt;mq-crawler processes content through mq-lang queries for targeted extraction:&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Example Collection
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract all code examples with context&lt;/span&gt;
mqcr &lt;span class="nt"&gt;-q&lt;/span&gt; &lt;span class="s1"&gt;'
  .code |
  {
    "language": attr("lang"),
    "code": to_text(),
  }
'&lt;/span&gt; https://tutorial.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ethical Crawling Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  robots.txt Compliance
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Respect robots.txt automatically&lt;/span&gt;
mqcr https://example.com

&lt;span class="c"&gt;# Use custom robots.txt&lt;/span&gt;
mqcr &lt;span class="nt"&gt;--robots-path&lt;/span&gt; ./custom-robots.txt https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rate Limiting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Configure crawl delays&lt;/span&gt;
mqcr &lt;span class="nt"&gt;--crawl-delay&lt;/span&gt; 2.0 https://example.com

&lt;span class="c"&gt;# Respectful concurrent crawling&lt;/span&gt;
mqcr &lt;span class="nt"&gt;-c&lt;/span&gt; 3 &lt;span class="nt"&gt;--crawl-delay&lt;/span&gt; 1.5 https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installation and Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Package Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install via Homebrew&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;harehare/tap/mqcr

&lt;span class="c"&gt;# Download pre-built binary directly&lt;/span&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://github.com/harehare/mq/releases/latest/download/mqcr-linux-x86_64 &lt;span class="nt"&gt;-o&lt;/span&gt; mqcr
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x mqcr

&lt;span class="c"&gt;# Or build from source&lt;/span&gt;
cargo &lt;span class="nb"&gt;install &lt;/span&gt;https://github.com/harehare/mq.git mq-crawler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Results and Benefits
&lt;/h2&gt;

&lt;p&gt;The mq-crawler approach provides:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single Binary Deployment&lt;/strong&gt;: immediate execution&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean Markdown Output&lt;/strong&gt;: Structured content without HTML noise&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Targeted Extraction&lt;/strong&gt;: Query-based filtering for relevant content&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ethical Compliance&lt;/strong&gt;: Automated robots.txt respect and rate limiting&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable Processing&lt;/strong&gt;: Concurrent crawling with configurable limits&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM-Ready Format&lt;/strong&gt;: Properly formatted Markdown&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This combination reduces manual preprocessing overhead while maintaining content quality for LLM applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using Homebrew&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;harehare/tap/mqcr

&lt;span class="c"&gt;# Direct binary download (no dependencies)&lt;/span&gt;
curl &lt;span class="nt"&gt;-L&lt;/span&gt; https://github.com/harehare/mq/releases/latest/download/mqcr-linux-x86_64 &lt;span class="nt"&gt;-o&lt;/span&gt; mqcr
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x mqcr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For other installation methods, including Docker and pre-built binaries, check the &lt;a href="https://mqlang.org/book/start/install.html" rel="noopener noreferrer"&gt;official installation guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq/tree/main/crates/mq-crawler" rel="noopener noreferrer"&gt;mq-crawler Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/start/crawler" rel="noopener noreferrer"&gt;mq-crawler Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/reference/" rel="noopener noreferrer"&gt;mq Query Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/start/example" rel="noopener noreferrer"&gt;mq Query Example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;mq Playground&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>crawler</category>
      <category>llm</category>
      <category>markdown</category>
      <category>automation</category>
    </item>
    <item>
      <title>In-Place Markdown Editing with mq's --update Flag</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Wed, 02 Jul 2025 15:07:59 +0000</pubDate>
      <link>https://forem.com/harehare/in-place-markdown-editing-with-mqs-update-flag-ejp</link>
      <guid>https://forem.com/harehare/in-place-markdown-editing-with-mqs-update-flag-ejp</guid>
      <description>&lt;p&gt;When managing documentation across multiple markdown files, manual editing becomes inefficient. The &lt;code&gt;mq&lt;/code&gt; command-line tool includes an &lt;code&gt;--update&lt;/code&gt; flag that modifies files in place while preserving their markdown structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7imqu6kklliaj6t6jyy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi7imqu6kklliaj6t6jyy.gif" alt="demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  In-Place File Modification
&lt;/h2&gt;

&lt;p&gt;Most markdown processors output filtered results without modifying source files. The &lt;code&gt;-U&lt;/code&gt; or &lt;code&gt;--update&lt;/code&gt; flag changes this behavior by updating the original markdown structure, replacing specific nodes with query results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Basic syntax for updates&lt;/span&gt;
mq &lt;span class="nt"&gt;--update&lt;/span&gt; &lt;span class="s1"&gt;'your_query_here'&lt;/span&gt; file.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Batch URL Updates
&lt;/h3&gt;

&lt;p&gt;Replace URLs across multiple files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Update specific URLs across all markdown files&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'if (and(or(.link, .definition), matches_url("old-domain.com"))):
  update(replace("old-domain.com", "new-domain.com"))'&lt;/span&gt; docs/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;See our &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;API docs&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://old-domain.com/api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;Reference&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="sx"&gt;https://old-domain.com/reference&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Check out our &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;API docs&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://new-domain.com/api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;Reference&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="sx"&gt;https://new-domain.com/reference&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Content Standardization
&lt;/h3&gt;

&lt;p&gt;Standardize code block languages across your documentation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Convert all 'js' code blocks to 'javascript'&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.code | if (attr("lang") == "js"): set_attr("lang", "javascript")'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Header Consistency
&lt;/h3&gt;

&lt;p&gt;Ensure consistent header formatting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Remove trailing colons from headers&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.h | if (ends_with(":")): update(rtrimstr(":"))'&lt;/span&gt; documentation.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Getting Started:&lt;/span&gt;
&lt;span class="gu"&gt;## Installation:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Getting Started&lt;/span&gt;
&lt;span class="gu"&gt;## Installation&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Link Reference Cleanup
&lt;/h3&gt;

&lt;p&gt;Update broken internal links:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Fix internal link references&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.link | if (starts_with("#old-section")): update(replace("#old-section", "#new-section"))'&lt;/span&gt; README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced Update Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Conditional Updates
&lt;/h3&gt;

&lt;p&gt;Update content based on complex conditions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Update deprecated badges&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'if (and(.image, contains("deprecated"))): update(replace("deprecated", "legacy"))'&lt;/span&gt; CHANGELOG.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selective Text Replacement
&lt;/h3&gt;

&lt;p&gt;Replace text only in specific contexts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Update version numbers only in code blocks&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.code | if (contains("v1.0")): update(replace("v1.0", "v2.0"))'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nested Element Updates
&lt;/h3&gt;

&lt;p&gt;Modify content within complex structures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Update URLs inside link text&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.link | if (matches_url("example.com")): update("newexample.com")'&lt;/span&gt; documentation/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update Safety
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Advanced Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Update + Custom Functions
&lt;/h3&gt;

&lt;p&gt;Create reusable update patterns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Save to custom.mq&lt;/span&gt;
def modernize_badges&lt;span class="o"&gt;(&lt;/span&gt;badge_text&lt;span class="o"&gt;)&lt;/span&gt;:
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;contains&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"build-passing"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;:
    replace&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"build-passing"&lt;/span&gt;, &lt;span class="s2"&gt;"build%20passing"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;:
    badge_text&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;# Use it&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'include "custom" | .image | modernize_badges()'&lt;/span&gt; README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Update + File Context
&lt;/h3&gt;

&lt;p&gt;Use file information in updates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add file-specific prefixes&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'let filename = __FILE__ | .h1 | let text = to_text() | update(s"[${filename}] ${text}")'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update Scenarios
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Documentation Maintenance
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Remove outdated warning boxes&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'select(.blockquote) | if (contains("deprecated")): update("")'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md

&lt;span class="c"&gt;# Update installation commands&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.code("bash") | if (contains("npm install old-package")): update("npm install new-package")'&lt;/span&gt; tutorials/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Link Management
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Convert relative to absolute URLs&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.link | if (starts_with("./")): update(replace("./", "https://docs.example.com/"))'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.md

&lt;span class="c"&gt;# Update image CDN URLs&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.image | if (matches_url("old-cdn.com")): update(replace("old-cdn.com", "new-cdn.com"))'&lt;/span&gt; assets/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Implementation Details
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Structure Preservation
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; parses markdown into an abstract syntax tree, unlike text replacement tools:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# This won't accidentally modify code blocks or URLs&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.text | if (contains("API")): update("Interface")'&lt;/span&gt; docs.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Element Targeting
&lt;/h3&gt;

&lt;p&gt;Queries target specific markdown elements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Only update headers, not body text&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="s1"&gt;'.h | if (contains("v1")): update(replace("v1", "v2"))'&lt;/span&gt; changelog.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Format Preservation
&lt;/h3&gt;

&lt;p&gt;Updates maintain markdown formatting conventions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Preserves link formatting styles&lt;/span&gt;
mq &lt;span class="nt"&gt;-U&lt;/span&gt; &lt;span class="nt"&gt;--link-title-style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;double &lt;span class="s1"&gt;'.link | update_text("New Title")'&lt;/span&gt; docs.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration with Workflows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CI/CD Automation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# GitHub Actions&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;harehare/setup-mq@v1&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update Documentation URLs&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;mq -U '.link | if (contains("staging.example.com")):&lt;/span&gt;
      &lt;span class="s"&gt;update(replace("staging.example.com", "example.com"))' docs/*.md&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;The easiest way to install &lt;code&gt;mq&lt;/code&gt; is through Cargo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/harehare/mq.git mq-cli &lt;span class="nt"&gt;--tag&lt;/span&gt; v0.2.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For other installation methods, including Homebrew, Docker, and pre-built binaries, check the &lt;a href="https://mqlang.org/book/start/install.html" rel="noopener noreferrer"&gt;official installation guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;--update&lt;/code&gt; flag modifies &lt;code&gt;mq&lt;/code&gt; behavior from read-only filtering to in-place file editing. The feature handles markdown transformations by operating on parsed syntax trees rather than raw text, preserving document structure during modifications.&lt;/p&gt;

&lt;p&gt;Start with simple text replacements, then implement conditional logic for complex transformations. This approach reduces manual editing overhead in documentation maintenance workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;mq Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq/tree/main/examples" rel="noopener noreferrer"&gt;Advanced Examples Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;mq Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=harehare.vscode-mq" rel="noopener noreferrer"&gt;VSCode Extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>cli</category>
      <category>rust</category>
      <category>automation</category>
    </item>
    <item>
      <title>Advanced mq Techniques: From Simple Queries to Complex Workflows</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Mon, 30 Jun 2025 00:58:57 +0000</pubDate>
      <link>https://forem.com/harehare/advanced-mq-techniques-from-simple-queries-to-complex-workflows-2m4k</link>
      <guid>https://forem.com/harehare/advanced-mq-techniques-from-simple-queries-to-complex-workflows-2m4k</guid>
      <description>&lt;p&gt;&lt;em&gt;Unleash the full power of mq for professional Markdown processing&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Beyond Basic Queries
&lt;/h2&gt;

&lt;p&gt;In my &lt;a href="https://dev.to/harehare/mq-the-missing-link-between-jq-and-markdown-bge"&gt;previous article&lt;/a&gt;, we covered the basics of &lt;code&gt;mq&lt;/code&gt;. Now let's dive into advanced techniques that make &lt;code&gt;mq&lt;/code&gt; indispensable for professional workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Selectors and Filtering
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Conditional Logic
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; supports sophisticated conditional logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract different content based on header level&lt;/span&gt;
mq &lt;span class="s1"&gt;'let text = to_text(self)
    | if (is_h1()):
      s"# Table of Contents for ${text}"
    elif (is_h2()):
      s"## ${text}"
    else:
      None'&lt;/span&gt; documentation.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complex Filtering
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Find code blocks that contain specific patterns&lt;/span&gt;
mq &lt;span class="s1"&gt;'.code | select(or(contains("async"), contains("function")))'&lt;/span&gt; api-docs.md

&lt;span class="c"&gt;# Extract headers that don't contain "deprecated"&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h | select(not(contains("deprecated")))'&lt;/span&gt; changelog.md

&lt;span class="c"&gt;# Find lists with more than 3 items&lt;/span&gt;
mq &lt;span class="s1"&gt;'.[] | select(len() &amp;gt; 3)'&lt;/span&gt; requirements.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  String Interpolation and Variables
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Using Variables
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Define reusable values&lt;/span&gt;
mq &lt;span class="nt"&gt;-I&lt;/span&gt; null &lt;span class="s1"&gt;'let project_name = "my-awesome-project" |
    let version = "1.0.0" |
    s"# ${project_name} v${version}\n\nWelcome to ${project_name}!"'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dynamic Content Generation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Generate badges dynamically&lt;/span&gt;
mq &lt;span class="nt"&gt;-I&lt;/span&gt; null &lt;span class="s1"&gt;'let lang = "rust" |
    let repo = "harehare/mq" |
    s"[![${lang}](https://img.shields.io/badge/language-${lang}-orange.svg)](https://github.com/${repo})"'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Working with Multiple Files
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Batch Processing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Process all markdown files in a directory&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h1 | to_text()'&lt;/span&gt; docs/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md

&lt;span class="c"&gt;# Combine multiple files with separators&lt;/span&gt;
mq &lt;span class="nt"&gt;-S&lt;/span&gt; &lt;span class="s1"&gt;'s"\n---\n# ${__FILE__}\n---\n"'&lt;/span&gt; &lt;span class="s1"&gt;'identity()'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md

&lt;span class="c"&gt;# Extract code examples from all files&lt;/span&gt;
mq &lt;span class="s1"&gt;'.code("javascript") | to_text()'&lt;/span&gt; tutorials/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  File-Specific Processing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add file context to extracted content&lt;/span&gt;
mq &lt;span class="s1"&gt;'let filename = __FILE__
    | let text = to_text(self)
    | .code
    | s"From ${filename}:\n${text}\n"'&lt;/span&gt; examples/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Content Transformation Workflows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Documentation Processing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Generate API documentation index&lt;/span&gt;
mq &lt;span class="s1"&gt;'select(.h2) |
    let title = to_text(self) |
    let anchor = to_link(s"#${title}", title, "") |
    to_md_list(anchor, 1)'&lt;/span&gt; api/&lt;span class="k"&gt;*&lt;/span&gt;.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; api-index.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Content Migration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Convert HTML to Markdown and extract specific sections&lt;/span&gt;
mq &lt;span class="s1"&gt;'select(or(.h1, .h2))
  | let text = to_text(self)
  | if (is_h1()):
      s"# ${text}"
    else:
      s"## ${text}"'&lt;/span&gt; legacy-docs.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  LLM and AI Workflows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prompt Engineering
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract code examples for training data&lt;/span&gt;
mq &lt;span class="s1"&gt;'.code |
    let code_content = to_text(self) |
    s"Code:\n${code_content}\n---"'&lt;/span&gt; tutorials/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Content Preparation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Prepare content for embedding&lt;/span&gt;
mq &lt;span class="s1"&gt;'select(or(.h, .text)) |
    let type = to_md_name() |
    let content = to_text(self) |
    s"${type}: ${content}"'&lt;/span&gt; knowledge-base/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced Table Processing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CSV to Markdown
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Convert CSV data to markdown tables&lt;/span&gt;
mq &lt;span class="s1"&gt;'nodes | csv2table_with_header()'&lt;/span&gt; data.csv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Custom Functions and Modules
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating Reusable Logic
&lt;/h3&gt;

&lt;p&gt;Create a file &lt;code&gt;custom.mq&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def format_api_endpoint(method, path, description):
  s"**${method}** `${path}`\n\n${description}\n";

def extract_endpoints():
  select(or(select(starts_with("GET"), starts_with("POST"))));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use it in your queries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'include "custom" | .code | extract_endpoints() | format_api_endpoint("GET", self, "API endpoint")'&lt;/span&gt; api-docs.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Performance Optimization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Parallel Processing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Process large numbers of files in parallel&lt;/span&gt;
mq &lt;span class="nt"&gt;-P&lt;/span&gt; 5 &lt;span class="s1"&gt;'.h1 | to_text()'&lt;/span&gt; docs/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Streaming Processing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Process large files without loading everything into memory&lt;/span&gt;
mq &lt;span class="nt"&gt;--unbuffered&lt;/span&gt; &lt;span class="s1"&gt;'.code | to_text()'&lt;/span&gt; large-documentation.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Integration Patterns
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CI/CD Integration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# GitHub Actions example&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Extract API Changes&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;mq 'select(and(.h2, contains("API"))) | to_text()' CHANGELOG.md &amp;gt; api-changes.txt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Build Tool Integration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract version from changelog&lt;/span&gt;
&lt;span class="nv"&gt;VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;mq &lt;span class="s1"&gt;'select(.h2) | to_text() | match("v?([0-9.]+)")'&lt;/span&gt; CHANGELOG.md&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Building version: &lt;/span&gt;&lt;span class="nv"&gt;$VERSION&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Documentation Maintenance
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Find outdated documentation sections&lt;/span&gt;
mq &lt;span class="s1"&gt;'select(or(contains("TODO"), contains("FIXME")))
    | s"File: ${__FILE__}\nIssue: ${to_text(self)}"'&lt;/span&gt; docs/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Content Audit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Check for broken internal links&lt;/span&gt;
mq &lt;span class="s1"&gt;'.link | select(starts_with("#")) |
    let target = slice(1) |
    s"Link target: ${target}"'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; excels at complex Markdown processing tasks that would be difficult or impossible with traditional text processing tools. By mastering these advanced techniques, you can build sophisticated documentation workflows, automate content processing, and integrate Markdown manipulation into your development pipeline.&lt;/p&gt;

&lt;p&gt;The combination of structural understanding, powerful filtering, and transformation capabilities makes &lt;code&gt;mq&lt;/code&gt; an useful tool for any developer working with Markdown at scale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;mq Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq/tree/main/examples" rel="noopener noreferrer"&gt;Advanced Examples Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;mq Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=harehare.vscode-mq" rel="noopener noreferrer"&gt;VSCode Extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>cli</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>mq: The Missing Link Between jq and Markdown</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sun, 29 Jun 2025 13:47:38 +0000</pubDate>
      <link>https://forem.com/harehare/mq-the-missing-link-between-jq-and-markdown-bge</link>
      <guid>https://forem.com/harehare/mq-the-missing-link-between-jq-and-markdown-bge</guid>
      <description>&lt;p&gt;&lt;em&gt;Transform Markdown with the power of jq-like queries&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Have you ever found yourself needing to extract specific content from Markdown files, manipulate documentation structures, or process content for LLM workflows? If you're familiar with &lt;code&gt;jq&lt;/code&gt; for JSON processing, you'll love &lt;code&gt;mq&lt;/code&gt; - a powerful command-line tool that brings the same level of querying sophistication to Markdown documents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38b935vrivitoewkyjq3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38b935vrivitoewkyjq3.gif" alt="Demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is mq?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; is a Rust-based command-line tool that processes Markdown using a syntax similar to &lt;code&gt;jq&lt;/code&gt;. It allows you to slice, filter, map, and transform Markdown content with ease, making it an essential tool for developers working with documentation, content management, and modern AI workflows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why mq Matters
&lt;/h2&gt;

&lt;p&gt;In today's development landscape, Markdown is everywhere:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Documentation&lt;/strong&gt;: README files, API docs, technical specifications&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LLM Workflows&lt;/strong&gt;: Processing prompts and outputs for AI applications&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Management&lt;/strong&gt;: Blog posts, articles, and knowledge bases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static Site Generation&lt;/strong&gt;: Processing content for Jekyll, Hugo, and similar tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traditional text processing tools like &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;sed&lt;/code&gt;, and &lt;code&gt;awk&lt;/code&gt; work at the text level, but Markdown has structure that these tools can't understand. &lt;code&gt;mq&lt;/code&gt; understands Markdown's semantic structure, allowing you to work with headers, code blocks, lists, and tables as first-class objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;The easiest way to install &lt;code&gt;mq&lt;/code&gt; is through Cargo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/harehare/mq.git mq-cli &lt;span class="nt"&gt;--tag&lt;/span&gt; v0.2.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For other installation methods, including Homebrew, Docker, and pre-built binaries, check the &lt;a href="https://mqlang.org/book/start/install.html" rel="noopener noreferrer"&gt;official installation guide&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your First Query
&lt;/h3&gt;

&lt;p&gt;Let's start with a simple example. Create a file called &lt;code&gt;example.md&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;
&lt;span class="gh"&gt;# My Project&lt;/span&gt;

This is a sample project with multiple sections.

&lt;span class="gu"&gt;## Features&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; Fast processing
&lt;span class="p"&gt;-&lt;/span&gt; Easy to use
&lt;span class="p"&gt;-&lt;/span&gt; Extensible

&lt;span class="gu"&gt;## Code Examples&lt;/span&gt;

&lt;span class="sb"&gt;``javascript
console.log("Hello, World!");
``&lt;/span&gt;

&lt;span class="sb"&gt;``python
print("Hello, World!")
``&lt;/span&gt;

&lt;span class="gu"&gt;## Installation&lt;/span&gt;

Run the following command:jj

&lt;span class="sb"&gt;``bash
npm install my-project
``&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's extract all the code blocks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'.code'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output all code blocks from the file. The &lt;code&gt;.code&lt;/code&gt; selector specifically targets code block elements in the Markdown structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Selectors
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; provides several built-in selectors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.code&lt;/code&gt; - Select all code blocks&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.h1&lt;/code&gt;, &lt;code&gt;.h2&lt;/code&gt;, &lt;code&gt;.h3&lt;/code&gt;, etc. - Select headers by level&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.[]&lt;/code&gt; - Select list items&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.[][]&lt;/code&gt; - Select table cells&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's try a few more examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract all headers&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h'&lt;/span&gt; example.md

&lt;span class="c"&gt;# Extract only level 2 headers&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h2'&lt;/span&gt; example.md

&lt;span class="c"&gt;# Extract all list items&lt;/span&gt;
mq &lt;span class="s1"&gt;'.[]'&lt;/span&gt; example.md

&lt;span class="c"&gt;# Extract JavaScript code blocks only&lt;/span&gt;
mq &lt;span class="s1"&gt;'.code("javascript")'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Filtering and Transforming
&lt;/h2&gt;

&lt;p&gt;One of &lt;code&gt;mq&lt;/code&gt;'s strengths is its ability to filter and transform content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Find headers containing "install"&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h | select(contains("install"))'&lt;/span&gt; example.md

&lt;span class="c"&gt;# Convert all headers to text&lt;/span&gt;
mq &lt;span class="s1"&gt;'.h | to_text()'&lt;/span&gt; example.md

&lt;span class="c"&gt;# Extract code blocks and convert to text&lt;/span&gt;
mq &lt;span class="s1"&gt;'.code | to_text()'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Practical Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Generate Table of Contents
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'select(or(.h1, .h2, .h3)) | let link = to_link(add("#", to_text(self)), to_text(self), "") | if (is_h1()): to_md_list(link, 1) elif (is_h2()): to_md_list(link, 2) elif (is_h3()): to_md_list(link, 3) else: None'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Extract All Code Examples
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'.code | to_text()'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Find Specific Content
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Find all sections mentioning "installation"&lt;/span&gt;
mq &lt;span class="s1"&gt;'select(contains("installation"))'&lt;/span&gt; example.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Interactive Development
&lt;/h2&gt;

&lt;p&gt;For experimentation and learning, &lt;code&gt;mq&lt;/code&gt; provides a REPL (Read-Eval-Print Loop):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq repl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows you to interactively test queries and explore your Markdown structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  IDE Support
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; comes with excellent tooling support:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VSCode Extension&lt;/strong&gt;: Available on the Visual Studio Marketplace&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Language Server Protocol (LSP)&lt;/strong&gt;: For custom function development&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Syntax Highlighting&lt;/strong&gt;: For &lt;code&gt;.mq&lt;/code&gt; files&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;This introduction covers the basics of &lt;code&gt;mq&lt;/code&gt;, but there's much more to explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced selectors and filtering&lt;/li&gt;
&lt;li&gt;Custom functions and modules&lt;/li&gt;
&lt;li&gt;Batch processing multiple files&lt;/li&gt;
&lt;li&gt;Integration with CI/CD pipelines&lt;/li&gt;
&lt;li&gt;Web API and Python bindings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;mq&lt;/code&gt; transforms how you work with Markdown, making complex document processing tasks simple and intuitive. Whether you're managing documentation, processing content for AI workflows, or building content pipelines, &lt;code&gt;mq&lt;/code&gt; provides the tools you need.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Interactive Playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=harehare.vscode-mq" rel="noopener noreferrer"&gt;VSCode Extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start exploring &lt;code&gt;mq&lt;/code&gt; today and discover how it can streamline your Markdown workflows!&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>cli</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Extract AI Rules from Markdown Files with mq</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Thu, 26 Jun 2025 15:16:23 +0000</pubDate>
      <link>https://forem.com/harehare/extract-ai-rules-from-markdown-files-with-mq-25b8</link>
      <guid>https://forem.com/harehare/extract-ai-rules-from-markdown-files-with-mq-25b8</guid>
      <description>&lt;p&gt;Managing separate AI rule files for different systems? &lt;code&gt;mq&lt;/code&gt; can generate them from one master file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgai9db4xxeykd66od77q.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgai9db4xxeykd66od77q.gif" alt="demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Each AI system needs its own rule file. Managing multiple separate Markdown files gets messy quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Solution
&lt;/h2&gt;

&lt;p&gt;Keep all AI rules in one master file, then generate individual files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;mq &lt;span class="s1"&gt;'nodes | sections(2) | filter(fn(section): let head = first(section) | contains(head, "Claude Rules");) | first() | map(decrease_header_level) | to_markdown_string()'&lt;/span&gt; master-ai-rules.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; claude-rules.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generate Multiple AI Rule Files
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Extract different AI system rules from one master file&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;mq &lt;span class="s1"&gt;'nodes | sections(2) | filter(fn(s): contains(first(s), "GPT Rules")) | first() | map(decrease_header_level) | to_markdown_string()'&lt;/span&gt; master-ai-rules.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; gpt-rules.md
&lt;span class="nv"&gt;$ &lt;/span&gt;mq &lt;span class="s1"&gt;'nodes | sections(2) | filter(fn(s): contains(first(s), "Gemini Rules")) | first() | map(decrease_header_level) | to_markdown_string()'&lt;/span&gt; master-ai-rules.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; gemini-rules.md
&lt;span class="nv"&gt;$ &lt;/span&gt;mq &lt;span class="s1"&gt;'nodes | sections(2) | filter(fn(s): contains(first(s), "Claude Rules")) | first() | map(decrease_header_level) | to_markdown_string()'&lt;/span&gt; master-ai-rules.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; claude-rules.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why This Approach Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Single source of truth&lt;/strong&gt;: All AI rules in one master file&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy maintenance&lt;/strong&gt;: Update rules in one place&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic generation&lt;/strong&gt;: Create individual files with one script&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version control friendly&lt;/strong&gt;: Track changes in one file&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No vendor lock-in&lt;/strong&gt;: Generated files are plain Markdown, work anywhere&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;harehare/tap/mq
&lt;span class="nv"&gt;$ &lt;/span&gt;mq &lt;span class="s1"&gt;'nodes | sections(2) | filter(fn(s): contains(first(s), "Claude Rules")) | first() | map(decrease_header_level) | to_markdown_string()'&lt;/span&gt; master-ai-rules.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; claude-rules.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can manage all AI rules in one file and generate individual rule files as needed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Online playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/markdown-query/" rel="noopener noreferrer"&gt;Pypi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>cli</category>
      <category>ai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Optimize NotebookLM Input with mq: Efficient Markdown File Merging</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Thu, 19 Jun 2025 14:54:54 +0000</pubDate>
      <link>https://forem.com/harehare/optimize-notebooklm-input-with-mq-efficient-markdown-file-merging-lmg</link>
      <guid>https://forem.com/harehare/optimize-notebooklm-input-with-mq-efficient-markdown-file-merging-lmg</guid>
      <description>&lt;p&gt;Uploading multiple Markdown files to NotebookLM one by one is tedious. &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;&lt;code&gt;mq&lt;/code&gt;&lt;/a&gt; solves this by merging and filtering files into a single, optimized input for better AI analysis.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxadf1fx3fjonhn6z04v.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnxadf1fx3fjonhn6z04v.gif" alt="demo" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic File Merging
&lt;/h2&gt;

&lt;p&gt;Merge all content from multiple files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="nt"&gt;--separator&lt;/span&gt; &lt;span class="s1"&gt;'s"\nFILE: ${__FILE__}\n"'&lt;/span&gt; &lt;span class="s1"&gt;'identity()'&lt;/span&gt; notes/&lt;span class="k"&gt;*&lt;/span&gt;.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; merged.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Extract Key Information
&lt;/h2&gt;

&lt;p&gt;Keep only headers and links for focused analysis:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="nt"&gt;--separator&lt;/span&gt; &lt;span class="s1"&gt;'s"\nFILE: ${__FILE__}\n"'&lt;/span&gt; &lt;span class="s1"&gt;'select(or(.h, .link))'&lt;/span&gt; notes/&lt;span class="k"&gt;*&lt;/span&gt;.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; merged.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Include code blocks too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="nt"&gt;--separator&lt;/span&gt; &lt;span class="s1"&gt;'s"\nFILE: ${__FILE__}\n"'&lt;/span&gt; &lt;span class="s1"&gt;'select(or(.h, .link, .code))'&lt;/span&gt; notes/&lt;span class="k"&gt;*&lt;/span&gt;.md &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; merged.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Use Cases
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Documentation: Combine README, API docs, and guides&lt;/li&gt;
&lt;li&gt;Research: Merge papers, notes, and references&lt;/li&gt;
&lt;li&gt;Projects: Consolidate specs, meeting notes, and plans&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Upload the generated &lt;code&gt;merged.md&lt;/code&gt; to NotebookLM for streamlined AI-powered analysis and Q&amp;amp;A.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Online playground&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/markdown-query/" rel="noopener noreferrer"&gt;Pypi&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>markdown</category>
      <category>llm</category>
      <category>cli</category>
      <category>programming</category>
    </item>
    <item>
      <title>Extracting Markdown Headers and Links for LLMs with mq</title>
      <dc:creator>Takahiro Sato</dc:creator>
      <pubDate>Sat, 07 Jun 2025 14:51:13 +0000</pubDate>
      <link>https://forem.com/harehare/extracting-markdown-headers-and-links-for-llms-with-mq-22cf</link>
      <guid>https://forem.com/harehare/extracting-markdown-headers-and-links-for-llms-with-mq-22cf</guid>
      <description>&lt;p&gt;There may be times when you want to extract just the headers or links from Markdown files, rather than working with the entire document.&lt;br&gt;
You can also use Large Language Models (LLMs) with only the extracted headers or links, instead of always providing the full document.&lt;/p&gt;

&lt;p&gt;Here's how you could try this with &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;mq&lt;/a&gt;, a jq-like CLI tool for Markdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcz7vy467cchuasxhicp0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcz7vy467cchuasxhicp0.gif" alt="mq command" width="1200" height="600"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Command
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The following command assumes you are running it in &lt;code&gt;zsh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'.h | let h = to_text() | s"- [${h}](${__FILE__})"'&lt;/span&gt; &lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.h&lt;/code&gt; selects all headers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let h = to_text()&lt;/code&gt; gets header text&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;s"- [${h}](${__FILE__})"&lt;/code&gt; outputs a Markdown link with the file path&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Suppose you have:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;docs/intro.md&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Introduction&lt;/span&gt;
&lt;span class="gu"&gt;## Getting Started&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;docs/usage.md&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Usage&lt;/span&gt;
&lt;span class="gu"&gt;## Advanced&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'.h | s"- [${self}](${__FILE__})"'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- [# Introduction](docs/intro.md)
- [## Getting Started](docs/intro.md)
- [## Example Code Block](docs/intro.md)
- [# Usage](docs/usage.md)
- [## Advanced](docs/usage.md)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mq &lt;span class="s1"&gt;'.h | let h = to_text() | s"- [${h}](${__FILE__})"'&lt;/span&gt; docs/&lt;span class="k"&gt;*&lt;/span&gt;.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- [Introduction](docs/intro.md)
- [Getting Started](docs/intro.md)
- [Example Code Block](docs/intro.md)
- [Usage](docs/usage.md)
- [Advanced](docs/usage.md)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could use this list as a table of contents, or provide it to an LLM as a hint for summarization or exploration, instead of providing the full document.&lt;br&gt;
This approach might be useful in some scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--git&lt;/span&gt; https://github.com/harehare/mq.git mq-cli
&lt;span class="c"&gt;# or&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;harehare/tap/mq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/book/" rel="noopener noreferrer"&gt;Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mqlang.org/playground" rel="noopener noreferrer"&gt;Playground&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🐛 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Report bugs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💡 &lt;a href="https://github.com/harehare/mq/issues" rel="noopener noreferrer"&gt;Request features&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;⭐ &lt;a href="https://github.com/harehare/mq" rel="noopener noreferrer"&gt;Star the project&lt;/a&gt; if you find it useful!&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;mq makes it easy to extract and format Markdown structure—such as headers and links—which may be helpful in some cases as an alternative to inputting the entire document.&lt;/p&gt;

</description>
      <category>cli</category>
      <category>markdown</category>
      <category>programming</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
