From 066f3e33b7838e3e6fad740ab97265e280f78619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=B7=E5=B0=8F=E5=B9=BF?= Date: Sun, 30 Jun 2019 17:20:06 -0400 Subject: [PATCH] Archive: GenSvgImg function from Token.wl. (cherry picked from commit d5e411ac1cbc5ddbe222c3579c136c1162f96ae2) --- WolframLanguageServer/Archives.wl | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 WolframLanguageServer/Archives.wl diff --git a/WolframLanguageServer/Archives.wl b/WolframLanguageServer/Archives.wl new file mode 100644 index 0000000..bfa6595 --- /dev/null +++ b/WolframLanguageServer/Archives.wl @@ -0,0 +1,51 @@ +(* ::Package:: *) +(*Archives*) + +(* Wolfram Language Server Archived Functions *) +(* Author: kenkangxgwe , + huxianglong +*) + + +BeginPackage["WolframLanguageServer`Archives`"] +ClearAll[Evaluate[Context[] <> "*"]] + + +Begin["`Private`"] +ClearAll[Evaluate[Context[] <> "*"]] + + +(* ::Section:: *) +(*GenSvgImg*) + + +Options[GenSvgImg] := { + "Theme" -> "dark", + "TempDir" -> $TemporaryDirectory +} + + +GenSvgImg[token_String, width_Integer, o:OptionsPattern[]] := Module[ + { + tempImgPath, background, theme, tempDir + }, + + {theme, tempImgPath} = OptionValue[GenSvgImg, {o}, {"Theme", "TempDir"}]; + background = If[theme === "light", Black, White]; + tempImgPath = FileNameJoin[{tempDir, CreateUUID[] <> ".svg"}]; + (* Export[tempImgPath, Style[#, background]& @* (#::usage&) @ Symbol[token]]; *) + Export[tempImgPath, + Style[ + Pane[StringReplace[#, StartOfLine -> "\[FilledSmallCircle] "], .85*width, Alignment -> Left], FontSize -> 13, background + ]& @ ToExpression[token <> "::usage"] + ]; + (* "![" <> "test" <> "](" <> tempImgPath <> ")" <> "\n" <> "```" <> StringRepeat[StringJoin[CharacterRange["a", "z"]], 4] <> "```" *) + "![" <> "test" <> "](" <> tempImgPath <> ")" <> "\n\n" <> "```typescript" <> StringRepeat[StringRepeat["\t", 50] <> "\n", 20] <> "```" <> "\n\n" + (* "![" <> ToString[(#::usage&) @ Symbol[token]] <> "](" <> tempImgPath <> ")" *) +] + + +End[] + + +EndPackage[] \ No newline at end of file