Skip to content

[Repo Assist] Add (*** include-toc ***) directive for inline table of contents in literate F# scripts#1058

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-issue-163-include-toc-eac5d5e355b2e64c
Draft

[Repo Assist] Add (*** include-toc ***) directive for inline table of contents in literate F# scripts#1058
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-issue-163-include-toc-eac5d5e355b2e64c

Conversation

@github-actions
Copy link
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #163

Summary

Implements the long-requested in-page table of contents directive for literate F# scripts (.fsx files).

Usage

In any literate .fsx file, place one of these commands where you want the TOC to appear:

(*** include-toc ***)        (* list all headings up to depth 3 (default) *)
(*** include-toc:2 ***)      (* list only H1 and H2 headings *)
(*** include-toc:1 ***)      (* list only H1 headings *)

The directive generates an unordered list of hyperlinks pointing to the heading anchors in the rendered HTML. It requires generateAnchors = true (the default in fsdocs build).

Example

(**
# My Document

(*** include-toc:2 ***)

## Section One

Some content.

## Section Two

More content.
*)

Renders the TOC as links to #Section-One and #Section-Two.

Implementation

  • Document.fs: New TableOfContents of maxDepth: int * paragraphOptions: LiterateParagraphOptions case on LiterateParagraph.
  • ParseScript.fs: Handles (*** include-toc ***) and (*** include-toc:N ***) commands in transformBlocks, defaulting depth to 3.
  • Transformations.fs: New generateTableOfContents function that collects all Heading nodes, computes anchor names using the same algorithm as HtmlFormatting.formatAnchor (including UniqueNameGenerator simulation for duplicate headings), and replaces each TableOfContents paragraph with a ListBlock of DirectLink spans.
  • Formatting.fs: generateTableOfContents is called as the first step in transformDocument, before replaceLiterateParagraphs.

Test Status

  • Build: ✅ succeeded (0 warnings, 0 errors)
  • Tests: ✅ 116/116 passed (FSharp.Literate.Tests)

Generated by Repo Assist for issue #163

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70

…iterate F# scripts

Implements issue #163. Adds a new LiterateParagraph case TableOfContents and
a new transformation generateTableOfContents that replaces it with a ListBlock
of DirectLink elements pointing to all heading anchors in the document.

Usage in .fsx literate scripts:
  (*** include-toc ***)       - list all headings up to depth 3
  (*** include-toc:2 ***)     - list headings up to depth 2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Would be nice to be able to auto generate a toc inside a page

0 participants