Skip to content

Commit

Permalink
Archive: GenSvgImg function from Token.wl.
Browse files Browse the repository at this point in the history
(cherry picked from commit d5e411ac1cbc5ddbe222c3579c136c1162f96ae2)
  • Loading branch information
kenkangxgwe committed Jun 30, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2c36473 commit 066f3e3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions WolframLanguageServer/Archives.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(* ::Package:: *)
(*Archives*)

(* Wolfram Language Server Archived Functions *)
(* Author: kenkangxgwe <kenkangxgwe_at_gmail.com>,
huxianglong <hxianglong_at_gmail.com>
*)


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[]

0 comments on commit 066f3e3

Please sign in to comment.