From 045a4248ef353ea3553e1c7bec2556a8286ed93f Mon Sep 17 00:00:00 2001 From: Altynay K Date: Thu, 26 Nov 2026 12:53:32 +0500 Subject: [PATCH 01/12] made initial draft and organized submission template --- .../Project 2 submission.md | 91 +++++++++++ YAML team 2 specification/draft.md | 145 ++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 YAML team 2 specification/Project 2 submission.md create mode 100644 YAML team 2 specification/draft.md diff --git a/YAML team 2 specification/Project 2 submission.md b/YAML team 2 specification/Project 2 submission.md new file mode 100644 index 00000000..82b6cdac --- /dev/null +++ b/YAML team 2 specification/Project 2 submission.md @@ -0,0 +1,91 @@ +Project 2 submission +==================== + +Team members are Altynay Kishkenebayeva, Aiym Saparkhan, +Daulet Bakytkhanov, +Ali Zhumatayev. The specification +consists of the file [ .md]( .md). + +Draft submission +---------------- + +### Compiler test + +The following statements summarize LLM output on each team member's computer, +based on the prompt "Verify that you can compile and run the project in the +current git repo." + +### Altynay + +Created first draft version. + +#### LLM Review (Copilot / GPT-Luna-6 balanced) + +Lorem ipsum + +#### Spec review rounds + +Lorem ipsum + +#### Last LLM review + +Lorem ipsum + + + +### Ali + + + + +### Daulet + + + + +### Aiym + + + + + +--- + +Final submission +---------------- + +### Altynay + +#### Contributions + +Lorem ipsum + +#### Spec review rounds + +Lorem ipsum + +#### Implementation review rounds + +Lorem ipsum + +#### Last LLM spec review + +Lorem ipsum + +#### Last LLM implementation review + +Lorem ipsum + + + +### Ali + + + + +### Daulet + + + + +### Aiym \ No newline at end of file diff --git a/YAML team 2 specification/draft.md b/YAML team 2 specification/draft.md new file mode 100644 index 00000000..a4da321d --- /dev/null +++ b/YAML team 2 specification/draft.md @@ -0,0 +1,145 @@ +# YAML Front Matter Preservation +================================ + +## Status + +Draft specification. Recognition rules and the exact preservation of line +endings and HTML-sensitive text still need review. + +## Purpose + +Preserve a YAML metadata block at the beginning of a Markdown document when the +CodeChat Editor converts Markdown to HTML and later converts that HTML back to +Markdown. + +The YAML is opaque text. The editor must not parse, validate, reorder, or +reformat it. + +## Scope + +This specification covers only a YAML block at the beginning of a Markdown +document, delimited by lines containing `---`. In HTML, the block is represented +by a ` +

Hello

+``` + +The precise whitespace around the element may follow the existing HTML +serializer, but it must not become part of the YAML payload. + +## HTML to Markdown + +1. Before converting the HTML document to Markdown, find its YAML element. +2. Extract the element's text content without parsing or formatting it. +3. Exclude the YAML element from the HTML passed to the normal HTML-to-Markdown + converter. The element must not produce visible Markdown or be converted as + an ordinary script or code block. +4. If one YAML element is found, prepend a front matter block to the converted + Markdown: an opening `---` line, the extracted payload, and a closing `---` + line. +5. If no YAML element is found, convert the HTML as usual. + +The presence of the YAML element must not change how the rest of the document +is converted. + +## Preservation and error cases + +* Preserve payload characters and ordering. In particular, do not normalize + indentation, spaces, comments, blank lines, or YAML key ordering. +* Do not reject a payload because it is not valid YAML. YAML validation is out + of scope. +* An opening delimiter without a closing delimiter is not a complete block; + under this draft, leave the document unchanged and render it as ordinary + Markdown. +* A closing delimiter is the first later line that exactly matches `---`. + Delimiter lines containing extra spaces are not recognized under this draft. +* The expected document has at most one YAML element. Handling multiple + matching elements must be decided before implementation; do not silently + discard additional payloads. +* HTML `` can terminate the element + early. The implementation must use a reversible representation or define a + limitation that prevents data loss. HTML entity escaping alone may not + preserve text inside a script element. +* HTML parsers can normalize line endings. The required fidelity for CRLF versus + LF must be decided: preserve the original line-ending representation, or + preserve the payload text with line endings normalized. +* The editor's HTML processing and save/reopen path must retain the YAML + element, and the element must not appear as visible document content. + +## Acceptance tests + +At minimum, tests must cover: + +* A document with front matter converts to HTML with exactly one YAML element + and converts back with the payload unchanged. +* Markdown after the closing delimiter is still rendered and converted + normally. +* A document without front matter converts as before and does not gain a YAML + element. +* An empty payload and a payload containing comments, blank lines, indentation, + colons, and non-ASCII text are preserved. +* An unclosed opening delimiter follows the specified incomplete-block rule. +* HTML without a YAML element converts as before. +* The YAML element is not included in the Markdown produced by the ordinary + HTML-to-Markdown conversion. +* HTML-sensitive payload text and line endings follow the final preservation + decisions above. +* Opening and saving a document through the editor does not display or remove + the metadata. + +## Open questions for review + +1. Should delimiters allow surrounding whitespace, or must a delimiter line be + exactly `---`? +2. Should a UTF-8 byte-order mark before the first delimiter be accepted? +3. Must payload preservation include the exact original line-ending + representation? +4. What reversible representation should be used for payload text that could + close the HTML script element? +5. Should multiple YAML elements be an error, or should a deterministic one be + selected? \ No newline at end of file From 46037317f148c45ede7685663eba4d2822f5dadd Mon Sep 17 00:00:00 2001 From: Altynay K Date: Thu, 26 Nov 2026 13:23:22 +0500 Subject: [PATCH 02/12] Added 1 round --- .../Project 2 submission.md | 55 +++++- YAML team 2 specification/draft.md | 145 --------------- YAML team 2 specification/yaml-spec.md | 168 ++++++++++++++++++ 3 files changed, 219 insertions(+), 149 deletions(-) delete mode 100644 YAML team 2 specification/draft.md create mode 100644 YAML team 2 specification/yaml-spec.md diff --git a/YAML team 2 specification/Project 2 submission.md b/YAML team 2 specification/Project 2 submission.md index 82b6cdac..1f8656b3 100644 --- a/YAML team 2 specification/Project 2 submission.md +++ b/YAML team 2 specification/Project 2 submission.md @@ -4,7 +4,7 @@ Project 2 submission Team members are Altynay Kishkenebayeva, Aiym Saparkhan, Daulet Bakytkhanov, Ali Zhumatayev. The specification -consists of the file [ .md]( .md). +consists of the file [yaml-spec.md](yaml-spec.md). Draft submission ---------------- @@ -17,15 +17,62 @@ current git repo." ### Altynay -Created first draft version. +#### Contributions +- Created first draft version. #### LLM Review (Copilot / GPT-Luna-6 balanced) -Lorem ipsum +``` +prompt: Please review @attachment:yaml-spec.md and give your feedback +``` + +The specification clearly identifies the main transformation, uses a focused +scope, and provides a useful draft for recognizing and preserving front matter. +However, it is not yet implementation-ready: several preservation decisions +affect both Markdown parsing and HTML round-tripping, and the draft leaves them +to later implementation. + +* The Markdown rules should define the exact byte or character model for line + boundaries. In particular, state whether CRLF is retained or normalized, how + a payload with no final newline is reconstructed, and whether the two + delimiter lines have to have matching line terminators. The HTML-to-Markdown + step also needs to account for the newline between a payload and the closing + delimiter so that a round trip does not add or remove characters. +* The handling of `` in a payload is underspecified even though the + spec correctly identifies the risk. Entity escaping is not sufficient inside + a script element. The HTML representation must be named and reversible, or + the specification must explicitly exclude that input; an implementation + should not silently split, truncate, or alter the payload. +* The behavior for multiple matching YAML elements is not decided. It should + say whether this is an error or, as a deterministic alternative, which + element is used and whether the others are preserved or discarded. +* The exact HTML identification rules are incomplete. Define whether `type` + matching is case-sensitive and whitespace-sensitive, and whether extra + attributes are allowed. It should also define whether the element must be + the first HTML element and whether ``, a final newline in the payload, BOM input, delimiter +lines with surrounding whitespace, and editor save/reopen behavior through the +real HTML serializer and parser rather than only through string operations. +These additions would make the acceptance criteria testable and would avoid +differences between implementations. #### Spec review rounds -Lorem ipsum +| Round number | Number of findings | Summary | +| --- | ---: | --- | +| 1 | 6 | Defined exact line-ending and payload boundaries, reversible `` handling, multiple-element behavior, HTML element matching rules, BOM and delimiter edge cases, and the closing-delimiter limitation. | #### Last LLM review diff --git a/YAML team 2 specification/draft.md b/YAML team 2 specification/draft.md deleted file mode 100644 index a4da321d..00000000 --- a/YAML team 2 specification/draft.md +++ /dev/null @@ -1,145 +0,0 @@ -# YAML Front Matter Preservation -================================ - -## Status - -Draft specification. Recognition rules and the exact preservation of line -endings and HTML-sensitive text still need review. - -## Purpose - -Preserve a YAML metadata block at the beginning of a Markdown document when the -CodeChat Editor converts Markdown to HTML and later converts that HTML back to -Markdown. - -The YAML is opaque text. The editor must not parse, validate, reorder, or -reformat it. - -## Scope - -This specification covers only a YAML block at the beginning of a Markdown -document, delimited by lines containing `---`. In HTML, the block is represented -by a ` -

Hello

-``` - -The precise whitespace around the element may follow the existing HTML -serializer, but it must not become part of the YAML payload. - -## HTML to Markdown - -1. Before converting the HTML document to Markdown, find its YAML element. -2. Extract the element's text content without parsing or formatting it. -3. Exclude the YAML element from the HTML passed to the normal HTML-to-Markdown - converter. The element must not produce visible Markdown or be converted as - an ordinary script or code block. -4. If one YAML element is found, prepend a front matter block to the converted - Markdown: an opening `---` line, the extracted payload, and a closing `---` - line. -5. If no YAML element is found, convert the HTML as usual. - -The presence of the YAML element must not change how the rest of the document -is converted. - -## Preservation and error cases - -* Preserve payload characters and ordering. In particular, do not normalize - indentation, spaces, comments, blank lines, or YAML key ordering. -* Do not reject a payload because it is not valid YAML. YAML validation is out - of scope. -* An opening delimiter without a closing delimiter is not a complete block; - under this draft, leave the document unchanged and render it as ordinary - Markdown. -* A closing delimiter is the first later line that exactly matches `---`. - Delimiter lines containing extra spaces are not recognized under this draft. -* The expected document has at most one YAML element. Handling multiple - matching elements must be decided before implementation; do not silently - discard additional payloads. -* HTML `` can terminate the element - early. The implementation must use a reversible representation or define a - limitation that prevents data loss. HTML entity escaping alone may not - preserve text inside a script element. -* HTML parsers can normalize line endings. The required fidelity for CRLF versus - LF must be decided: preserve the original line-ending representation, or - preserve the payload text with line endings normalized. -* The editor's HTML processing and save/reopen path must retain the YAML - element, and the element must not appear as visible document content. - -## Acceptance tests - -At minimum, tests must cover: - -* A document with front matter converts to HTML with exactly one YAML element - and converts back with the payload unchanged. -* Markdown after the closing delimiter is still rendered and converted - normally. -* A document without front matter converts as before and does not gain a YAML - element. -* An empty payload and a payload containing comments, blank lines, indentation, - colons, and non-ASCII text are preserved. -* An unclosed opening delimiter follows the specified incomplete-block rule. -* HTML without a YAML element converts as before. -* The YAML element is not included in the Markdown produced by the ordinary - HTML-to-Markdown conversion. -* HTML-sensitive payload text and line endings follow the final preservation - decisions above. -* Opening and saving a document through the editor does not display or remove - the metadata. - -## Open questions for review - -1. Should delimiters allow surrounding whitespace, or must a delimiter line be - exactly `---`? -2. Should a UTF-8 byte-order mark before the first delimiter be accepted? -3. Must payload preservation include the exact original line-ending - representation? -4. What reversible representation should be used for payload text that could - close the HTML script element? -5. Should multiple YAML elements be an error, or should a deterministic one be - selected? \ No newline at end of file diff --git a/YAML team 2 specification/yaml-spec.md b/YAML team 2 specification/yaml-spec.md new file mode 100644 index 00000000..6c282dbe --- /dev/null +++ b/YAML team 2 specification/yaml-spec.md @@ -0,0 +1,168 @@ +# YAML Front Matter Preservation +================================ + +## Status + +Draft specification. The recognition and preservation rules below are +normative for implementations of this feature. + +## Purpose + +Preserve a YAML metadata block at the beginning of a Markdown document when the +CodeChat Editor converts Markdown to HTML and later converts that HTML back to +Markdown. + +The YAML is opaque text. The editor must not parse, validate, reorder, or +reformat it. + +## Scope + +This specification covers only a YAML block at the beginning of a Markdown +document, delimited by lines containing `---`. In HTML, the block is represented +by a ` +

Hello

+``` + +The precise whitespace around the element may follow the existing HTML +serializer, but it must not become part of the YAML payload. + +## HTML to Markdown + +1. Before converting the HTML document to Markdown, find YAML elements. +2. A matching element is a `script` element whose `type` attribute is exactly + `application/yaml` (case-sensitive, with no surrounding whitespace). + Extra attributes are allowed. The element must be the first HTML element in + the document or fragment; HTML text nodes containing only whitespace before + it do not count. +3. If exactly one matching element is present and it is first, decode it using + `data-codechat-yaml-encoding="base64"` and + `data-codechat-yaml-base64`. Also accept the legacy direct-text + representation from the example for compatibility: its `textContent`, before + HTML parser normalization, is the payload. +4. Multiple matching elements are an error. An implementation must not silently + select or discard one. The editor must report an explicit conversion error. + YAML elements elsewhere than first are not recognized; they are passed to + the normal converter and must not be interpreted as document front matter. +5. Exclude the recognized YAML element from the HTML passed to the normal + HTML-to-Markdown converter. The element must not produce visible Markdown or + be converted as an ordinary script or code block. +6. Prepend a front matter block to the converted Markdown: an opening `---` + line, the extracted payload, and a closing `---` line. +7. If no YAML element is found, convert the HTML as usual. + +The presence of the YAML element must not change how the rest of the document +is converted. + +## Preservation and error cases + +* Preserve payload characters and ordering. In particular, do not normalize + indentation, spaces, comments, blank lines, YAML key ordering, or payload + line terminators. The recognized payload is an exact character sequence, + with LF, CRLF, and CR retained. The delimiter lines reconstructed by + HTML-to-Markdown use LF. +* The HTML representation must be reversible and must not allow `` or + parser-normalized text to change the payload. Implementations must encode + the payload's UTF-8 bytes as Base64 in + `data-codechat-yaml-base64`, and set + `data-codechat-yaml-encoding="base64"`. The element's text content should be + empty. A direct text representation may be emitted only as a legacy + compatibility fallback; it must not be used by a new implementation for + payload text containing a raw `` sequence. +* Do not reject a payload because it is not valid YAML. YAML validation is out + of scope. +* An opening delimiter without a closing delimiter is not a complete block; + leave the document unchanged and render it as ordinary Markdown. +* A closing delimiter is the first later line that exactly matches `---`. + Delimiter lines containing extra spaces are not recognized. +* A payload cannot contain a line exactly equal to `---`: the first such line + closes the block. Supporting YAML document separators inside front matter is + outside this specification. +* A UTF-8 BOM is not accepted as part of front-matter recognition. A BOM + before ordinary content, including before `---`, is ordinary document text + and has no special preservation rule. +* HTML `` sequence are preserved. +* Payload and line terminator round trips cover LF, CRLF, CR, an empty payload, + a payload with no final newline, and a payload with a final newline. +* A BOM, delimiter lines with surrounding whitespace, and an unclosed opening + delimiter follow the specified recognition rules. +* HTML without a YAML element converts as before. +* HTML with a first YAML element is excluded from ordinary Markdown conversion. +* A second YAML element causes an explicit error and is never silently + discarded. +* A YAML element that is not the first HTML element is not recognized as front + matter. +* `type="APPLICATION/YAML"` and `type="application/yaml "` are not matches. +* Opening and saving a document through the real editor HTML serializer/parser + does not display or remove the metadata. \ No newline at end of file From 51ec69a70f2c75f966bc06f12eb554a06742fe67 Mon Sep 17 00:00:00 2001 From: Altynay K Date: Fri, 27 Nov 2026 20:43:56 +0500 Subject: [PATCH 03/12] Added more specification details for the draft --- .../Project 2 submission.md | 139 +++++--- YAML team 2 specification/yaml-spec.md | 330 +++++++++++------- 2 files changed, 311 insertions(+), 158 deletions(-) diff --git a/YAML team 2 specification/Project 2 submission.md b/YAML team 2 specification/Project 2 submission.md index 1f8656b3..28934a65 100644 --- a/YAML team 2 specification/Project 2 submission.md +++ b/YAML team 2 specification/Project 2 submission.md @@ -18,12 +18,15 @@ current git repo." ### Altynay #### Contributions -- Created first draft version. + +* Created first draft version. +* Established strict parsing \& serialization boundaries. +* Completed editor lifecycle \& terminology specifications. #### LLM Review (Copilot / GPT-Luna-6 balanced) ``` -prompt: Please review @attachment:yaml-spec.md and give your feedback +prompt: Audit the provided specification for logical flaws, ambiguities, edge cases, and missing requirements. Output your findings in a file named llm-review.md. ``` The specification clearly identifies the main transformation, uses a focused @@ -33,24 +36,23 @@ affect both Markdown parsing and HTML round-tripping, and the draft leaves them to later implementation. * The Markdown rules should define the exact byte or character model for line - boundaries. In particular, state whether CRLF is retained or normalized, how - a payload with no final newline is reconstructed, and whether the two - delimiter lines have to have matching line terminators. The HTML-to-Markdown - step also needs to account for the newline between a payload and the closing - delimiter so that a round trip does not add or remove characters. + boundaries. In particular, state whether CRLF is retained or normalized, how a + payload with no final newline is reconstructed, and whether the two delimiter + lines have to have matching line terminators. The HTML-to-Markdown step also + needs to account for the newline between a payload and the closing delimiter + so that a round trip does not add or remove characters. * The handling of `` in a payload is underspecified even though the - spec correctly identifies the risk. Entity escaping is not sufficient inside - a script element. The HTML representation must be named and reversible, or - the specification must explicitly exclude that input; an implementation - should not silently split, truncate, or alter the payload. -* The behavior for multiple matching YAML elements is not decided. It should - say whether this is an error or, as a deterministic alternative, which - element is used and whether the others are preserved or discarded. + spec correctly identifies the risk. Entity escaping is not sufficient inside a + script element. The HTML representation must be named and reversible, or the + specification must explicitly exclude that input; an implementation should not + silently split, truncate, or alter the payload. +* The behavior for multiple matching YAML elements is not decided. It should say + whether this is an error or, as a deterministic alternative, which element is + used and whether the others are preserved or discarded. * The exact HTML identification rules are incomplete. Define whether `type` matching is case-sensitive and whitespace-sensitive, and whether extra - attributes are allowed. It should also define whether the element must be - the first HTML element and whether ``, a final newline in the payload, BOM input, delimiter -lines with surrounding whitespace, and editor save/reopen behavior through the -real HTML serializer and parser rather than only through string operations. -These additions would make the acceptance criteria testable and would avoid +The current test list is appropriate, but it should also verify exact byte-level +or character-level round trips, multiple YAML elements, script text containing +``, a final newline in the payload, BOM input, delimiter lines with +surrounding whitespace, and editor save/reopen behavior through the real HTML +serializer and parser rather than only through string operations. These +additions would make the acceptance criteria testable and would avoid differences between implementations. #### Spec review rounds -| Round number | Number of findings | Summary | -| --- | ---: | --- | -| 1 | 6 | Defined exact line-ending and payload boundaries, reversible `` handling, multiple-element behavior, HTML element matching rules, BOM and delimiter edge cases, and the closing-delimiter limitation. | +| Round number | Number of findings | Summary | +| ------------ | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | 6 | Defined exact line-ending and payload boundaries, reversible `` handling, multiple-element behavior, HTML element matching rules, BOM and delimiter edge cases, and the closing-delimiter limitation. | +| 2 | 3 severe / 6 medium / 1 small | Closed the remaining severe ambiguity in YAML element counting and strict Base64/UTF-8 decoding, added legacy text rules, bounded element discovery to document or fragment traversal, specified whitespace/comment/doctype handling, removed exactly the recognized element, and completed editor retention and reconstruction requirements. | +| 3 | 3 severe / 9 medium / 2 small | Clarified payload extraction and DOM traversal boundaries, strict duplicate/Base64/UTF-8 handling, exact HTML serialization and legacy emission mode, template/shadow exclusion, editor retention recovery, mixed line terminators, and the remaining terminology and opacity edge cases. | #### Last LLM review -Lorem ipsum +**High severity** + +1. HTML whitespace is undefined. “Whitespace-only” could mean + HTML ASCII whitespace, JavaScript whitespace, or Unicode whitespace. Define + the exact character set, since it determines whether an element is first. + +2. Duplicate attribute handling is not + implementation-independent. The HTML parser can retain or silently + merge duplicate attributes, and HTML attribute names are case-insensitive + during normalization. Define duplicate detection before normalization, + including ASCII-case rules for `data-codechat-yaml-*`. + +3. Legacy text can lose CR and CRLF terminators. HTML parsing + and serialization may normalize CR or CRLF to LF, making exact legacy + preservation impossible. Restrict legacy compatibility to determinable line + endings or require Base64 for CR/CRLF payloads. + +4. Lone UTF-16 surrogates are unspecified. The rules require + strict UTF-8 but do not say whether Markdown or DOM surrogate code units are + rejected, preserved, or replaced. Replace neither; define explicit rejection + and apply it to Markdown, Base64, and legacy text. + +5. The legacy raw-text prohibition is incomplete. Script end + tags are recognized case-insensitively and may include whitespace or `/`. + Define all forbidden parser end-tag forms and validate legacy text after + parsing, rather than matching only lowercase ``. + +**Medium severity** + +6. Supplied-root traversal is ambiguous. It is unclear whether + an element supplied as the traversal root is itself visited before its + descendants. This changes recognition when that root is a YAML script. Define + root inclusion and pre-order for documents, elements, fragments, templates, + and shadow roots. + +7. Pre-order boundaries need a formal definition. Foreign + namespaces, template content, shadow roots, and nested elements have + interacting rules, but the relative position of a supplied root and its + descendants is not explicit. Define first-element position unambiguously for + every root type. + +8. Non-first-element behavior is contradictory. The text says + such an element is passed to the normal converter and that recognized YAML + elements are excluded. Clarify that exactly one non-first match is neither + decoded nor excluded, and is converted normally. + +9. EOF delimiter semantics are incomplete. It is unclear + whether `---` at EOF can close a block or only an opening delimiter. Define + EOF as an empty terminator and test closing delimiters without a trailing + newline. + +10. Source-file UTF-8 and NUL handling are unspecified. Invalid + or replacement-decoded source bytes, embedded NULs, and overlong sequences + have no rule. Define the accepted text model and explicit error behavior + while keeping the Base64 path strict. + +11. Editor survival lacks measurable copy/paste and sanitization + tests. Opening and saving are insufficient. Test DOM + clones/fragments, copy/paste, undo/redo, external sanitizers, and imports + that remove or strip the YAML element or attributes. + +**Missing acceptance coverage** + +12. Legacy and parser edge cases need tests. Add coverage for + character references and non-ASCII legacy text, all forbidden end-tag forms, + noncanonical line endings, a second match outside the first subtree, + matching supplied element roots, CR/CRLF legacy payloads, and duplicate or + case-variant Base64 attributes. ### Ali - ### Daulet - ### Aiym - - - - --- Final submission @@ -121,18 +186,14 @@ Lorem ipsum #### Last LLM implementation review -Lorem ipsum - - +Lorem ipsum ### Ali - ### Daulet - -### Aiym \ No newline at end of file +### Aiym diff --git a/YAML team 2 specification/yaml-spec.md b/YAML team 2 specification/yaml-spec.md index 6c282dbe..4f5a0a03 100644 --- a/YAML team 2 specification/yaml-spec.md +++ b/YAML team 2 specification/yaml-spec.md @@ -1,64 +1,88 @@ -# YAML Front Matter Preservation -================================ +YAML Front Matter Preservation +============================== -## Status +\================================ -Draft specification. The recognition and preservation rules below are -normative for implementations of this feature. +Status +------ -## Purpose +Draft specification. The rules below are normative for implementations. -Preserve a YAML metadata block at the beginning of a Markdown document when the -CodeChat Editor converts Markdown to HTML and later converts that HTML back to -Markdown. +Purpose +------- -The YAML is opaque text. The editor must not parse, validate, reorder, or -reformat it. +Preserve YAML metadata at the beginning of a Markdown document across Markdown +to HTML and HTML to Markdown conversion. -## Scope +YAML is opaque text: the editor must not parse, validate, reorder, or reformat +it. Opaqueness does not exempt it from this specification's character, UTF-8, +and HTML representation rules. -This specification covers only a YAML block at the beginning of a Markdown -document, delimited by lines containing `---`. In HTML, the block is represented -by a ` + data-codechat-yaml-base64="dGl0bGU6IEV4YW1wbGU=">

Hello

``` -The precise whitespace around the element may follow the existing HTML -serializer, but it must not become part of the YAML payload. - -## HTML to Markdown - -1. Before converting the HTML document to Markdown, find YAML elements. -2. A matching element is a `script` element whose `type` attribute is exactly - `application/yaml` (case-sensitive, with no surrounding whitespace). - Extra attributes are allowed. The element must be the first HTML element in - the document or fragment; HTML text nodes containing only whitespace before - it do not count. -3. If exactly one matching element is present and it is first, decode it using - `data-codechat-yaml-encoding="base64"` and - `data-codechat-yaml-base64`. Also accept the legacy direct-text - representation from the example for compatibility: its `textContent`, before - HTML parser normalization, is the payload. -4. Multiple matching elements are an error. An implementation must not silently - select or discard one. The editor must report an explicit conversion error. - YAML elements elsewhere than first are not recognized; they are passed to - the normal converter and must not be interpreted as document front matter. -5. Exclude the recognized YAML element from the HTML passed to the normal - HTML-to-Markdown converter. The element must not produce visible Markdown or - be converted as an ordinary script or code block. -6. Prepend a front matter block to the converted Markdown: an opening `---` - line, the extracted payload, and a closing `---` line. +Whitespace around the element may follow the existing HTML serializer, but must +not become part of the YAML payload. + +HTML to Markdown +---------------- + +1. Before converting HTML to Markdown, search the document or fragment in + pre-order for matching YAML elements. +2. A matching element is an HTML-namespace `script` element whose `type` + attribute is exactly `application/yaml`, case-sensitive, with no surrounding + whitespace. Extra attributes are allowed. Exclude elements inside + `