Repository navigation
markdown-fragments-1 #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
azaayapbergenov
wants to merge
8
commits into
bjones1:main
Choose a base branch
from
azaayapbergenov:markdown-fragments-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
markdown-fragments-1 #169
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b136a5f
Spec: define fragments in Markdown documents
azaayapbergenov f14d215
More spefic spec for fragment <Markdown>
Crazy24-x c2189c3
Remove misplaced cache-spec.md from repo root
azaayapbergenov 70ab139
Point cache-spec.md at the Markdown fragment specification
azaayapbergenov 3fc44f3
Spec: only top-level headings bound a Markdown fragment
azaayapbergenov 41176ee
Point cache-spec.md at the Markdown fragment specification
azaayapbergenov 56dd984
cache-spec: separate source-file and Markdown fragment behavior
azaayapbergenov 6106c96
Add draft submission.md
azaayapbergenov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 `<fragment>` | ||
| 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 | ||
| `<fragment>` 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 `<fragment>` tag itself is never part of the content: it is removed, along | ||
| with any backlinks hydrated into it. | ||
|
|
||
| ### Example | ||
|
|
||
| ````markdown | ||
| ## Request | ||
|
|
||
| <fragment id="req"></fragment> | ||
|
|
||
| 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 `<fragment id="req" following="1"></fragment>` 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. | ||
| * `<fragment>` 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** (`<fragment>...</fragment>`). 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| `<fragment>` 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the cache spec that still prohibits Markdown fragments.
server/src/processing/cache-spec.mdlines 144-146 state that fragments are not allowed in Markdown documents and that their content is an error message. This PR leaves that file unchanged.markdown-fragments-spec.mdremoves that rule, so the two specifications give opposite instructions.server/src/processing/cache.rslinks tocache-spec.md, so a reader following that link receives the old rule.Replace the prohibition in
cache-spec.mdwith a statement that Markdown fragments follow the rules inmarkdown-fragments-spec.md. Add a link to that file at the same point. Remove the error-message rule.Mark the Markdown fragment rule as planned, not current behavior.
Lines 11-12 say that a Markdown fragment "is now valid." The current processing code still rejects Markdown fragments with "fragments are not allowed in Markdown documents." Readers can take the specification as a description of current behavior. State that the rule is a design that the implementation does not yet provide.
Suggested fix
Committable suggestion