diff --git a/server/src/processing/cache-spec.md b/server/src/processing/cache-spec.md index 704d8cf5..c37e9154 100644 --- a/server/src/processing/cache-spec.md +++ b/server/src/processing/cache-spec.md @@ -140,14 +140,15 @@ things` is a `Target` with the `data-gather` attribute. It becomes a list of the content of fragments it refers to after hydration by the cache. An example fragment tag, after cache hydration: `See Bazzy things, Zappy things`. A fragment's -content by default includes the content of the current doc block and the content -of the following code/doc block; fragments are not allowed in Markdown documents -(in this case, the fragment content consists of an error message). Fragments may -include the `following` attribute to enclose a specific number of the following -code/doc blocks; for example, `` -includes the current doc block along with the next 3 code/doc blocks; -`following` must be a whole number. +href="path/to/another/gather#zap">Zappy things`. In a source +file, a fragment's content by default includes the content of the current doc +block and the content of the following code/doc block. Fragments may include the +`following` attribute to enclose a specific number of the following code/doc +blocks; for example, `` includes the +current doc block along with the next 3 code/doc blocks; `following` must be a +whole number. In a Markdown document, a fragment instead encloses a section of +top-level blocks, and `following` counts top-level blocks; see +[markdown-fragments-spec.md](markdown-fragments-spec.md). Details: diff --git a/server/src/processing/markdown-fragments-spec.md b/server/src/processing/markdown-fragments-spec.md new file mode 100644 index 00000000..56b647b9 --- /dev/null +++ b/server/src/processing/markdown-fragments-spec.md @@ -0,0 +1,134 @@ +Fragments in Markdown documents +------------------------------- + +A Markdown document has no code blocks or doc blocks, so the rules which count +code/doc blocks cannot apply to it. This section defines what a `` +encloses in a Markdown document, so that a gather element can display it just as +it displays a fragment in a source file. The rest of the cache (ids, dependents, +the reverse edge, outdating) is unchanged; only the *extent* and *content* of a +Markdown fragment are new. + +This replaces the earlier rule that fragments are not allowed in Markdown +documents: such a fragment is now valid and has the extent defined below. + +### What a fragment encloses + +The rules are expressed in terms of the document's **top-level blocks**: the +children of the rendered document's root (a paragraph, heading, list, block +quote, code block, table, and so on). A block nested inside another (a list item +inside a list) belongs to its top-level block. + +* **Default.** The fragment encloses the top-level block containing the + `` tag, then every following top-level block up to, but not + including, the next heading whose level is the same as or higher (a smaller + number) than that of the closest heading at or before the tag. If no heading + precedes the tag, the fragment ends at the end of the document. If the tag is + inside a heading, that heading is the closest one, and it is included in the + fragment. Skipped heading levels (a `###` directly under a `#`) make no + difference: only the numeric levels are compared. +* **Only top-level headings count.** A heading nested inside another block (a + list item or block quote) is neither the "closest heading" nor a + section-ending heading; it is ordinary content of its top-level block. +* **`following="N"`.** The fragment encloses the block containing the tag plus + the next `N` top-level blocks, regardless of headings. `N` must be a whole + number; `following="0"` encloses only the block containing the tag. A value + larger than the number of remaining blocks is clamped to the end of the + document. A value which isn't a whole number replaces the fragment's content + with an error message, as in source files. +* The `` tag itself is never part of the content: it is removed, along + with any backlinks hydrated into it. + +### Example + +````markdown +## Request + + + +The client sends a `POST` to `/upload`. + +* The body is JSON. +* The reply is `204`. + +## Response + +The server replies... +```` + +`req` encloses the block holding the tag, the paragraph, and the list, and stops +before `## Response`, since that heading has the same level as `## Request`. +Replacing the tag with `` encloses +only the tag's block and the paragraph. + +### Content stored in the cache + +The cache stores each Markdown fragment's content as cleaned HTML, produced by +the same cleaner used for source-file fragments: + +* All `id` attributes are removed, so a gather element never duplicates an id. +* `` tags are removed with their contents, so backlink hydration is + excluded from the stored content; this is what keeps a gather element and the + fragments it lists from outdating each other forever (see the reverse edge). +* Cross-references in the content are hydrated in the fragment's file, then + re-hydrated by the gather element so that links lead from the gather + element's file. +* Relative images and URLs in the content aren't rewritten; as stated under + "Misc", they aren't supported when the gathering file lies in a different + directory. + +Unlike a source-file fragment, the content has no line-number gutter or indents, +since a Markdown document has none. + +### Keeping the cache current + +Because a Markdown fragment's extent depends on the document's structure, the +cache re-derives it each time the file is processed. A fragment's stored content +changes when any enclosed block changes, when the enclosing section gains or +loses blocks, or when a heading is added, removed, or changes level so that the +section ends elsewhere. As for any fragment, changed content outdates the files +containing gather elements which list it (`update_fragment_content`). + +### Errors + +A Markdown fragment produces an error message, as a source-file fragment does, +when: + +* it has no `id`, or its `id` isn't a valid CSS identifier; +* its `following` value isn't a whole number; +* its enclosed blocks contain a gather element, including one whose `id` is + missing or invalid (a fragment must not gather); +* its `id` is a duplicate. + +A gather element listing a Markdown fragment follows the existing rules: an +error message replaces the content for an id which is missing, duplicated, or +names a target rather than a fragment. + +### Edge cases + +* Two fragments in the same section both enclose the rest of the section, so + their contents overlap; this is allowed. +* A fragment tag in the last block of the document encloses only that block. +* A tag inside a code block or inline code is literal text, not a fragment. +* Nested block quotes and lists count as one top-level block. +* A heading inside a list item or block quote never starts or ends a section. + +### Why this design + +Alternatives considered: + +1. **Everything in the current heading, ignoring the tag's position.** Simple, + but the author can't enclose less than a whole section, and content above + the tag within the same heading is always included. Starting at the block + holding the tag lets the author choose where a fragment begins by placing + the tag, while still ending at the section's end by default. +2. **Only the text inside the tag** (`...`). Markdown's HTML + block rules end an HTML block at the first blank line, so multi-paragraph + content wouldn't stay inside the tag. +3. **An explicit end tag.** Flexible, but easy to forget, and an unclosed tag + silently swallows the rest of the document. +4. **Block counting only.** Matches source files, but breaks when blocks are + added or removed; the section default adapts automatically. + +The chosen design keeps the existing `following` attribute, so source files and +Markdown behave alike, and adds a default which follows the document's own +structure. diff --git a/server/src/processing/submission.md b/server/src/processing/submission.md new file mode 100644 index 00000000..8c232662 --- /dev/null +++ b/server/src/processing/submission.md @@ -0,0 +1,111 @@ +Project 2 submission +==================== + +Team name: markdown-fragments-1 + +The specification consists of the file +[markdown-fragments-spec.md](markdown-fragments-spec.md), which defines what a +`` encloses in a Markdown document. + +Draft submission +---------------- + +### Azamat Ayapbergenov + +GitHub userid: azaayapbergenov + +#### Contributions + +Wrote the Markdown fragment specification (default extent, `following="N"`, +cached content, errors, edge cases, and the design alternatives) and prepared +this submission. + +#### Build and run test + +Prompting Copilot Fusion (standard effort) with "Verify that you can build and +run the project in the current git repo." gave a partial verification: + +* `cargo build --workspace` succeeded with warnings only. The documented build + then stopped at `cargo nextest run export_bindings` because `cargo-nextest` is + not installed; Node.js and pnpm are also missing, so the client and extension + builds could not run. +* The standalone server started and answered `/ping` with HTTP 200 `pong` when + given a temporary placeholder asset map. This verifies HTTP startup but not + the full UI, whose generated assets are missing. +* The worktree stayed clean; the smoke-test process and temporary files were + removed. + +Conclusion: the backend builds and the server starts; a complete build and UI +run are unverified until the missing tools are installed. + +#### Specification review rounds + +| Round | Findings | Main changes made | +| ----- | -------- | ----------------- | +| 1 | 2 | Replaced the `cache-spec.md` rule banning Markdown fragments with a link to `markdown-fragments-spec.md` | +| 2 | 2 | Only top-level headings count as section boundaries (new rule and edge case); `cache-spec.md` now says `following` counts top-level blocks in Markdown | +| 3 | 2 | `cache-spec.md` now describes source-file and Markdown fragment behavior (default extent and `following`) in separate sentences | +| 4 | **TODO** | **TODO** | + +#### Last specification review + +Prompting Copilot Fusion, standard effort, with +`Review the section named "Fragments in Markdown documents" in markdown-fragments-spec.md, writing findings to review.md` +produced the following output; strikethrough indicates LLM output that I deemed +incorrect or irrelevant. + +> **TODO: replace with the output of your final round once more rounds are +> done. The text below is round 3.** +> +> ### Findings +> +> #### High +> +> 1. ~~**The Markdown fragment rules are not implemented.** +> `server/src/processing.rs` (line 2711) explicitly replaces every fragment +> in a Markdown document with "fragments are not allowed in Markdown +> documents". The `server/src/processing/tests.rs` (line 2897) also asserts +> this obsolete behavior.~~ +> +> ~~This directly contradicts the section, which says Markdown fragments are +> valid and defines their default and `following` extents. The implementation +> also has no Markdown top-level-block walk or cleaned HTML cache storage for +> this feature.~~ +> +> #### Medium +> +> 2. **The cache specification still describes source-file fragment behavior as +> the general default.** `server/src/processing/cache-spec.md` (line 138) +> says that fragment content normally includes the current doc block and the +> next code/doc block, and that `following` counts code/doc blocks even +> though the following paragraph links Markdown readers to the new section. +> +> That wording is ambiguous for Markdown: the general default is +> section-based there, not current-doc-block-plus-next-block. It should +> explicitly separate source-file and Markdown behavior so the cache +> specification does not retain two incompatible `following` and default +> models. + +### (Team member 2 name) + +GitHub userid: Crazy24-x + +#### Contributions + +#### Build and run test + +#### Specification review rounds + +#### Last specification review + +### (Team member 3 name) + +GitHub userid: AlisherToxanbayev + +#### Contributions + +#### Build and run test + +#### Specification review rounds + +#### Last specification review