From 887cc681a5220ab9d70eaa4190d80e02b1d03b45 Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Sun, 8 Nov 2026 11:41:19 +0300 Subject: [PATCH] docs(openspec): archive add-keep-code change --- .../2026-11-08-add-keep-code}/.openspec.yaml | 0 .../2026-11-08-add-keep-code}/design.md | 0 .../2026-11-08-add-keep-code}/proposal.md | 0 .../specs/toc-heading-markup/spec.md | 0 .../specs/toc-keep-code/spec.md | 0 .../2026-11-08-add-keep-code}/tasks.md | 0 openspec/specs/toc-heading-markup/spec.md | 3 +- openspec/specs/toc-keep-code/spec.md | 138 ++++++++++++++++++ 8 files changed, 140 insertions(+), 1 deletion(-) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/.openspec.yaml (100%) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/design.md (100%) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/proposal.md (100%) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/specs/toc-heading-markup/spec.md (100%) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/specs/toc-keep-code/spec.md (100%) rename openspec/changes/{add-keep-code => archive/2026-11-08-add-keep-code}/tasks.md (100%) create mode 100644 openspec/specs/toc-keep-code/spec.md diff --git a/openspec/changes/add-keep-code/.openspec.yaml b/openspec/changes/archive/2026-11-08-add-keep-code/.openspec.yaml similarity index 100% rename from openspec/changes/add-keep-code/.openspec.yaml rename to openspec/changes/archive/2026-11-08-add-keep-code/.openspec.yaml diff --git a/openspec/changes/add-keep-code/design.md b/openspec/changes/archive/2026-11-08-add-keep-code/design.md similarity index 100% rename from openspec/changes/add-keep-code/design.md rename to openspec/changes/archive/2026-11-08-add-keep-code/design.md diff --git a/openspec/changes/add-keep-code/proposal.md b/openspec/changes/archive/2026-11-08-add-keep-code/proposal.md similarity index 100% rename from openspec/changes/add-keep-code/proposal.md rename to openspec/changes/archive/2026-11-08-add-keep-code/proposal.md diff --git a/openspec/changes/add-keep-code/specs/toc-heading-markup/spec.md b/openspec/changes/archive/2026-11-08-add-keep-code/specs/toc-heading-markup/spec.md similarity index 100% rename from openspec/changes/add-keep-code/specs/toc-heading-markup/spec.md rename to openspec/changes/archive/2026-11-08-add-keep-code/specs/toc-heading-markup/spec.md diff --git a/openspec/changes/add-keep-code/specs/toc-keep-code/spec.md b/openspec/changes/archive/2026-11-08-add-keep-code/specs/toc-keep-code/spec.md similarity index 100% rename from openspec/changes/add-keep-code/specs/toc-keep-code/spec.md rename to openspec/changes/archive/2026-11-08-add-keep-code/specs/toc-keep-code/spec.md diff --git a/openspec/changes/add-keep-code/tasks.md b/openspec/changes/archive/2026-11-08-add-keep-code/tasks.md similarity index 100% rename from openspec/changes/add-keep-code/tasks.md rename to openspec/changes/archive/2026-11-08-add-keep-code/tasks.md diff --git a/openspec/specs/toc-heading-markup/spec.md b/openspec/specs/toc-heading-markup/spec.md index 33909dd..6d800f4 100644 --- a/openspec/specs/toc-heading-markup/spec.md +++ b/openspec/specs/toc-heading-markup/spec.md @@ -34,7 +34,8 @@ HTML tags removed. The text inside link, image, formatting and inline HTML eleme GitHub renders them (`&`, `<`), and the spaces around a removed element SHALL stay as they are. Entries of headings without HTML tags SHALL NOT change. This SHALL apply to every input: stdin, a local file, a remote URL, several inputs, `--insert` and -`--stdout`. +`--stdout`. With `--keep-code`, the inline code of the heading SHALL be written as in +`toc-keep-code`, and the rest of the text SHALL follow this requirement. #### Scenario: Escaped characters are not tags diff --git a/openspec/specs/toc-keep-code/spec.md b/openspec/specs/toc-keep-code/spec.md new file mode 100644 index 0000000..cd871ad --- /dev/null +++ b/openspec/specs/toc-keep-code/spec.md @@ -0,0 +1,138 @@ +# toc-keep-code Specification + +## Purpose + +Lets the TOC entry of a heading with inline code keep that code in backticks, so the +entry shows the code as the heading does and linters that compare them pass. + +## Requirements + +### Requirement: Inline code in backticks + +With `--keep-code`, every inline code element of the heading text, as GitHub renders it, +SHALL be written into the TOC entry as a markdown code span with the same content: + +- `<`, `>` and `&` inside the code SHALL be written as `<`, `>` and `&`; +- the code SHALL be enclosed in a run of backticks one longer than the longest run of + backticks inside the code; +- when the code starts or ends with a space or a backtick and is not only spaces, one + space SHALL be added on each side, between the backticks and the code. + +The text outside the inline code SHALL be the same as without `--keep-code`, as in +`toc-heading-markup`: tags removed and HTML entities as GitHub renders them. The link of +the entry SHALL be the same as without `--keep-code`. + +#### Scenario: Headings with inline code + +- **WHEN** the user runs `gh-md-toc --keep-code "tests/test directory/test_keepcode.md"`, + where the file has these headings, separated by empty lines: + + ```` + # `Headline` + ## The command `foo1` is better + ## `a&c` + ## `` a`b `` + ## `` `a` `` + ## ``` a``b ``` + ## `< ©` + ## ` spaced ` + ## x ` ` y + ## `**kwargs**` + ## Tom & `Jerry` <3 + ## A *em `code`* and [`link`](#headline) + ```` + +- **THEN** the TOC entries are these lines, followed by + ``: + + ```` + * [`Headline`](#headline) + * [The command `foo1` is better](#the-command-foo1-is-better) + * [`a&c`](#abc) + * [``a`b``](#ab) + * [`` `a` ``](#a) + * [```a``b```](#ab-1) + * [`< ©`](#lt-copy) + * [` spaced `](#--spaced--) + * [x ` ` y](#x---y) + * [`**kwargs**`](#kwargs) + * [Tom & `Jerry` <3](#tom--jerry-3) + * [A em `code` and `link`](#a-em-code-and-link) + ```` + +### Requirement: Every input + +`--keep-code` SHALL apply to every input: stdin, a local file, a remote URL, several +inputs, `--insert` and `--stdout`. + +`--keep-code` SHALL be accepted after `--indent `, `--depth `, +`--numbered ` and `--bullet ` (when given) and before `-`, `--insert`, +`--no-backup`, `--hide-footer`, `--skip-no-markers`, `--stdout`, `--skip-header` and the +inputs. + +#### Scenario: Stdin with a bullet + +- **WHEN** the user runs + `cat "tests/test directory/test_backquote.md" | gh-md-toc --bullet - --keep-code -` +- **THEN** the output is these lines: + + ```` + - [The command `foo1`](#the-command-foo1) + - [The command `foo2` is better](#the-command-foo2-is-better) + - [The command `bar1`](#the-command-bar1) + - [The command `bar2` is better](#the-command-bar2-is-better) + - [The command `bar3` is the best](#the-command-bar3-is-the-best) + ```` + +#### Scenario: Remote URL + +- **WHEN** the user runs + `gh-md-toc --keep-code https://github.com/ekalinin/github-markdown-toc/blob/a28f86dcb616ce17103d1dfc28f6c3ac423c388c/tests/test%20directory/test_backquote.md` +- **THEN** the TOC entries are the lines of the scenario "Stdin with a bullet" with `*` + instead of `-`, and the exit code is 0 + +#### Scenario: Whole file to stdout + +- **WHEN** the user runs `gh-md-toc --keep-code --hide-footer --stdout /a.md`, where + `a.md` is ``\n\n\n# The command `foo1`\n`` +- **THEN** stdout is + ``\n* [The command `foo1`](#the-command-foo1)\n\n\n# The command `foo1`\n``, + `a.md` does not change, and the exit code is 0 + +### Requirement: Without the option + +Without `--keep-code`, the TOC entries SHALL be the same as before this change: the +inline code is written without backticks, as in `toc-heading-markup`. + +#### Scenario: Headings with inline code without the option + +- **WHEN** the user runs `gh-md-toc "tests/test directory/test_keepcode.md"` +- **THEN** the TOC entries are these lines, followed by + ``: + + ```` + * [Headline](#headline) + * [The command foo1 is better](#the-command-foo1-is-better) + * [a<b>&c](#abc) + * [a`b](#ab) + * [`a`](#a) + * [a``b](#ab-1) + * [&lt; &copy;](#lt-copy) + * [ spaced ](#--spaced--) + * [x y](#x---y) + * [**kwargs**](#kwargs) + * [Tom & Jerry <3](#tom--jerry-3) + * [A em code and link](#a-em-code-and-link) + ```` + +### Requirement: Help lists the option + +`--help` SHALL list `--keep-code` in the "Options" section right after +`--bullet `. + +#### Scenario: Help output + +- **WHEN** the user runs `gh-md-toc --help` +- **THEN** the line after + ` --bullet Bullet of TOC entries: *, - or +. Default: *.` + is ` --keep-code Keep inline code of headings in backticks. Default: false.`