@@ -307,3 +307,119 @@ func mkLang(name string, code string) *Lang {
307307 code : code ,
308308 }
309309}
310+
311+ const tmplMarkdown = `# Customizing SumatraPDF %VER%
312+
313+ You can change the look and behavior of
314+ [SumatraPDF](https://www.sumatrapdfreader.org/)
315+ by editing the file ` + "`SumatraPDF-settings.txt`" + `. The file is stored in
316+ ` + "`%LOCALAPPDATA%\\ SumatraPDF`" + ` directory for the installed version or in the
317+ same directory as ` + "`SumatraPDF.exe`" + ` executable for the portable version.
318+
319+ Use the menu item ` + "`Settings -> Advanced Settings...`" + ` to open the settings file
320+ with your default text editor.
321+
322+ The file is in a simple text format. Below is an explanation of
323+ what the different settings mean and what their default values are.
324+
325+ Highlighted settings can't be changed from the UI. Modifying other settings
326+ directly in this file is not recommended.
327+
328+ If you add or remove lines with square brackets, **make sure to always add/remove
329+ square brackets in pairs**! Else you risk losing all the data following them.
330+
331+ ` + "```" + `
332+ %INSIDE%
333+ ` + "```" + `
334+
335+ ## Syntax for color values
336+
337+ The syntax for colors is: ` + "`#rrggbb`" + `.
338+
339+ The components are hex values (ranging from 00 to FF) and stand for:
340+ - ` + "`rr`" + ` : red component
341+ - ` + "`gg`" + ` : green component
342+ - ` + "`bb`" + ` : blue component
343+
344+ For example #ff0000 means red color. You can use [Sphere](https://galactic.ink/sphere/) to pick a color.
345+ `
346+
347+ func genCommentMarkdown (comment string , first bool ) string {
348+ lineLen := 80
349+ s := "\n "
350+ if first {
351+ s = ""
352+ }
353+ s = s + "; "
354+ left := lineLen - 2
355+ // [foo](bar.html) is converted to foo (bar.html) in plain text
356+ hrefText := ""
357+ words := strings .Split (comment , " " )
358+ for _ , word := range words {
359+ if word [0 ] == '[' {
360+ wordURL := extractURL (word [1 :])
361+ if len (wordURL ) == 2 {
362+ s += fmt .Sprintf ("%s (%s)" , wordURL [0 ], wordURL [1 ])
363+ continue
364+ }
365+ hrefText = wordURL [0 ]
366+ continue
367+ } else if hrefText != "" {
368+ wordURL := extractURL (word )
369+ hrefText = hrefText + " " + wordURL [0 ]
370+ if len (wordURL ) == 2 {
371+ s += fmt .Sprintf ("%s (%s) " , hrefText , wordURL [1 ])
372+ hrefText = ""
373+ }
374+ continue
375+ }
376+ if left < len (word ) {
377+ s = rstrip (s ) + "\n ; "
378+ left = lineLen - 2
379+ }
380+ word += " "
381+ left -= len (word )
382+ s += word
383+ }
384+ s = rstrip (s )
385+ return s
386+ }
387+
388+ func genStructMarkdown (struc * Field , indent string ) string {
389+ var lines []string
390+ first := true
391+
392+ fields := struc .Default .([]* Field )
393+ for _ , field := range fields {
394+ if field .Internal || field .isComment () {
395+ continue
396+ }
397+ comment := field .DocComment
398+ if field .Version != "2.3" {
399+ comment += fmt .Sprintf (" (introduced in version %s)" , field .Version )
400+ }
401+
402+ s := genCommentMarkdown (comment , first )
403+ lines = append (lines , s )
404+
405+ switch field .Type .Name {
406+ case "Array" :
407+ indent2 := indent + indentStr [:len (indentStr )/ 2 ]
408+ start := fmt .Sprintf ("%s%s [\n %s[" , indent , field .Name , indent2 )
409+ end := fmt .Sprintf ("%s]\n %s]" , indent2 , indent )
410+ inside := genStructMarkdown (field , indent + indentStr )
411+ lines = append (lines , start , inside , end )
412+ case "Struct" :
413+ start := fmt .Sprintf ("%s%s [" , indent , field .Name )
414+ end := fmt .Sprintf ("%s]" , indent )
415+ inside := genStructMarkdown (field , indent + indentStr )
416+ lines = append (lines , start , inside , end )
417+ default :
418+ s = field .initDefault ()
419+ s = lstrip (s )
420+ lines = append (lines , indent + s )
421+ }
422+ first = false
423+ }
424+ return strings .Join (lines , "\n " )
425+ }
0 commit comments