From 74a72ae0a273ff05a487dfc0a92f141a88225c53 Mon Sep 17 00:00:00 2001 From: debbie <148627186+webdevred@users.noreply.github.com> Date: Wed, 9 Jul 2025 20:58:32 +0200 Subject: [PATCH 1/2] Show LaTeX math expressions in haddockToMarkdown - Replace fallback messages with raw LaTeX math expressions using $...$ and $$...$$. - This lets editors display the original math content even if they don't render LaTeX. - No sanitization is performed, raw LaTeX is output as-is. --- ghcide/src/Development/IDE/Spans/Common.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index f3e86d792d..07a5a5d8d8 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -190,11 +190,10 @@ haddockToMarkdown (H.DocOrderedList things) = haddockToMarkdown (H.DocDefList things) = '\n' : (unlines $ map (\(term, defn) -> "+ **" ++ haddockToMarkdown term ++ "**: " ++ haddockToMarkdown defn) things) --- we cannot render math by default -haddockToMarkdown (H.DocMathInline _) - = "*cannot render inline math formula*" -haddockToMarkdown (H.DocMathDisplay _) - = "\n\n*cannot render display math formula*\n\n" +haddockToMarkdown (H.DocMathInline s) + = "$" ++ s ++ "$" +haddockToMarkdown (H.DocMathDisplay s) + = "\n$$\n" ++ s ++ "\n$$\n" -- TODO: render tables haddockToMarkdown (H.DocTable _t) From 82c802306e7b607fd2fde2a8a22d0dfde4e1ed73 Mon Sep 17 00:00:00 2001 From: webdevred <148627186+webdevred@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:37:16 +0200 Subject: [PATCH 2/2] Do backticks for inline math and fenced latex blocks for math blocks --- ghcide/src/Development/IDE/Spans/Common.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index 07a5a5d8d8..996e55ef1a 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -191,9 +191,9 @@ haddockToMarkdown (H.DocDefList things) = '\n' : (unlines $ map (\(term, defn) -> "+ **" ++ haddockToMarkdown term ++ "**: " ++ haddockToMarkdown defn) things) haddockToMarkdown (H.DocMathInline s) - = "$" ++ s ++ "$" + = "`" ++ s ++ "`" haddockToMarkdown (H.DocMathDisplay s) - = "\n$$\n" ++ s ++ "\n$$\n" + = "\n```latex\n" ++ s ++ "\n```\n" -- TODO: render tables haddockToMarkdown (H.DocTable _t)