diff --git a/doc/md_docs.go b/doc/md_docs.go
index d76f6d5e..932da407 100644
--- a/doc/md_docs.go
+++ b/doc/md_docs.go
@@ -51,11 +51,21 @@ func GenMarkdown(cmd *cobra.Command, w io.Writer) error {
 }
 
 // GenMarkdownCustom creates custom markdown output.
-func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {
+func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) (err error) {
 	cmd.InitDefaultHelpCmd()
 	cmd.InitDefaultHelpFlag()
 
 	buf := new(bytes.Buffer)
+	defer func() {
+		if err != nil {
+			return
+		}
+		if !cmd.DisableAutoGenTag {
+			buf.WriteString("###### Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "\n")
+		}
+		_, err = buf.WriteTo(w)
+	}()
+
 	name := cmd.CommandPath()
 
 	short := cmd.Short
@@ -64,6 +74,11 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
 		long = short
 	}
 
+	if cmd.IsAdditionalHelpTopicCommand() {
+		buf.WriteString(long + "\n\n")
+		return nil
+	}
+
 	buf.WriteString("## " + name + "\n\n")
 	buf.WriteString(short + "\n\n")
 	buf.WriteString("### Synopsis\n\n")
@@ -100,7 +115,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
 		sort.Sort(byName(children))
 
 		for _, child := range children {
-			if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
+			if !child.IsAvailableCommand() && !child.IsAdditionalHelpTopicCommand() {
 				continue
 			}
 			cname := name + " " + child.Name()
@@ -110,11 +125,8 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
 		}
 		buf.WriteString("\n")
 	}
-	if !cmd.DisableAutoGenTag {
-		buf.WriteString("###### Auto generated by spf13/cobra on " + time.Now().Format("2-Jan-2006") + "\n")
-	}
-	_, err := buf.WriteTo(w)
-	return err
+
+	return nil
 }
 
 // GenMarkdownTree will generate a markdown page for this command and all
@@ -133,7 +145,7 @@ func GenMarkdownTree(cmd *cobra.Command, dir string) error {
 // with custom filePrepender and linkHandler.
 func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {
 	for _, c := range cmd.Commands() {
-		if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
+		if !c.IsAvailableCommand() && !c.IsAdditionalHelpTopicCommand() {
 			continue
 		}
 		if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {