Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/FSharp.Formatting.CodeFormat/CommentFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// F# CodeFormat (CommentProcessing.fs)
// (c) Tomas Petricek, 2012, Available under Apache 2.0 license.
// --------------------------------------------------------------------------------------
/// Internal module for pre-processing F# source snippets: extracting named snippet regions
/// (<c>// [snippet:Name]</c> / <c>// [/snippet]</c>), shrinking omitted blocks
/// (<c>(*[omit:...]*)..(*[/omit]*)</c>), and surfacing FSI output markers (<c>// [fsi:...]</c>).
module internal FSharp.Formatting.CodeFormat.CommentFilter

open System.Text
Expand Down
3 changes: 3 additions & 0 deletions src/FSharp.Formatting.CodeFormat/LatexFormatting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// (c) Tomas Petricek, 2012, Available under Apache 2.0 license.
// --------------------------------------------------------------------------------------

/// Internal module for rendering F# code snippets as LaTeX using the lstlistings environment.
module internal FSharp.Formatting.CodeFormat.Latex

open System
Expand All @@ -28,6 +29,8 @@ let specialChars =
"~", @"{\textasciitilde}"
"^", @"{\textasciicircum}" |]

/// Escape a string for safe inclusion in LaTeX source,
/// substituting all LaTeX special characters with their command equivalents.
let latexEncode s =
specialChars
|> Array.fold (fun (acc: string) (k, v) -> acc.Replace(k, v)) (HttpUtility.HtmlDecode s)
Expand Down
2 changes: 2 additions & 0 deletions src/FSharp.Formatting.CodeFormat/SourceCode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ type SourceError =
/// error kind and the message
| SourceError of start: (int * int) * finish: (int * int) * errorKind: ErrorKind * message: string

/// Internal helpers for mapping TokenKind values to CSS class names.
module internal CodeFormatHelper =

/// Map a TokenKind to the corresponding CSS class name string using the default CSS class map.
let defaultTokenMap kind =
match kind with
| TokenKind.Comment -> CSS.Comment
Expand Down
4 changes: 4 additions & 0 deletions src/FSharp.Formatting.Literate/ParseScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module internal CodeBlockUtils =
| _ -> false)
|> List.ofSeq

/// Split a string into lines, normalising line endings.
let splitLines (s: string) =
s.Replace("\r\n", "\n").Split([| '\n' |])

Expand Down Expand Up @@ -149,15 +150,18 @@ open CodeBlockUtils
/// as hide, define and include.
type internal ParseScript(parseOptions, ctx: CompilerContext) =

/// Determine the visibility of a code block based on its commands dictionary.
let getVisibility cmds =
match cmds with
| Command "hide" _ -> LiterateCodeVisibility.HiddenCode
| Command "define" name -> LiterateCodeVisibility.NamedCode name
| _ -> LiterateCodeVisibility.VisibleCode

/// Return true if a code block should be evaluated, based on global noEval flag and block commands.
let getEvaluate noEval (cmds: IDictionary<_, _>) =
not (noEval || cmds.ContainsKey("do-not-eval"))

/// Extract paragraph options (conditional defines) from block commands.
let getParaOptions cmds =
match cmds with
| Command "condition" name when not (String.IsNullOrWhiteSpace name) -> { Condition = Some name }
Expand Down
6 changes: 5 additions & 1 deletion src/FSharp.Formatting.Literate/Transformations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ open FSharp.Formatting.CodeFormat
open FSharp.Formatting.Literate.Evaluation
open FSharp.Formatting.Markdown

/// Internal transformations applied to a LiterateDocument:
/// formatting F# code snippets, evaluating them with FSI, resolving references,
/// and replacing literate paragraphs with their final HTML/LaTeX/Fsx representations.
module internal Transformations =
// ----------------------------------------------------------------------------------------------
// Replace all code snippets (assume F#) with their nicely formatted versions
Expand Down Expand Up @@ -460,7 +463,8 @@ module internal Transformations =
| _ -> () ]


/// Replace all special 'LiterateParagraph' elements recursively using the given lookup dictionary
/// Format a non-F# language-tagged code block as an HTML table with optional line numbers,
/// using the CSharpFormat syntax highlighter for the given language.
let replaceHtmlTaggedCode (ctx: LiterateProcessingContext) (lang: string) (code: string) =
let sb = new System.Text.StringBuilder()
let writer = new System.IO.StringWriter(sb)
Expand Down