[Repo Assist] Add (*** include-toc ***) directive for inline table of contents in literate F# scripts#1058
Conversation
…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>
|
/repo-assist add tests and documentation for this, and show us an example by replying in a comment here |
…nb/ToFsx paths - Add 5 NUnit tests covering parsing, HTML output, depth filtering, and duplicate anchor handling for (*** include-toc ***) and (*** include-toc:N ***) - Fix bug: generateTableOfContents was only called in the transformDocument path (Formatting.fs) but not in the direct Literate.ToHtml, WriteHtml, ToLatex, WriteLatex, ToPynb, ToFsx methods in Literate.fs - Add documentation in docs/literate.fsx explaining the directive, usage syntax, and correct placement as a standalone command Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
|
🤖 This is an automated response from Repo Assist. Done! I've pushed a commit that adds tests and documentation. Here's a summary of what was added — and a bug fix I found along the way. ExampleThe (**
# My Document
*)
(*** include-toc:2 ***)
(**
## Section One
Some content here.
## Section Two
More content here.
*)This renders an unordered list of links at the position of Use What was added5 new tests in
All 121 tests pass. Documentation added to Bug fixI found that
|
|
@dsyme devil's advocate but do we still needs this since we got the sidebar? Example https://fsprojects.github.io/FSharp.Formatting/apidocs.html
|

🤖 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 (
.fsxfiles).Usage
In any literate
.fsxfile, place one of these commands where you want the TOC to appear:The directive generates an unordered list of hyperlinks pointing to the heading anchors in the rendered HTML. It requires
generateAnchors = true(the default infsdocs build).Example
Renders the TOC as links to
#Section-Oneand#Section-Two.Implementation
Document.fs: NewTableOfContents of maxDepth: int * paragraphOptions: LiterateParagraphOptionscase onLiterateParagraph.ParseScript.fs: Handles(*** include-toc ***)and(*** include-toc:N ***)commands intransformBlocks, defaulting depth to 3.Transformations.fs: NewgenerateTableOfContentsfunction that collects allHeadingnodes, computes anchor names using the same algorithm asHtmlFormatting.formatAnchor(includingUniqueNameGeneratorsimulation for duplicate headings), and replaces eachTableOfContentsparagraph with aListBlockofDirectLinkspans.Formatting.fs:generateTableOfContentsis called as the first step intransformDocument, beforereplaceLiterateParagraphs.Test Status
FSharp.Literate.Tests)