Repository navigation
feat(toc): add --keep-code to keep inline code in backticks - #202
Merged
Merged
Conversation
This was referenced Nov 8, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #153: an option to keep the inline code of the headings in backticks in the TOC.
Today the
<code>tags of a heading are removed (since the fix of #13), so the TOC entryhas the code without backticks:
# `Headline`gives* [Headline](#headline). Alinter that compares the entries with the headings fails on that, and the code is read
as markdown in the TOC:
## `**kwargs**`gives* [**kwargs**](#kwargs), renderedas a bold "kwargs".
--keep-codewrites every inline code element as a code span with the same content:<,>and&inside the code are decoded: in a code span they are shownas is. The entities outside the code stay as before.
backtick and is not only spaces, so the spaces at the edges are kept (CommonMark
strips one from each side).
The issue proposes the name
--no-code-tag-removal.--keep-codeis used instead: itsays what the user gets, the option also decodes the entities and picks the backticks,
and the longer name does not fit the option column of
--help.Changes:
gh-md-toc:gh_toc_grab: a new parameter$7. With it, thesedstep that removes<code>isskipped, and a loop in
common_awk_script(shared by the default and OS/390branches) builds the code spans. The tags are removed only from the text around the
code, otherwise the decoded
a<b>&cwould lose<b>. Without the option, the loopdoes not run and the
sedstep runs as before.gh_toc_app:--keep-codeis parsed right after--bullet, before-, so it workswith stdin. It is passed to
gh_toc(12th parameter),gh_toc_stdout(8th) and tothe stdin call of
gh_toc_grab.--help: a new line right after--bullet.README.md: a sentence and an example after the--bulletexample, without a newheading, so the README TOC asserted in the tests does not change.
tests/tests.bats: a new fixturetests/test directory/test_keepcode.md(12headings, 13 code spans), 5 tests (a local file with and without the option, stdin
with
--bullet -, a remote URL pinned to a commit,--stdout),test_helpupdated.openspec: theadd-keep-codechange (proposal, design, specs, tasks), not archivedyet. It adds the
toc-keep-codespec and updates "Plain text of the heading" intoc-heading-markupto point to it.Without
--keep-code, the output does not change.Not included: keeping the backticks by default, other markup back to markdown
(
*em*,**strong**), headings missing from the TOC when GitHub puts a line break afterthe heading tag (#201), a version bump.
Testing
without the option passes, it pins down the output that does not change. All 76 tests
pass with the change (macOS, BSD awk 20200816).
--keep-code, rendered by the markdownAPI, have the same
<code>content as the headings, for all 13 code spans;--keep-code --insertgives the same file as the output of--keep-code --stdout;awk of the Debian Docker image) and GNU awk 5.2.1 as on macOS.
make lintpasses.