Skip to content

Fix nested comment parsing in literate scripts and add AddHtmlPrinter tests#1138

Merged
dsyme merged 2 commits intomainfrom
fix-nested-comment-parsing-and-add-tests
Apr 2, 2026
Merged

Fix nested comment parsing in literate scripts and add AddHtmlPrinter tests#1138
dsyme merged 2 commits intomainfrom
fix-nested-comment-parsing-and-add-tests

Conversation

@dsyme
Copy link
Copy Markdown
Contributor

@dsyme dsyme commented Apr 2, 2026

Problem

The literate script comment parser in ParseScript.fs used LastIndexOf("*)") to detect where (** comment blocks end. This incorrectly matched *) inside nested (*** command ***) markers that appeared in markdown text — for example, backtick-quoted references like `(*** include-it ***)` or `(*** include-it-raw ***)`.

This caused a rendering bug in docs/evaluation.fsx: the section starting with "A common use-case is embedding chart or plot images..." was silently dropped from the generated HTML because the *) inside `(*** include-it-raw ***)` prematurely closed the surrounding (** block.

Fix

Replaced the naive LastIndexOf("*)") with a nesting-aware scanner (findOuterCommentEnd) that properly tracks (* ... *) depth, only matching *) at depth 0.

Tests added

  • Comment blocks containing nested (*** ***) markers are not truncated
  • AddHtmlPrinter with include-it-raw
  • AddHtmlPrinter with CSS/JS resources
  • AddHtmlPrinter with base64 image pattern (as documented in evaluation.fsx)
  • AddPrintTransformer chained with AddHtmlPrinter and include-it-raw

Other fixes

  • Added missing [<Test>] attribute on Can include-output-and-it test (was never executed by the test runner)

dsyme added 2 commits April 2, 2026 18:37
… tests

- Fix ParseScript.fs: the comment block parser used LastIndexOf("*)")
  to detect comment endings, which incorrectly matched nested
  (*** command ***) markers inside markdown text (e.g. backtick-quoted
  examples of include-it or include-it-raw). This caused content after
  such references to be silently dropped from HTML output. Replaced
  with a nesting-aware scanner (findOuterCommentEnd) that properly
  tracks (* ... *) depth.

- Add integration tests for:
  - Comment blocks containing nested (*** ***) markers
  - AddHtmlPrinter with include-it-raw
  - AddHtmlPrinter with CSS/JS resources
  - AddHtmlPrinter with base64 image pattern (as documented)
  - AddPrintTransformer chained with AddHtmlPrinter and include-it-raw

- Fix missing [<Test>] attribute on Can include-output-and-it test
@dsyme dsyme merged commit 014c199 into main Apr 2, 2026
4 checks passed
@dsyme dsyme deleted the fix-nested-comment-parsing-and-add-tests branch April 2, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant