TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Jq-Like Tool for Markdown

325 pointsby yshavit3 months ago
There have been a few times I wanted the ability to select some text out of a Markdown doc. For example, a GitHub CI check to ensure that PRs &#x2F; issues &#x2F; etc are properly formatted.<p>This can be done to some extent with regex, but those expressions are brittle and hard to read or edit later. mdq uses a familiar pipe syntax to navigate the Markdown in a structured way.<p>It&#x27;s in 0.x because I don&#x27;t want to fully commit to the syntax being stable, in case real-world testing shows that the syntax needs tweaking. But I think the project is in a pretty good spot overall, and would be interested in feedback!

19 comments

verdverm3 months ago
&gt; GitHub PRs are Markdown documents, and some organizations have specific templates with checklists for all reviewers to complete. Enforcing these often requires ugly regexes that are a pain to write and worse to debug<p>This is because GitHub is not building the features we need, instead they are putting their energy towards the AI land grab. Bitbucket, by contrast, has a feature where you can block PRs using a checkbox list outside of the description box. There are better ways to solve this first example from OP readme. Cool project, I write mainly MDX these days, would be cool to see support for that dialect
评论 #43154358 未加载
评论 #43153710 未加载
评论 #43154450 未加载
评论 #43154151 未加载
评论 #43154025 未加载
评论 #43156630 未加载
评论 #43163396 未加载
lanstin3 months ago
Ironically one of the reasons markdown (and other text based file formats) were popular because you could use regular find&#x2F;grep to analyze it, and version control to manage it.
评论 #43153447 未加载
评论 #43153358 未加载
评论 #43153313 未加载
unglaublich3 months ago
My flow is to go through the Pandoc JSON AST and then use Jq. This works for other input formats, too.
评论 #43153442 未加载
评论 #43153777 未加载
dleeftink3 months ago
Kind of aligned with this is MarkdownDB, providing an SQLite backend to your Markdown files [0]. Cool to see this, I feel the structure of .md files is not always equally respected or regarded as a data serialisation target.<p>[0]: <a href="https:&#x2F;&#x2F;markdowndb.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;markdowndb.com&#x2F;</a>
broodbucket3 months ago
I think you&#x27;d benefit of having some more real-world-ish examples in the README, as someone who doesn&#x27;t intuit what I&#x27;d want to use this for.
评论 #43155309 未加载
评论 #43154465 未加载
pokstad3 months ago
Please don’t reimplement JQ. That problem is already solved. Instead, just provide a tool that can convert your target syntax into JSON, then it can be piped to JQ for querying.
kbd3 months ago
Cool thanks for sharing! I&#x27;ll have to check this out. I&#x27;ve wanted something similar.<p>After trying a bunch of the usual ones, the only &quot;notes system&quot; I&#x27;ve stuck with is just a directory of markdown files that&#x27;s automatically committed to git on any change using watchexec.<p>I&#x27;ve wanted to add a little smarts to it so I could use it to track tasks (eg. sort, prune completed, forward uncomplete tasks over to the next day&#x27;s journal, collect tasks from &quot;projects&quot;, etc.) so I started writing some Rust code using markdown-rs. Then, to round-trip markdown with changes, only the javascript version of the library currently supports serializing github flavored markdown. So then I actually dumped the markdown ast to json from rust and picked it up in js to serialize it for a proof of concept. That&#x27;s about as far as I got so far. But while markdown-rs saves position information, it doesn&#x27;t save source token information (like, * and - are both list items) so you can&#x27;t reliably round-trip.<p>FWIW, the other thing I was hoping to do was treat markdown documents as trees (based on headings) use an xpath kind of language to pull out sections. Anyway, will check out your code, thanks for posting.
threecheese3 months ago
Interesting; one thing you may have learned researching existing tools and libraries: many of them serialize markdown to html before running structured extraction&#x2F;manipulation - even stuff like converting to pdf.<p>The core assumption here is that Markdown was&#x2F;is designed to be serializeable to html - this is why a markdown document&#x2F;AST is mostly <i>not</i> a tree structure, for tree-ish elements such as sub-sections. Instead, it is flat, an array of elements in order of appearance in the document. Apparently this most closely matches the structure of html, at both the block and inline levels. Only Lists and Blockquotes (afair) support nesting.<p>Ex: h1 -&gt; paragraph -&gt; h2 -&gt; paragraph is not nested, it is an array of four ordered elements.<p>Anyway, you might throw a task at Cursor or Copilot to see how an equivalent implementation using html fares against your test suite, you may be able to develop more quickly.
aqueueaqueue3 months ago
Why not MD -&gt; json, then use jq! That would be half a static site generator there!
spiffyk3 months ago
Thanks for sharing! No immediate use-case <i>for me</i> right now, but good to know something like this exists.<p>I wanted to point out little nitpicks for the documented shell invocations:<p><pre><code> cat example.md | mdq &#x27;# usage&#x27; </code></pre> This can be changed into a stdin file redirect to avoid invoking an extra `cat` process (see Useless use of cat [1]):<p><pre><code> mdq &#x27;# usage&#x27; &lt; example.md </code></pre> In a similar fashion, you can avoid an extra `echo` process here:<p><pre><code> echo &quot;$ISSUE_TEXT&quot; | mdq -q &#x27;- [x] I have searched for existing issues&#x27; </code></pre> by changing to this:<p><pre><code> mdq -q &#x27;- [x] I have searched for existing issues&#x27; &lt;&lt;&lt; &quot;$ISSUE_TEXT&quot; </code></pre> [1]: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cat_(Unix)#Useless_use_of_cat" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cat_(Unix)#Useless_use_of_cat</a>
评论 #43158018 未加载
twinkjock3 months ago
Thanks for sharing this Yuval! Thanks as well for using permissive licenses so I can use this at work.
评论 #43153427 未加载
frankfrank133 months ago
I worked on a project converting word docs to markdown so they could more easily be ingested into an LLM, one issue was that context windows used to be very short, so we would basically split on `\n#` to get sections, but this turns into a whole thing where you have to make guesses about which header level is appropriate to split at, and then you turn each section into a separate chunk in FAISS. Anyways we ended up using HTML instead of MD but theres so much tooling for traversing HTML and not MD. This would have been helpful for that
foo423 months ago
This is one of those moments where you come across a tool _just_ at the right moment. I have a task for which this will be perfect
infogulch3 months ago
I&#x27;ve always wanted a &quot;literate programming&quot; &#x2F; jupyter-style notebook based on markdown. Maybe this could help make something like that possible.
评论 #43162930 未加载
zerkten3 months ago
Thanks! I have to grapple with some markdown across multiple repos and this&#x27;ll be a helpful tool in the toolchest.
linklater123 months ago
congrats on your tool, will check it out. I have a side question on markdown: cursor messes up markdown generation quite often for me. I think its responses are always in markdown with sections for code and asking it to generate markdown breaks it. So the question: any ideas on how to have cursor generate markdown?
nodesocket3 months ago
How is it parsing? Just normal string and regex matching or transforming markdown to an intermediate structured language?
评论 #43153615 未加载
dcreater3 months ago
What purpose does this serve that grep doesn&#x27;t?
moonshotideas3 months ago
Love this! One persons opinion - I’d change it to mq - less chars are always better for command