diff --git a/gen/stdlib-generator.go b/gen/stdlib-generator.go index 9830627..6f78584 100644 --- a/gen/stdlib-generator.go +++ b/gen/stdlib-generator.go @@ -3,7 +3,6 @@ package main import ( "bytes" "fmt" - "html" "io/fs" "os" "path/filepath" @@ -18,24 +17,12 @@ import ( var nameMap = map[string]map[string]string{ "DE": { - "params": "Parameter", - "paramType": "Parameter Typ", - "returnType": "Rückgabe Typ", - "aliases": "Aliase", - "impl": "Implementation", - "externImpl": "Implementiert in", "type": "Typ", "var": "Variablen", "func": "Funktionen", "moduleEmpty": "Dieses Modul ist Leer", }, "EN": { - "params": "Parameters", - "paramType": "Parameter type", - "returnType": "Return type", - "aliases": "Aliases", - "impl": "Implementation", - "externImpl": "Implemented in", "type": "Type", "var": "variables", "func": "functions", @@ -128,74 +115,54 @@ func MakeMdFiles(inputFilePath, outputFilePath, lang string) { case *ast.FuncDecl: hasFuncs = true - fmt.Fprintln(funcBldr, "
") - // Funktionsname - fmt.Fprintf(funcBldr, "

%s

\n", decl.Name()) - - fmt.Fprintln(funcBldr, "") - - // Aliases - fmt.Fprintf(funcBldr, "\n

%s

\n
    \n", nameMap[lang]["aliases"]) - for _, alias := range decl.Aliases { - fmt.Fprintf(funcBldr, "\t
  1. %s
  2. \n", html.EscapeString(alias.Original.Literal)) + aliases := "" + for i, alias := range decl.Aliases { + aliases += strings.Trim(alias.Original.Literal, "\"\n") + if i+1 < len(decl.Aliases) { + aliases += "\\\"" + } } - fmt.Fprintln(funcBldr, "
") - // Implemetation - fmt.Fprintf(funcBldr, "\n

%s

\n", nameMap[lang]["impl"]) + impl := "" + isExtern := ast.IsExternFunc(decl) if ast.IsExternFunc(decl) { - fmt.Fprintf(funcBldr, "%s %s\n", nameMap[lang]["externImpl"], decl.ExternFile.String()) + impl = strings.Trim(decl.ExternFile.String(), "\"") } else { - fmt.Fprintln(funcBldr, "
\n")
-
-				inputStr := strings.Split(string(inputFile), "\n")
+				file := strings.Trim(string(inputFile), "\r\n")
+				inputStr := strings.Split(file, "\n")
 				lines := inputStr[decl.Body.Range.Start.Line:decl.Body.Range.End.Line]
-				for _, line := range lines {
-					fmt.Fprintln(funcBldr, strings.Replace(line, "\t", "", 1))
-				}
 
-				fmt.Fprintln(funcBldr, "\n\n
") + impl = strings.Join(lines, "
") + impl = strings.ReplaceAll(impl, "\r", "") + impl = strings.ReplaceAll(impl, "\n", "
") + impl = strings.ReplaceAll(impl, "\"", "\\\"") + impl = strings.ReplaceAll(impl, "\t", " ") } - fmt.Fprint(funcBldr, "
\n\n") + fmt.Fprintf(funcBldr, "{{< duden-function name=\"%s\" desc=\"%s\" params=\"%s\" paramTypes=\"%s\" ret=\"%s\" impl=\"%s\" extern=\"%t\" aliases=\"%s\" >}}\n\n", // }}" + decl.Name(), descr, params, paramTypes, decl.Type.String(), impl, isExtern, aliases) case *ast.VarDecl: hasVars = true diff --git a/i18n/de.toml b/i18n/de.toml index 5e797e5..0f8dfc3 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -1,4 +1,11 @@ toc = "Inhaltsverzeichnis" prev = "Vorherige Seite" next = "Nächste Seite" -desc = "Die Dokumentation der Deutschen Programmiersprache." \ No newline at end of file +desc = "Die Dokumentation der Deutschen Programmiersprache." +params = "Parameter" +paramType = "Parameter Typ" +returnType = "Rückgabe Typ" +aliases = "Aliase" +impl = "Implementation" +externImpl = "Implementiert in" +type = "Typ" diff --git a/i18n/en.toml b/i18n/en.toml index 1a5b85c..0f7949d 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -1,4 +1,11 @@ toc = "Table of Contents" prev = "Previous Page" next = "Next Page" -desc = "The documentation for DDP." \ No newline at end of file +desc = "The documentation for DDP." +params = "Parameters" +paramType = "Parameter type" +returnType = "Return type" +aliases = "Aliases" +impl = "Implementation" +externImpl = "Implemented in" +type = "Type" \ No newline at end of file diff --git a/layouts/shortcodes/duden-function.html b/layouts/shortcodes/duden-function.html new file mode 100644 index 0000000..c1ca256 --- /dev/null +++ b/layouts/shortcodes/duden-function.html @@ -0,0 +1,41 @@ +
+

{{ .Get "name" }}

+ {{ with .Get "desc" }} +
{{ . | plainify }}
+ {{ end }} + + +

{{ i18n "aliases" }}

+
    + {{ with .Get "aliases" }} + {{ $aliases := split . "\"" }} + {{ range $aliases}} +
  1. {{ . }}
  2. + {{ end }} + {{ else}} +

    Keine Aliase definiert

    + {{ end}} +
+ +

{{ i18n "impl" }}

+ {{ if eq (.Get "extern") "false" }} +
{{ replace (.Get "impl" | plainify) " " "    " }}
+ {{ else }} +

{{ i18n "externImpl" }} {{ .Get "impl" }}

+ {{ end }} + +
\ No newline at end of file