FSharp.Formatting

repository·main·Indexed 19 days ago

https://github.com/fsprojects/fsharp.formatting

A set of tools and libraries for processing F# scripts and Markdown, specifically tailored for documentation generation. It includes the fsdocs command-line tool for generating API documentation, supporting features such as literate F# script evaluation, polyglot notebook processing, and LaTeX rendering via MathJax.

Tokens
9.1K
Snippets
37
Records
48
Agent score
61%

What's inside FSharp.Formatting

  1. Use FSharp.Formatting as a library

    main

    FSharp.Formatting is available on NuGet as a set of libraries for programmatic access to its core features. You can use it for:

    • Markdown processing: Use the built-in F# Markdown parser to process and manipulate markdown documents.
    • F# code formatting: Use the F# code formatter to analyze or format F# source files and extract information from them.
  2. Levels of customization in fsdocs

    main

    When using fsdocs, you can customize your documentation at six different levels of complexity:

    1. No customization: Simply write content. This is the easiest to maintain.
    2. Content customization: Add files like docs/index.md for a custom front page or docs/reference/Namespace.md to provide bespoke landing pages for specific namespaces (overriding generated content).
    3. Styling Parameters: Use project file properties to set basic visual elements.
    4. CSS: Override styles using a custom CSS file.
    5. New Templates: Create custom HTML templates for the site structure.
    6. Custom Site Generation: Use the FSharp.Formatting.ApiDocs API to generate a site using your own code.
  3. Requirements for generating API documentation

    main

    When running fsdocs, the tool automatically searches for projects/solutions in the working directory. To be included in the API documentation, a project must meet these criteria:

    • <OutputType> must be library.
    • The project must be built (a binary must exist).
    • <IsTestProject> must not be true.
    • <GenerateDocumentationFile> must be true.

    If you change these settings and the documentation doesn't update, try removing the .fsdocs/cache file.

  4. Transform Markdown with embedded F# using literate.fsx

    main

    You can write Markdown documents containing embedded F# snippets and transform them into formatted HTML using the literate.fsx script provided by the FSharp.Formatting package. The document remains valid Markdown and supports standard features like unordered lists, bold, and emphasis.

    # Example: Using Markdown Content
    
    This file demonstrates how to write Markdown document with 
    embedded F# snippets that can be transformed into nice HTML 
    using the `literate.fsx` script from the [F# Formatting
    package](http://fsprojects.github.io/FSharp.Formatting).
  5. Generate and preview documentation with dotnet fsdocs watch

    main

    Use the watch command to generate documentation and start a local web server. This is ideal for development as it handles the root path correctly for local HTTP serving.

    Run the command: dotnet fsdocs watch

    By default, the server is available at http://localhost:8901.

    dotnet fsdocs watch
  6. Install and use the fsdocs tool

    main

    To generate documentation for an F# project that includes project files, markdown, and script content (typically located in a docs directory), use the fsdocs command-line tool.

    Follow these steps to install and run the tool:

    1. Install the tool globally using dotnet tool install fsdocs-tool.
    2. Build the documentation using dotnet fsdocs build.
    3. Use dotnet fsdocs watch to monitor changes and rebuild automatically.
    dotnet tool install fsdocs-tool
    dotnet fsdocs build 
    dotnet fsdocs watch
  7. Use inline and block LaTeX in Markdown

    main

    The Markdown extensions support two modes for LaTeX:

    1. Inline LaTeX: Enclose the LaTeX code with single $ delimiters (e.g., $ code $). You can also use $$ for inline mode.
    2. Block LaTeX: Start a new paragraph and mark the first line with $$$ (do not include a closing $$$).

    LaTeX Escape Rules

    When using inline mode, you must escape certain characters to prevent them from being interpreted as delimiters:

    • Escape $ using $ \$ $ or $ \$var $.
    • Other characters that may require escaping depending on your MathJax configuration include: &, %, $, #, _, {, and }.
    • For comparison operators, use standard syntax like x > 1, y < 1, x >= 1, or x <= 1.
    $ k_{n+1} = n^2 + k_n^2 - k_{n-1} $
    
    $$$
    A_{m,n} = 
     \begin{pmatrix}
      a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
      a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
      \vdots  & \vdots  & \ddots & \vdots  \\
      a_{m,1} & a_{m,2} & \cdots & a_{m,n}
     \end{pmatrix}
  8. Build static documentation for production

    main

    Use dotnet fsdocs build to generate static files for a production environment (like GitHub Pages).

    Local Preview Tip: If <PackageProjectUrl> is not set, opening the output files directly in a browser via file:// will result in broken links. To preview the build locally without a web server, pass a relative root:

    dotnet fsdocs build --parameters root ./

    dotnet fsdocs build --parameters root ./