hypermarkdown 0.4.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/CHANGELOG.md +157 -1
  2. {hypermarkdown-0.4.0/src/hypermarkdown.egg-info → hypermarkdown-0.5.0}/PKG-INFO +4 -3
  3. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/README.md +3 -2
  4. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/pyproject.toml +5 -0
  5. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/__init__.py +1 -1
  6. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/cli.py +22 -9
  7. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/config.py +83 -44
  8. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/embed.py +70 -28
  9. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/frontmatter.py +79 -34
  10. hypermarkdown-0.5.0/src/hypermarkdown/frontmatter_position.py +231 -0
  11. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/graph.py +1 -1
  12. hypermarkdown-0.5.0/src/hypermarkdown/highlight.py +171 -0
  13. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/imports.py +11 -5
  14. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/lint/rules.py +106 -41
  15. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/mkdocs_plugin.py +61 -8
  16. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/model.py +48 -4
  17. hypermarkdown-0.5.0/src/hypermarkdown/parse.py +317 -0
  18. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/render/flat.py +11 -5
  19. hypermarkdown-0.5.0/src/hypermarkdown/render/ids.py +116 -0
  20. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/resolve.py +259 -59
  21. hypermarkdown-0.5.0/src/hypermarkdown/scan.py +334 -0
  22. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0/src/hypermarkdown.egg-info}/PKG-INFO +4 -3
  23. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown.egg-info/SOURCES.txt +4 -1
  24. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown.egg-info/entry_points.txt +3 -0
  25. hypermarkdown-0.4.0/src/hypermarkdown/parse.py +0 -211
  26. hypermarkdown-0.4.0/src/hypermarkdown/scan.py +0 -153
  27. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/LICENSE +0 -0
  28. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/MANIFEST.in +0 -0
  29. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/setup.cfg +0 -0
  30. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/diagram.py +0 -0
  31. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/lint/__init__.py +0 -0
  32. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/lint/report.py +0 -0
  33. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/render/__init__.py +0 -0
  34. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown/urls.py +0 -0
  35. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown.egg-info/dependency_links.txt +0 -0
  36. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown.egg-info/requires.txt +0 -0
  37. {hypermarkdown-0.4.0 → hypermarkdown-0.5.0}/src/hypermarkdown.egg-info/top_level.txt +0 -0
@@ -13,6 +13,151 @@ only for the Python API.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.5.0] — 2026-11-25
17
+
18
+ ### Added
19
+ - **A Pygments lexer for HyperMarkDown**, registered as `hmd` (alias
20
+ `hypermarkdown`, files `*.hmd`). A code sample fenced as ```` ```hmd ```` is
21
+ coloured as a card in MkDocs, in `hmd render --to html`, and anywhere else
22
+ Pygments is used: wikilinks, embeds, block anchors, and frontmatter are
23
+ distinct tokens, and a fenced block inside the sample is coloured as its own
24
+ language. Nothing has to be configured; Pygments finds the lexer through an
25
+ entry point.
26
+ - **An anchored repeat heading is not HMD011.** A heading whose key equals an
27
+ earlier one's is reported only when it carries no block anchor: the anchor
28
+ is the remedy, and makes the heading reachable.
29
+ - **An anchor on a heading embeds its section.** `![[card#^setup-linux]]`,
30
+ where `^setup-linux` ends a heading's line, expands that heading's whole
31
+ section, exactly as `![[card#Linux]]` does, instead of the heading line alone.
32
+ - **Setext headings are headings.** `Setup` over a line of `===` or `---` is
33
+ indexed and addressable like `# Setup`, at level 1 or 2, and ends an embedded
34
+ section the way an ATX heading does. A `---` after a blank line is still a
35
+ thematic break, a `---` frontmatter fence is still frontmatter, and no line
36
+ inside a fence or a comment is ever a heading.
37
+ - **HMD019**, an error: a file with a card extension that is not valid UTF-8,
38
+ reported at line 1, column 1. The file is then not a card — not scanned, not
39
+ a link target, not in the graph — where it used to stop the run with a
40
+ `UnicodeDecodeError`. `hmd lint` accepts such a file by path.
41
+
42
+ ### Changed
43
+ - **A reference that ends in `/` names a directory**, and resolves only to
44
+ its folder note, in every phase: `[[m/]]` reaches `m/index.hmd` even
45
+ where `m.hmd` claims the name, it never matches a named import, and the
46
+ recursive search considers only folder notes. `[[/]]` is the root's folder
47
+ note. A trailing `/` used to be dropped, so `[[m/]]` reached `m.hmd`.
48
+ - **A `location_path` that resolves into a nested vault is refused.** If a
49
+ directory between the vault and the namespace root carries its own `.hmd/`,
50
+ the vault is not loaded, and the error names `location_path` and the nested
51
+ vault.
52
+ - **Frontmatter diagnostics are reported where the problem is written**, no
53
+ longer all at line 1, column 1. A malformed value of a top-level key is at
54
+ the key; a problem inside `nav` at the key inside it; a malformed list entry,
55
+ such as a tag, a `use` entry, or an `import` statement, at the entry's first
56
+ character (after `- ` in a block list, its own first character in a flow
57
+ list); anything else at its nearest enclosing key. HMD015 and HMD003 about an
58
+ import are at its statement. Invalid YAML stays at the block's start.
59
+ - **A block anchor's position starts at its `^`**, not at the spaces or
60
+ tabs before it, so HMD006 points at the `^`. The blanks before the anchor
61
+ still go with it when a block is embedded or rendered.
62
+ - **Breaking: `wiki` is renamed `location_path`, and its default is `.`**, the
63
+ vault itself, where it was `doc/wiki`. A `.hmd/config.toml` that still sets
64
+ `wiki` is refused: the vault is not loaded, every command exits 2, and the
65
+ error names `wiki` and `location_path`. The MkDocs plugin stops the build
66
+ with the same message. `hmd init` takes `--location-path` in place of
67
+ `--wiki`, writes `location_path`, and with no flag makes no directory of its
68
+ own, since `.` is the project root; it prints the root on a `location:`
69
+ line. In the Python API, `config.init` takes `location_path=`,
70
+ `InitResult.wiki` is `InitResult.location`, and `DEFAULT_WIKI` is
71
+ `DEFAULT_LOCATION_PATH`.
72
+ - **A backslash anywhere in a wikilink is HMD010**: in its path, its
73
+ fragment, or its display. A backslash is never a path separator and
74
+ escapes nothing; one before `[[` is outside the link and changes nothing.
75
+ - **An `import` statement takes only spaces and tabs as whitespace**, between
76
+ its words and on either side of a comma, as the grammar's `WS` says; another
77
+ whitespace character there is HMD014. An imported name or alias is a
78
+ segment with no whitespace, so `:` and the reserved characters make it
79
+ HMD014 too.
80
+ - **A local name bound twice by imports is HMD015 even when both bindings
81
+ reach one card**, as in `from /shared import tokens` beside
82
+ `from ./shared import tokens`. It used to be reported only when the two
83
+ cards differed. The first binding stands.
84
+ - **Resolution follows the HyperMarkDown 0.1 algorithm**, checked by the
85
+ corpus's `resolve-*` cases, which are written from the specification rather
86
+ than generated. `.` and `..` belong to relative references alone, and are
87
+ normalised there: in an absolute or unqualified reference, such as
88
+ `[[/a/../b]]` or `[[a/../b]]`, either one is HMD010 and the reference is not
89
+ a link. A relative reference whose last component is `.` or `..` names that
90
+ directory, and reaches only its folder note. A path that leaves the namespace is HMD003 in every phase: one
91
+ that climbs above the root, enters a nested vault, or meets a symbolic link
92
+ out of the root; a path into a nested vault used to be HMD001. `[[./]]` and
93
+ `[[../]]` bind only the directory's folder note, the root's included. A
94
+ reference that writes an extension reaches a shadowed card in the
95
+ recursive search too, and a named import whose card has another extension
96
+ does not apply to it. In the recursive search a folder note matched by its
97
+ directory's name gives way to a card beside the directory. Every imported
98
+ search path is probed, and HMD016 names each other card once; one card
99
+ reached through two imports is not reported.
100
+ - **A symbolic link out of the namespace root is not a card.** Nothing
101
+ through one is loaded, where a linked file used to be read as a card
102
+ wherever it pointed.
103
+ - **An unclosed `[[` is text, not HMD010.** A `[[` with no `]]` after it on
104
+ its line, or with a `[` or `]` first, begins no link and is ordinary
105
+ Markdown, so a matrix in maths such as `$[[1,2],[3,4]]$` no longer reports an
106
+ error. A link that is closed but malformed is still HMD010.
107
+ - **`:` is reserved in a link target**, for namespace-qualified references
108
+ such as `[[namespace:article]]`. A target containing one is HMD010.
109
+ - **HMD012 is a warning.** A card beside a module's folder note of the same name
110
+ shadows the note, which stays reachable by its `index` path; like HMD018,
111
+ that is a shadow decided by a fixed order, not a content bug.
112
+ - **A heading fragment matches by key, not by slug** — the HyperMarkDown 0.1
113
+ rule. The key is the text in NFC, case-folded, with every character that is
114
+ not a letter, mark, or number turned into a space and the spaces collapsed.
115
+ `[[card#ошибка 404]]` reaches `# Ошибка 404!`, `[[card#STRASSE]]` reaches
116
+ `Straße`, and `[[card#Cafe]]` no longer reaches `Café`: accents are
117
+ significant, and letters of every script are kept, where the old slug
118
+ dropped them. A fragment matches the first heading with its key; the `_1`
119
+ suffix that reached a repeat is gone, so `[[card#setup_1]]` is now HMD004 and
120
+ a repeat is reached by a block anchor on its line.
121
+ - **HMD011 reports headings with the same key**, at each repeat, naming the
122
+ line of the heading a fragment reaches instead. It used to report a slug
123
+ collision and suggest the `_1` address.
124
+ - A heading's text is what a reader sees: `## The *fast* path` is
125
+ `The fast path` in the graph and in the derived nav, without its markup. The
126
+ graph's `slug` field is replaced by `key`.
127
+ - **HMD004 names the fragment as written**, `has no heading '#Cafe Menu'`,
128
+ rather than its slug.
129
+ - The MkDocs plugin and `hmd render` rewrite each heading link to the id
130
+ Python-Markdown's `toc` gives the heading the link matched — numbered `_1`
131
+ when an embedded heading of the same slug comes first on the page, `_1` for
132
+ a heading `toc` cannot slug at all, and the id set by `attr_list`'s `{#id}`.
133
+ A link whose fragment matched nothing links to the page.
134
+ - **Spans count UTF-8 bytes; columns count code points.** A span's offsets are
135
+ byte offsets from byte 0 of the card, and a line ends at `\n`, `\r\n`, or a
136
+ lone `\r`. Cards are read as bytes, so a `\r\n` file keeps its offsets, and a
137
+ block anchor on a `\r\n` line is found. A form feed or U+2028 no longer
138
+ starts a line.
139
+ - **A leading byte-order mark is ignored**, so frontmatter after one is
140
+ frontmatter.
141
+ - **Names compare in NFC.** A reference and a name on disk match whether
142
+ either is stored composed or decomposed, for cards and for import origins.
143
+ - **Only `.hmd/` marks a project root.** The `.git` fallback is gone: a tree
144
+ with no `.hmd/` above it is refused with a pointer to `hmd init` and
145
+ `--root`, where it used to load the repository root as a project.
146
+
147
+ ### Fixed
148
+ - **A key inside a one-line flow mapping is located.** A problem in
149
+ `nav: {order: x}` is reported at `order`, as the frontmatter position rules
150
+ say, no longer at `nav`.
151
+ - **The embed depth limit counts from zero, and HMD008 is reported at the
152
+ embed.** The starting card is depth zero and the limit is 16, so a chain of
153
+ exactly sixteen nested embeds is fine; it used to be reported. HMD008 is now
154
+ reported once, at the embed that would exceed the limit, where it used to
155
+ sit at line 1, column 1 of the card past it, once per chain.
156
+ - **An embed of a section no longer reports a false cycle.** The HMD007 check
157
+ followed every embed in the embedded card, where an embed of a heading or a
158
+ block expands that region only. One section of a card embedding another
159
+ section of the same card is not a cycle, and is no longer reported as one.
160
+
16
161
  ## [0.4.0] — 2026-11-15
17
162
 
18
163
  ### Added
@@ -36,6 +181,15 @@ only for the Python API.
36
181
  sweep is HMD002.
37
182
 
38
183
  ### Fixed
184
+ - **Block anchors are no longer rendered.** `hmd render` and the site printed
185
+ the trailing `^id` of every anchored block, including the tutorial paragraph
186
+ that says its anchor cannot be seen. Expansion now drops each anchor and its
187
+ leading whitespace, in a card's own text and in embedded text alike; an
188
+ anchor shown inside a fenced block stays.
189
+ - **An import alias is compared after NFC**, like every other name, so a
190
+ decomposed alias is reachable by a composed reference.
191
+ - **A code span does not cross a blank line in a `\r\n` or `\r` card.** The
192
+ test looked for two `\n` in a row and missed a blank line written with `\r`.
39
193
  - **A heading right below the frontmatter fence is a heading.** The fence was
40
194
  blanked together with its line breaks, so the first body line read as
41
195
  indented: `# Title` directly under `---` produced no heading, and a fragment
@@ -303,7 +457,9 @@ Deliberate, and tracked per proposal under `doc/proposals/HMD-NNNN/STATUS.md`:
303
457
  Both specifications — the format and the site — are still `drafted`. Expect the
304
458
  format to move before `1.0`.
305
459
 
306
- [Unreleased]: https://github.com/ewiger/hypermarkdown/compare/v0.3.1...HEAD
460
+ [Unreleased]: https://github.com/ewiger/hypermarkdown/compare/v0.5.0...HEAD
461
+ [0.5.0]: https://github.com/ewiger/hypermarkdown/compare/v0.4.0...v0.5.0
462
+ [0.4.0]: https://github.com/ewiger/hypermarkdown/compare/v0.3.1...v0.4.0
307
463
  [0.3.1]: https://github.com/ewiger/hypermarkdown/compare/v0.3.0...v0.3.1
308
464
  [0.3.0]: https://github.com/ewiger/hypermarkdown/compare/v0.2.0...v0.3.0
309
465
  [0.2.0]: https://github.com/ewiger/hypermarkdown/compare/v0.1.1...v0.2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypermarkdown
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: A strict, machine-checkable markdown dialect for project knowledge bases.
5
5
  Author: Yauhen Yakimovich
6
6
  License-Expression: MIT
@@ -148,7 +148,7 @@ Every other key is yours, and nothing will inspect it.
148
148
  | Command | What it does |
149
149
  | --- | --- |
150
150
  | `hmd init` | Write `.hmd/config.toml` and create the namespace root it names |
151
- | `hmd lint` | Parse, resolve, and report — `HMD001`–`HMD017`, text or JSON |
151
+ | `hmd lint` | Parse, resolve, and report — `HMD001`–`HMD019`, text or JSON |
152
152
  | `hmd render` | Expand embeds and rewrite links, to flat markdown or HTML |
153
153
  | `hmd graph` | Dump the resolved link graph as JSON |
154
154
  | `hmd info` | Show the resolved root and discovery policy |
@@ -159,7 +159,8 @@ the vault, the directory holding `.hmd/`, the cards start (`doc/wiki` by
159
159
  default, `.` for directly under the vault). The directory it names is the
160
160
  namespace root, and every command but `init` takes `--root` to override it. A
161
161
  `.hmd/` directory doubles as the project root marker, so any subtree can be
162
- self-contained.
162
+ self-contained, and it is the only marker: a `.git` directory is not one, so a
163
+ tree with no `.hmd/` above it needs `--root`.
163
164
 
164
165
  ```bash
165
166
  hmd init # here; the namespace is named after the directory
@@ -110,7 +110,7 @@ Every other key is yours, and nothing will inspect it.
110
110
  | Command | What it does |
111
111
  | --- | --- |
112
112
  | `hmd init` | Write `.hmd/config.toml` and create the namespace root it names |
113
- | `hmd lint` | Parse, resolve, and report — `HMD001`–`HMD017`, text or JSON |
113
+ | `hmd lint` | Parse, resolve, and report — `HMD001`–`HMD019`, text or JSON |
114
114
  | `hmd render` | Expand embeds and rewrite links, to flat markdown or HTML |
115
115
  | `hmd graph` | Dump the resolved link graph as JSON |
116
116
  | `hmd info` | Show the resolved root and discovery policy |
@@ -121,7 +121,8 @@ the vault, the directory holding `.hmd/`, the cards start (`doc/wiki` by
121
121
  default, `.` for directly under the vault). The directory it names is the
122
122
  namespace root, and every command but `init` takes `--root` to override it. A
123
123
  `.hmd/` directory doubles as the project root marker, so any subtree can be
124
- self-contained.
124
+ self-contained, and it is the only marker: a `.git` directory is not one, so a
125
+ tree with no `.hmd/` above it needs `--root`.
125
126
 
126
127
  ```bash
127
128
  hmd init # here; the namespace is named after the directory
@@ -140,6 +140,11 @@ hmd = "hypermarkdown.cli:main"
140
140
  hypermarkdown = "hypermarkdown.mkdocs_plugin:HyperMarkDownPlugin"
141
141
  hyper-markdown = "hypermarkdown.mkdocs_plugin:HyperMarkDownPlugin"
142
142
 
143
+ # A code sample marked ```hmd is coloured as a card. Pygments discovers lexers
144
+ # through this group, so nothing has to be configured where it is used.
145
+ [project.entry-points."pygments.lexers"]
146
+ hmd = "hypermarkdown.highlight:HmdLexer"
147
+
143
148
  [tool.setuptools.dynamic]
144
149
  version = { attr = "hypermarkdown.__version__" }
145
150
 
@@ -15,7 +15,7 @@ from .config import Config, ConfigError
15
15
  from .model import Diagnostic, Document, Link, Span
16
16
  from .resolve import Outcome, Resolution, Workspace
17
17
 
18
- __version__ = "0.4.0"
18
+ __version__ = "0.5.0"
19
19
 
20
20
  __all__ = [
21
21
  "Config",
@@ -32,7 +32,9 @@ EXIT_OK = 0
32
32
  EXIT_DIAGNOSTICS = 1
33
33
  EXIT_USAGE = 2
34
34
 
35
- RootOption = typer.Option(None, "--root", help="Namespace root (default: the `wiki` setting, or doc/wiki).")
35
+ RootOption = typer.Option(
36
+ None, "--root", help="Namespace root (default: the `location_path` setting, or the vault itself)."
37
+ )
36
38
  FormatOption = typer.Option("text", "--format", help="Output format: text or json.")
37
39
 
38
40
 
@@ -75,15 +77,22 @@ def _selected(workspace: Workspace, paths: list[Path] | None) -> list[Path] | No
75
77
  if not paths:
76
78
  return None
77
79
  selected: list[Path] = []
80
+ # A file that is not UTF-8 is not a card, but naming it is how its HMD019
81
+ # is asked for.
82
+ files = [*workspace.pages(), *workspace.undecodable]
78
83
  for raw in paths:
79
84
  candidate = raw.resolve()
80
85
  if candidate.is_dir():
81
- selected.extend(p for p in workspace.pages() if candidate in p.parents or candidate == p.parent)
86
+ selected.extend(p for p in files if candidate in p.parents or candidate == p.parent)
82
87
  elif card_suffix(candidate.name):
83
- if candidate not in workspace.documents:
88
+ if candidate in workspace.undecodable:
89
+ selected.append(candidate)
90
+ continue
91
+ card = workspace.card(candidate)
92
+ if card is None:
84
93
  typer.echo(f"hmd: not inside the namespace root: {raw}", err=True)
85
94
  raise typer.Exit(EXIT_USAGE)
86
- selected.append(candidate)
95
+ selected.append(card)
87
96
  else:
88
97
  typer.echo(f"hmd: not a card ({', '.join(CARD_SUFFIXES)}) or directory: {raw}", err=True)
89
98
  raise typer.Exit(EXIT_USAGE)
@@ -93,13 +102,17 @@ def _selected(workspace: Workspace, paths: list[Path] | None) -> list[Path] | No
93
102
  @app.command()
94
103
  def init(
95
104
  path: Optional[Path] = typer.Argument(None, help="Project root to initialise (default: the working directory)."),
96
- wiki: str = typer.Option(config_mod.DEFAULT_WIKI, "--wiki", help="Namespace root, relative to the project root."),
105
+ location_path: str = typer.Option(
106
+ config_mod.DEFAULT_LOCATION_PATH,
107
+ "--location-path",
108
+ help="Namespace root, relative to the project root (default: the project root itself).",
109
+ ),
97
110
  name: Optional[str] = typer.Option(None, "--name", help="Namespace name (default: the project directory's name)."),
98
111
  force: bool = typer.Option(False, "--force", help="Replace an existing .hmd/config.toml."),
99
112
  ) -> None:
100
113
  """Create `.hmd/config.toml` and the namespace root it names."""
101
114
  try:
102
- result = config_mod.init(path, wiki=wiki, name=name, force=force)
115
+ result = config_mod.init(path, location_path=location_path, name=name, force=force)
103
116
  except config_mod.ConfigError as exc:
104
117
  typer.echo(f"hmd: {exc}", err=True)
105
118
  raise typer.Exit(EXIT_USAGE)
@@ -113,7 +126,7 @@ def init(
113
126
 
114
127
  typer.echo(f"project: {result.project}{note(result.project)}")
115
128
  typer.echo(f"config: {result.config}{note(result.config)}")
116
- typer.echo(f"wiki: {result.wiki}{note(result.wiki)}")
129
+ typer.echo(f"location: {result.location}{note(result.location)}")
117
130
  typer.echo(
118
131
  f"namespace: {result.name} ({result.provider})"
119
132
  f"{' — from the directory name' if result.derived_name else ''}"
@@ -178,8 +191,8 @@ def render(
178
191
  raise typer.Exit(EXIT_USAGE)
179
192
 
180
193
  workspace = _workspace(root)
181
- target = path.resolve()
182
- if target not in workspace.documents:
194
+ target = workspace.card(path.resolve())
195
+ if target is None:
183
196
  typer.echo(f"hmd: not a page inside the namespace root: {path}", err=True)
184
197
  raise typer.Exit(EXIT_USAGE)
185
198
 
@@ -9,7 +9,14 @@ from pathlib import Path, PurePosixPath, PureWindowsPath
9
9
 
10
10
  MARKER_DIR = ".hmd"
11
11
  CONFIG_NAME = "config.toml"
12
- DEFAULT_WIKI = "doc/wiki"
12
+ #: The namespace root, relative to the vault, when `location_path` is not set:
13
+ #: the vault itself.
14
+ DEFAULT_LOCATION_PATH = "."
15
+
16
+ #: The key `location_path` replaced, with the default `doc/wiki`. A config that
17
+ #: still sets it is refused rather than read with a different root: the vault
18
+ #: would load, silently, as a different namespace than its author wrote.
19
+ RETIRED_KEY = "wiki"
13
20
  DEFAULT_MODE = "both"
14
21
  VALID_MODES = frozenset({"both", "recursive"})
15
22
 
@@ -32,14 +39,15 @@ CONFIG_TEMPLATE = """\
32
39
  # HyperMarkdown project configuration.
33
40
  #
34
41
  # This directory doubles as the project root marker — `hmd` finds a project by
35
- # walking up from the working directory looking for `.hmd/`, falling back to
36
- # `.git/`. Only the settings below are read; every other key is ignored, so the
37
- # file is safe to extend.
42
+ # walking up from the working directory looking for `.hmd/`, and nothing else
43
+ # marks one. Only the settings below are read; every other key is ignored, so
44
+ # the file is safe to extend.
38
45
 
39
46
  # The cards location: where inside this project the cards start, relative to
40
- # this project root. It names the namespace root. Every `.hmd` card beneath
41
- # it is a page, and links resolve within it. Nothing outside it is checked.
42
- wiki = "{wiki}"
47
+ # this project root, with `/` between directories. It names the namespace
48
+ # root; "." is this project root itself. Every `.hmd` card beneath it is a
49
+ # page, and links resolve within it. Nothing outside it is checked.
50
+ location_path = "{location_path}"
43
51
 
44
52
  [namespace]
45
53
  # This tree's own name. A project's own namespace is otherwise unnamed — there
@@ -80,7 +88,7 @@ class InitResult:
80
88
 
81
89
  project: Path # the project root, absolute
82
90
  config: Path # the config file, written either way
83
- wiki: Path # the namespace root the config names, absolute
91
+ location: Path # the namespace root the config names, absolute
84
92
  created: frozenset[Path] # of the three above, the ones that did not exist
85
93
  name: str = "" # the namespace name written, derived or given
86
94
  provider: str = DEFAULT_PROVIDER # what backs that name
@@ -94,24 +102,26 @@ class ConfigError(Exception):
94
102
 
95
103
 
96
104
  def find_project_root(start: Path) -> Path | None:
97
- """Nearest ancestor holding `.hmd/`, else nearest holding `.git`."""
105
+ """Nearest ancestor holding `.hmd/`, or None.
106
+
107
+ Only `.hmd/` marks a project root. A `.git` directory does not: every
108
+ repository has one, and a repository is not a vault until it says so. A
109
+ tree with no marker above it has its namespace root named directly.
110
+ """
98
111
  start = start.resolve()
99
112
  candidates = [start, *start.parents] if start.is_dir() else list(start.parents)
100
113
  for parent in candidates:
101
114
  if (parent / MARKER_DIR).is_dir():
102
115
  return parent
103
- for parent in candidates:
104
- if (parent / ".git").exists():
105
- return parent
106
116
  return None
107
117
 
108
118
 
109
119
  def load(root_override: Path | None = None, start: Path | None = None) -> Config:
110
120
  """Resolve the namespace root and discovery policy.
111
121
 
112
- Absent `.hmd/config.toml` entirely, the root is `doc/wiki`, autodiscovery is
113
- on, and the mode is `both` — a tree with no configuration behaves the way a
114
- new author expects.
122
+ Absent `.hmd/config.toml` entirely, the root is the project root itself,
123
+ autodiscovery is on, and the mode is `both` — a tree with no configuration
124
+ behaves the way a new author expects.
115
125
  """
116
126
  if root_override is not None:
117
127
  root = root_override.resolve()
@@ -130,16 +140,17 @@ def load(root_override: Path | None = None, start: Path | None = None) -> Config
130
140
  project = find_project_root(start)
131
141
  if project is None:
132
142
  raise ConfigError(
133
- f"no project root above {start}: expected a .hmd/ or .git directory. "
134
- f"Pass --root to name the namespace root directly."
143
+ f"no project root above {start}: expected a .hmd/ directory. "
144
+ f"Run `hmd init`, or pass --root to name the namespace root directly."
135
145
  )
136
146
 
137
147
  data, source = _read(project)
138
- wiki = data.get("wiki", DEFAULT_WIKI)
139
- if not isinstance(wiki, str):
140
- raise ConfigError(f"`wiki` must be a string in {source}")
148
+ location = data.get("location_path", DEFAULT_LOCATION_PATH)
149
+ if not isinstance(location, str):
150
+ raise ConfigError(f"`location_path` must be a string in {source}")
141
151
 
142
- root = (project / wiki).resolve()
152
+ root = (project / location).resolve()
153
+ _check_not_in_nested_vault(project, location, source)
143
154
  if not root.is_dir():
144
155
  raise ConfigError(f"namespace root does not exist: {root}")
145
156
 
@@ -148,7 +159,7 @@ def load(root_override: Path | None = None, start: Path | None = None) -> Config
148
159
 
149
160
  def init(
150
161
  project: Path | None = None,
151
- wiki: str = DEFAULT_WIKI,
162
+ location_path: str = DEFAULT_LOCATION_PATH,
152
163
  name: str | None = None,
153
164
  provider: str = DEFAULT_PROVIDER,
154
165
  force: bool = False,
@@ -161,7 +172,7 @@ def init(
161
172
  folder is already called.
162
173
 
163
174
  The namespace root is created alongside the config on purpose. `load`
164
- refuses a `wiki` setting that points at nothing, so writing the file and
175
+ refuses a `location_path` setting that points at nothing, so writing the file and
165
176
  stopping there would leave a project whose very next command fails with a
166
177
  message about a directory the author never asked for.
167
178
 
@@ -173,7 +184,7 @@ def init(
173
184
  if project.exists() and not project.is_dir():
174
185
  raise ConfigError(f"project root is not a directory: {project}")
175
186
 
176
- setting = _wiki_setting(wiki)
187
+ setting = _location_setting(location_path)
177
188
  namespace = _namespace_name(project) if name is None else _checked_name(name)
178
189
  if provider not in VALID_PROVIDERS:
179
190
  raise ConfigError(f"provider must be one of {sorted(VALID_PROVIDERS)}, got {provider!r}")
@@ -181,11 +192,11 @@ def init(
181
192
 
182
193
  marker = project / MARKER_DIR
183
194
  config_path = marker / CONFIG_NAME
184
- wiki_path = project / setting
195
+ location = project / setting
185
196
 
186
197
  # Everything that can fail is checked before anything is written. The
187
198
  # command touches three paths, and a run that creates the marker and then
188
- # trips over the wiki root leaves a project half-made — with a config file
199
+ # trips over the namespace root leaves a project half-made — with a config file
189
200
  # claiming a root that is not there, which is the one state `load` cannot
190
201
  # explain to whoever finds it.
191
202
  overwritten = config_path.is_file()
@@ -193,16 +204,16 @@ def init(
193
204
  raise ConfigError(f"already initialised: {config_path} exists. Pass --force to replace it.")
194
205
  if marker.exists() and not marker.is_dir():
195
206
  raise ConfigError(f"{marker} exists and is not a directory")
196
- if wiki_path.exists() and not wiki_path.is_dir():
197
- raise ConfigError(f"wiki root exists and is not a directory: {wiki_path}")
207
+ if location.exists() and not location.is_dir():
208
+ raise ConfigError(f"namespace root exists and is not a directory: {location}")
198
209
 
199
- created = frozenset(path for path in (project, config_path, wiki_path) if not path.exists())
210
+ created = frozenset(path for path in (project, config_path, location) if not path.exists())
200
211
 
201
212
  try:
202
213
  marker.mkdir(parents=True, exist_ok=True)
203
214
  config_path.write_text(
204
215
  CONFIG_TEMPLATE.format(
205
- wiki=setting,
216
+ location_path=setting,
206
217
  name=namespace,
207
218
  provider=provider,
208
219
  autodiscovery="true",
@@ -210,14 +221,14 @@ def init(
210
221
  ),
211
222
  encoding="utf-8",
212
223
  )
213
- wiki_path.mkdir(parents=True, exist_ok=True)
224
+ location.mkdir(parents=True, exist_ok=True)
214
225
  except OSError as exc:
215
226
  raise ConfigError(f"cannot initialise {project}: {exc}") from exc
216
227
 
217
228
  return InitResult(
218
229
  project=project.resolve(),
219
230
  config=config_path.resolve(),
220
- wiki=wiki_path.resolve(),
231
+ location=location.resolve(),
221
232
  created=frozenset(path.resolve() for path in created),
222
233
  name=namespace,
223
234
  provider=provider,
@@ -227,23 +238,46 @@ def init(
227
238
  )
228
239
 
229
240
 
230
- def _wiki_setting(value: str) -> str:
231
- """Normalise a `--wiki` argument into a TOML-safe relative path.
241
+ def _check_not_in_nested_vault(project: Path, location: str, source: Path | None) -> None:
242
+ """Refuse a `location_path` that resolves into a nested vault.
243
+
244
+ The namespace root has to lie in the vault whose config names it. A
245
+ directory between the vault and the root that carries its own `.hmd/` is
246
+ another vault, and its cards are never this vault's. The vault's own marker
247
+ is not counted.
248
+ """
249
+ directory = project
250
+ for part in PurePosixPath(location).parts:
251
+ if part in (".", "/"):
252
+ continue
253
+ directory = directory / part
254
+ if (directory / MARKER_DIR).is_dir():
255
+ raise ConfigError(
256
+ f"`location_path` {location!r} in {source} resolves into the nested vault at "
257
+ f"{directory.relative_to(project).as_posix()}; the namespace root must lie in "
258
+ f"the vault that names it"
259
+ )
260
+
261
+
262
+ def _location_setting(value: str) -> str:
263
+ """Normalise a `--location-path` argument into a TOML-safe relative path.
232
264
 
233
265
  Rejected rather than escaped: absolute paths, `..` escapes, and the two
234
- characters a TOML basic string would need escaping. A wiki root outside the
235
- project it is configured from is not a narrower project, it is a config file
236
- filed somewhere it does not describe.
266
+ characters a TOML basic string would need escaping. A namespace root outside
267
+ the project it is configured from is not a narrower project, it is a config
268
+ file filed somewhere it does not describe.
237
269
  """
238
270
  text = value.strip().replace("\\", "/")
239
271
  if not text:
240
- raise ConfigError("wiki must name a directory relative to the project root")
272
+ raise ConfigError("location_path must name a directory relative to the project root")
241
273
  if PurePosixPath(text).is_absolute() or PureWindowsPath(text).is_absolute():
242
- raise ConfigError(f"wiki must be relative to the project root, got {value!r}")
274
+ raise ConfigError(f"location_path must be relative to the project root, got {value!r}")
243
275
  if ".." in PurePosixPath(text).parts:
244
- raise ConfigError(f"wiki must stay inside the project root, got {value!r}")
276
+ raise ConfigError(f"location_path must stay inside the project root, got {value!r}")
245
277
  if '"' in text or any(ord(char) < 0x20 for char in text):
246
- raise ConfigError(f"wiki contains characters a TOML string cannot hold: {value!r}")
278
+ raise ConfigError(
279
+ f"location_path contains characters a TOML string cannot hold: {value!r}"
280
+ )
247
281
  return PurePosixPath(text).as_posix()
248
282
 
249
283
 
@@ -279,8 +313,7 @@ def _checked_name(value: str) -> str:
279
313
  def _enclosing_project(project: Path) -> Path | None:
280
314
  """The nearest ancestor already carrying a `.hmd/`, if any.
281
315
 
282
- Only the marker counts, not the `.git` fallback — every repository would
283
- answer to that one, and nesting inside a repository is the normal case.
316
+ Only the marker counts, the same rule `find_project_root` follows.
284
317
  """
285
318
  start = project.resolve()
286
319
  for parent in start.parents:
@@ -295,9 +328,15 @@ def _read(project: Path) -> tuple[dict, Path | None]:
295
328
  return {}, None
296
329
  try:
297
330
  with path.open("rb") as handle:
298
- return tomllib.load(handle), path
331
+ data = tomllib.load(handle)
299
332
  except (OSError, tomllib.TOMLDecodeError) as exc:
300
333
  raise ConfigError(f"cannot read {path}: {exc}") from exc
334
+ if RETIRED_KEY in data:
335
+ raise ConfigError(
336
+ f"{path} sets `{RETIRED_KEY}`, which HyperMarkDown 0.1 renamed to "
337
+ f"`location_path`. Rename the key; the vault is not loaded until it is."
338
+ )
339
+ return data, path
301
340
 
302
341
 
303
342
  def _discovery(data: dict) -> dict: