Skip to content

Commit d5e1d08

Browse files
committed
add settings documentation to Advanced-options-settings.md
1 parent 0031e48 commit d5e1d08

File tree

4 files changed

+1421
-911
lines changed

4 files changed

+1421
-911
lines changed

do/settings_gen_code.go

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -409,13 +409,13 @@ enum class DisplayMode {
409409
ContinuousBookView,
410410
};
411411
412-
constexpr float kZoomFitPage = -1.f;
413-
constexpr float kZoomFitWidth = -2.f;
414-
constexpr float kZoomFitContent = -3.f;
415-
constexpr float kZoomActualSize = 100.0f;
416-
constexpr float kZoomMax = 6400.f; /* max zoom in % */
417-
constexpr float kZoomMin = 8.33f; /* min zoom in % */
418-
constexpr float kInvalidZoom = -99.0f;
412+
constexpr float kZoomFitPage = -1.F;
413+
constexpr float kZoomFitWidth = -2.F;
414+
constexpr float kZoomFitContent = -3.F;
415+
constexpr float kZoomActualSize = 100.0F;
416+
constexpr float kZoomMax = 6400.F; /* max zoom in % */
417+
constexpr float kZoomMin = 8.33F; /* min zoom in % */
418+
constexpr float kInvalidZoom = -99.0F;
419419
420420
{{structDef}}
421421
@@ -440,8 +440,8 @@ func genSettingsStruct() string {
440440
}
441441

442442
content := settingsStructsHeader
443-
content = strings.Replace(content, "{{structDef}}", structDef, -1)
444-
content = strings.Replace(content, "{{structMetadata}}", structMetaData, -1)
443+
content = strings.ReplaceAll(content, "{{structDef}}", structDef)
444+
content = strings.ReplaceAll(content, "{{structMetadata}}", structMetaData)
445445

446446
return content
447447
}
@@ -472,7 +472,7 @@ func genAndSaveSettingsStructs() {
472472
websiteSettingsDir := filepath.Join(websiteDir, "settings")
473473
ver := extractSumatraVersionMust()
474474
// this we do to work-around a bug in Cloudflare Pages that doesn't support '.' in file name
475-
verUrlized := strings.Replace(ver, ".", "-", -1)
475+
verUrlized := strings.ReplaceAll(ver, ".", "-")
476476

477477
settingsFileName := fmt.Sprintf("settings%s.html", verUrlized)
478478
langsFileName := fmt.Sprintf("langs%s.html", verUrlized)
@@ -496,8 +496,8 @@ func genAndSaveSettingsStructs() {
496496
*/
497497

498498
//fmt.Printf("%s\n", s)
499-
s = strings.Replace(s, "\n", "\r\n", -1)
500-
s = strings.Replace(s, "\t", " ", -1)
499+
// s = strings.ReplaceAll(s, "\n", "\r\n")
500+
s = strings.ReplaceAll(s, "\t", " ")
501501
path := filepath.Join("src", "Settings.h")
502502
writeFileMust(path, []byte(s))
503503
detectClangFormat()
@@ -518,14 +518,13 @@ func genAndSaveSettingsStructs() {
518518
lines = append(lines, s)
519519
}
520520
inside := strings.Join(lines, "\n")
521-
s := strings.Replace(tmplLangsHTML, "%INSIDE%", inside, -1)
521+
s := strings.ReplaceAll(tmplLangsHTML, "%INSIDE%", inside)
522522
ver := extractSumatraVersionMust()
523-
verUrlized := strings.Replace(ver, ".", "-", -1)
524-
s = strings.Replace(s, "%VER%", ver, -1)
525-
s = strings.Replace(s, "%VER_URL%", verUrlized, -1)
526-
s = strings.Replace(s, "settings.html", settingsFileName, -1)
527-
s = strings.Replace(s, "\n", "\r\n", -1)
528-
// undo html escaping that differs from Python
523+
verUrlized := strings.ReplaceAll(ver, ".", "-")
524+
s = strings.ReplaceAll(s, "%VER%", ver)
525+
s = strings.ReplaceAll(s, "%VER_URL%", verUrlized)
526+
s = strings.ReplaceAll(s, "settings.html", settingsFileName)
527+
s = strings.ReplaceAll(s, "\n", "\r\n") // undo html escaping that differs from Python
529528
// TODO: possibly remove
530529
//s = strings.Replace(s, "'", "'", -1)
531530

@@ -536,10 +535,10 @@ func genAndSaveSettingsStructs() {
536535
genSettingsHTML := func() {
537536
prefs := globalPrefsStruct
538537
inside := genStruct(prefs, "")
539-
s := strings.Replace(tmplHTML, "%INSIDE%", inside, -1)
540-
s = strings.Replace(s, "%VER%", extractSumatraVersionMust(), -1)
541-
s = strings.Replace(s, "langs.html", langsFileName, -1)
542-
s = strings.Replace(s, "\n", "\r\n", -1)
538+
s := strings.ReplaceAll(tmplHTML, "%INSIDE%", inside)
539+
s = strings.ReplaceAll(s, "%VER%", extractSumatraVersionMust())
540+
s = strings.ReplaceAll(s, "langs.html", langsFileName)
541+
// s = strings.ReplaceAll(s, "\n", "\r\n")
543542
// undo html escaping that differs from Python
544543
// TODO: possibly remove
545544
//s = strings.Replace(s, "'", "'", -1)
@@ -552,14 +551,19 @@ func genAndSaveSettingsStructs() {
552551
genSettingsMarkdown := func() {
553552
prefs := globalPrefsStruct
554553
inside := genStructMarkdown(prefs, "")
555-
s := strings.Replace(tmplMarkdown, "%INSIDE%", inside, -1)
556-
s = strings.Replace(s, "%VER%", extractSumatraVersionMust(), -1)
557-
s = strings.Replace(s, "\n", "\r\n", -1)
558-
559-
mdFileName := fmt.Sprintf("settings%s.md", verUrlized)
560-
path := filepath.Join(websiteSettingsDir, mdFileName)
561-
writeFileMust(path, []byte(s))
562-
fmt.Printf("Wrote '%s'\n", path)
554+
s := strings.ReplaceAll(tmplMarkdown, "%INSIDE%", inside)
555+
556+
// Append to docs/md/Advanced-options-settings.md after "# Settings" line
557+
mdPath := filepath.Join("docs", "md", "Advanced-options-settings.md")
558+
existing := string(readFileMust(mdPath))
559+
marker := "# Settings"
560+
idx := strings.Index(existing, marker)
561+
panicIf(idx == -1, "marker '%s' not found in '%s'", marker, mdPath)
562+
// Keep everything up to and including "# Settings\n"
563+
prefix := existing[:idx+len(marker)] + "\n\n"
564+
result := prefix + s
565+
writeFileMust(mdPath, []byte(result))
566+
fmt.Printf("Wrote '%s'\n", mdPath)
563567
}
564568

565569
genSettingsHTML()

do/settings_gen_html.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,9 @@ func mkLang(name string, code string) *Lang {
308308
}
309309
}
310310

311-
const tmplMarkdown = `# Customizing SumatraPDF %VER%
311+
const tmplMarkdown = `Below is an explanation of what the different settings mean and what their default values are.
312312
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.
313+
If you add or remove lines with square brackets, **make sure to always add/remove square brackets in pairs**! Else you risk losing all the data following them.
330314
331315
` + "```" + `
332316
%INSIDE%
@@ -341,7 +325,7 @@ The components are hex values (ranging from 00 to FF) and stand for:
341325
- ` + "`gg`" + ` : green component
342326
- ` + "`bb`" + ` : blue component
343327
344-
For example #ff0000 means red color. You can use [Sphere](https://galactic.ink/sphere/) to pick a color.
328+
For example #ff0000 means red color.
345329
`
346330

347331
func genCommentMarkdown(comment string, first bool) string {
@@ -354,8 +338,8 @@ func genCommentMarkdown(comment string, first bool) string {
354338
left := lineLen - 2
355339
// [foo](bar.html) is converted to foo (bar.html) in plain text
356340
hrefText := ""
357-
words := strings.Split(comment, " ")
358-
for _, word := range words {
341+
words := strings.SplitSeq(comment, " ")
342+
for word := range words {
359343
if word[0] == '[' {
360344
wordURL := extractURL(word[1:])
361345
if len(wordURL) == 2 {

0 commit comments

Comments
 (0)