Markdown tags and folders: #tags, YAML and plain files

Managing notes5 min read

To keep plain Markdown notes readable ten years from now, use folders for where a note lives and #tags or YAML tags for topics that cut across folders. A folder is a real directory that Finder, the iOS Files app, git, and terminal tools already understand, while tags sit inside the .md file itself so search tools can filter across directories without locking your writing into a database. Trouble starts when you ask one mechanism to do both jobs: fifty nested folders make filing slow, while tag-only systems collapse into a flat pile the day you export.

Folders, tag trees, and vault indexes compared

Every Markdown app chooses a primary spine for your library, and that choice dictates what survives when you switch editors.

Pure folder hierarchies map directly onto your disk, as covered in Local-first Markdown notes. Subfolders in your library directory appear as sidebar folders, and each .md file lives in one place. Reveal a note in Finder (⌥⌘R in MiaoYan), open a terminal (⌘J), or browse iCloud Drive on an iPhone, and the exact same hierarchy appears. The physical limit is that one file cannot sit inside both Projects/ and Reading/ without copies or symlinks.

Tag-only apps such as Bear remove folders altogether. As described in A Bear alternative for Mac, Bear keeps notes in a SQLite database and builds its sidebar from #tag and #parent/child tokens inside note text. Placing one note under three tags feels effortless until you export to Markdown and end up with hundreds of ungrouped .md files in a single folder.

Vault-index apps like Obsidian store plain files in folders while maintaining an auxiliary cache inside .obsidian for a tag pane. MiaoYan keeps the sidebar strictly tied to real disk folders while indexing inline #tags, YAML frontmatter tags, and open - [ ] tasks in memory for instant search across Mac, iPhone, and iPad. For direct links between two specific notes, [[Note Title]] connects them cleanly, covered in Wikilinks and backlinks.

Inline #tags vs YAML frontmatter tags:

CommonMark and GitHub Flavored Markdown define no native tag syntax, so plain-text tools have converged on two portable conventions:

---
title: Q4 architecture review
date: 2026-11-22
tags: [architecture, q4-review]
---

Checked replication lag with the storage team. #database/postgres #followup

- [ ] Benchmark read replicas before Friday

Inline #tags and #parent/child paths sit right inside prose or under a heading. Letters (including CJK and accented characters), digits, underscores, hyphens, and slashes for sub-tags all work, such as #work, #q4-review, or #database/postgres. Bear's #two words# closing-hash syntax is Bear-specific; join multi-word tags with hyphens (#two-words) or slashes so ripgrep and other Markdown tools read the full token.

YAML frontmatter tags: sits at line 1 between --- fences as either tags: [work, reading] or - work list items. Frontmatter fits drafts destined for Hugo, Astro, or Jekyll, or clean PDF exports without visible #hashtags in paragraphs. As detailed in Markdown front matter, MiaoYan hides valid YAML frontmatter in preview and export while indexing both tags: and tag:.

Avoiding # collisions: how MiaoYan parses tags

A naive regex searching Markdown for # drowns in false positives from headings, issue numbers, URL anchors, and CSS colors. MiaoYan's shared parser (NoteMetadataIndex in MiaoYanCore) filters each line before recording a tag:

# Heading with a space       -> ATX heading, ignored
Issue #123 and PR #42        -> Pure digits, ignored
Brand green is #1C5D33       -> 3/6/8-char hex color, ignored
See [docs](api.md#auth)      -> Link or URL anchor, ignored
Code `#fake` or ``` fence    -> Code span or fence, ignored
Notes on #facade or #work/q4 -> Indexed as #facade and #work/q4

Four rules handle the tricky cases:

  1. Headings vs tags. CommonMark ATX headings require a space or tab after # (# Heading). Inline #tags start immediately after # following start-of-line, whitespace, or standard ASCII and full-width CJK punctuation (,。;:!?「」【】). Always keep the space in # Heading.
  2. Code and links are masked. Fenced code blocks (``` and ~~~), inline code spans, Markdown link targets ([text](page.md#anchor)), and bare https:// URLs are masked out first, so # shell comments inside code blocks never become tags.
  3. Pure numbers and CSS hex colors are skipped. Tokens of digits alone (#123) are ignored as issue numbers. Three-, six-, and eight-character ASCII hex strings (#fff, #1C5D33, #aabbccdd) are rejected as CSS colors, while real English words made of letters a through f (#dad, #ace, #decade, #facade) stay allowlisted as valid tags.
  4. Hierarchical prefix matching. Searching #database matches both #database and child tags like #database/postgres, case-insensitively.

Filtering with #tag and todo: in MiaoYan and CLI

Shallow folders work best when cross-folder filtering is instant. Press ⌘/ on Mac (or tap the search bar on iPhone and iPad):

  • Quick filter chips. Focusing search scans notes off the main thread and shows clickable chips for Todo (when open - [ ] tasks exist) plus your top frequent #tags (up to eight on Mac, ten on iPhone and iPad).
  • Combined queries. Type #reading to match inline or YAML tags, todo: to require an unchecked - [ ] task outside code fences, or #work todo: invoice to require both and jump straight to the matching task line on open.
  • Terminal search. Because tags and tasks remain plain UTF-8 text, rg '(^|\s)#work(/|\b)' ~/MiaoYan and rg '^\s*[-*+] \[ \]' ~/MiaoYan work anytime without an app export.

A layout that stays tidy, and what to check when a tag misses

Keep five to seven folders by purpose (Inbox/, Projects/, Areas/, Reference/, Archive/, created with ⇧⌘N on Mac) and reserve #tags for attributes that cross folders (#tax, #q4-review, #draft) rather than repeating folder names.

If a tag fails to appear in search, check for spaces inside the tag (#my tag indexes only #my), check that it is outside unclosed code fences or backticks, and avoid six-character hex-only coinages like #cafe01 (write #cafe-01). If YAML tags: shows as raw text in preview, ensure --- starts on line 1 with valid key: value lines and a clean --- closer. MiaoYan is on the App Store for Mac, iPhone, and iPad, with MiaoYanCore open source on GitHub.

FAQ

Should I put tags inline or in YAML frontmatter?

Use inline #tags for fast daily notes where visible context helps, and YAML tags: [...] for static site drafts or clean PDFs without #hashtags in prose. MiaoYan indexes both the same way.

Does moving a note to another folder break its #tags?

No. Tags travel inside the .md file text rather than an external database, so moving files in Finder or MiaoYan keeps every tag intact.

Why keep folders at all if #parent/child tags can nest?

Folders organize local i/ attachment directories, git repos, Finder windows, and selective backups. Without folders, hundreds of .md files and images pile into one directory on disk.

Can I search for open tasks inside one tag?

Yes. Enter #project todo: (plus optional keywords like #project todo: deploy) in MiaoYan's search bar on Mac, iPhone, or iPad to match notes tagged #project that still contain an unchecked - [ ] item.