")
- // Funktionsname
- fmt.Fprintf(funcBldr, "%s
\n", decl.Name())
-
- fmt.Fprintln(funcBldr, "")
- // Kommentar/Beschreibung
+ descr := ""
if decl.Comment() != nil {
- descr := strings.Replace(strings.Trim(decl.Comment().String(), "[] \r\n"), "\t", "", -1)
- fmt.Fprintf(funcBldr, "
\n%s\n
\n", descr)
+ descr = strings.Replace(strings.Trim(decl.Comment().String(), "[] \r\n"), "\t", "", -1)
+ descr = strings.ReplaceAll(descr, "\r", "")
+ descr = strings.ReplaceAll(descr, "\n", "
")
+ descr = strings.ReplaceAll(descr, "\"", "\\\"")
}
+ params := ""
+ paramTypes := ""
if len(decl.ParamNames) > 0 {
- // Parameter Names
- fmt.Fprintf(funcBldr, "\t%s: ", nameMap[lang]["params"])
- for i, paramName := range decl.ParamNames {
- fmt.Fprintf(funcBldr, "%s
", paramName.String())
- if i < len(decl.ParamNames)-1 {
- fmt.Fprintf(funcBldr, ", ")
- }
- }
-
- // Parameter Types
- fmt.Fprintf(funcBldr, "\n\t%s", nameMap[lang]["paramType"])
- if len(decl.ParamNames) > 1 {
- if lang == "DE" {
- fmt.Fprintf(funcBldr, "en")
- } else if lang == "EN" {
- fmt.Fprintf(funcBldr, "s")
- }
+ names := make([]string, 0, len(decl.ParamNames))
+ types := make([]string, 0, len(decl.ParamTypes))
+ for i := range decl.ParamNames {
+ names = append(names, decl.ParamNames[i].String())
+ types = append(types, decl.ParamTypes[i].String())
}
- fmt.Fprintf(funcBldr, ": ")
- for i, paramTypes := range decl.ParamTypes {
- fmt.Fprintf(funcBldr, "%s
", paramTypes)
- if i < len(decl.ParamTypes)-1 {
- fmt.Fprintf(funcBldr, ", ")
- }
- }
+ params = strings.Join(names, ",")
+ paramTypes = strings.Join(types, ",")
}
- // Rückgabe Typ
- fmt.Fprintf(funcBldr, "\n\t%s: %s
\n", nameMap[lang]["returnType"], decl.Type)
- fmt.Fprintln(funcBldr, "")
-
- // Aliases
- fmt.Fprintf(funcBldr, "\n%s
\n\n", nameMap[lang]["aliases"])
- for _, alias := range decl.Aliases {
- fmt.Fprintf(funcBldr, "\t%s
\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 @@
+