diff --git a/pkg/proto/writer_markdown.go b/pkg/proto/writer_markdown.go
index 5891484..f10927a 100644
--- a/pkg/proto/writer_markdown.go
+++ b/pkg/proto/writer_markdown.go
@@ -58,7 +58,11 @@ func EnumToMarkdown(enum *Enum, wc *WriterConfig) (body string, diagram string)
if wc.visualize {
diagram = "\n" + ToMermaid(enum.Name, enum)
}
- body = fmt.Sprintf("## Enum: %s\n%s\n\n%s\n\n%s\n\n", enum.Name, fmt.Sprintf(fqn, enum.Qualifier), enum.Comment.ToMarkdownBlockQuote(), enumTable.String())
+ if wc.pureMarkdown {
+ body = fmt.Sprintf("## Enum: %s\n%s\n\n%s\n\n%s\n\n", enum.Name, fmt.Sprintf(fqnPureMd, enum.Qualifier), enum.Comment.ToMarkdownText(), enumTable.String())
+ } else {
+ body = fmt.Sprintf("## Enum: %s\n%s\n\n%s\n\n%s\n\n", enum.Name, fmt.Sprintf(fqn, enum.Qualifier), enum.Comment.ToMarkdownBlockQuote(), enumTable.String())
+ }
return body, diagram
}
@@ -87,8 +91,11 @@ func MessageToMarkdown(message *Message, wc *WriterConfig) (body string, diagram
diagram = "\n" + ToMermaid(message.Name, message)
}
- body = fmt.Sprintf("## Message: %s\n%s\n\n%s\n\n%s\n\n", message.Name, fmt.Sprintf(fqn, message.Qualifier), message.Comment.ToMarkdownBlockQuote(), attributeTable.String())
-
+ if wc.pureMarkdown {
+ body = fmt.Sprintf("## Message: %s\n%s\n\n%s\n\n%s\n\n", message.Name, fmt.Sprintf(fqnPureMd, message.Qualifier), message.Comment.ToMarkdownText(), attributeTable.String())
+ } else {
+ body = fmt.Sprintf("## Message: %s\n%s\n\n%s\n\n%s\n\n", message.Name, fmt.Sprintf(fqn, message.Qualifier), message.Comment.ToMarkdownBlockQuote(), attributeTable.String())
+ }
for _, e := range message.Enums {
eBody, eDiagram := EnumToMarkdown(e, wc)
body += eBody
@@ -122,6 +129,9 @@ func ServiceToMarkdown(s *Service, wc *WriterConfig) string {
table = ToMermaid(s.Name, s) + "\n\n" + table
}
+ if wc.pureMarkdown {
+ return fmt.Sprintf("## Service: %s\n%s\n\n%s\n\n%s\n\n", s.Name, fmt.Sprintf(fqnPureMd, s.Qualifier), s.Comment.ToMarkdownText(), table)
+ }
return fmt.Sprintf("## Service: %s\n%s\n\n%s\n\n%s\n\n", s.Name, fmt.Sprintf(fqn, s.Qualifier), s.Comment.ToMarkdownBlockQuote(), table)
}
@@ -175,6 +185,8 @@ func PackageFormatOptions(p *Package) (body string) {
const fqn = "
FQN: %s
"
+const fqnPureMd = "* **FQN**: %s"
+
const footer = `
`
@@ -188,6 +200,10 @@ func PackageToMarkDown(p *Package, wc *WriterConfig) string {
}
out += HandleEnums(p.Enums, wc)
out += HandleMessages(p.Messages, wc)
- out = fmt.Sprintf("# Package: %s\n\n%s\n\n%s\n\n%s\n\n%s\n%s\n", p.Name, p.Comment.ToMarkdownBlockQuote(), PackageFormatImports(p), PackageFormatOptions(p), out, footer)
+ if wc.pureMarkdown {
+ out = fmt.Sprintf("# Package: %s\n\n%s\n\n%s\n\n%s\n\n%s\n%s\n", p.Name, p.Comment.ToMarkdownText(), PackageFormatImports(p), PackageFormatOptions(p), out, footer)
+ } else {
+ out = fmt.Sprintf("# Package: %s\n\n%s\n\n%s\n\n%s\n\n%s\n%s\n", p.Name, p.Comment.ToMarkdownBlockQuote(), PackageFormatImports(p), PackageFormatOptions(p), out, footer)
+ }
return out
}
diff --git a/pkg/proto/writer_markdown_test.go b/pkg/proto/writer_markdown_test.go
index cb5cf62..c2118f5 100644
--- a/pkg/proto/writer_markdown_test.go
+++ b/pkg/proto/writer_markdown_test.go
@@ -59,6 +59,34 @@ func TestEnumToMarkdown(t *testing.T) {
| T_02 | 1 | |
+`, wantDiagram: ``},
+ {name: "Enum Markdown", args: args{
+ enum: &Enum{
+ Qualified: &Qualified{
+ Qualifier: "test.TestEnum",
+ Name: "TestEnum",
+ Comment: "Keen Enum",
+ },
+ Values: []*EnumValue{
+ NewEnumValue("test.TestEnum", "0", "T_01", ""),
+ NewEnumValue("test.TestEnum", "1", "T_02", ""),
+ },
+ },
+ wc: &WriterConfig{
+ visualize: false,
+ pureMarkdown: true,
+ },
+ }, wantBody: `## Enum: TestEnum
+* **FQN**: test.TestEnum
+
+Keen Enum
+
+| Name | Ordinal | Description |
+|------|---------|-------------|
+| T_01 | 0 | |
+| T_02 | 1 | |
+
+
`, wantDiagram: ``},
}
for _, tt := range tests {
@@ -122,6 +150,30 @@ func TestHandleEnums(t *testing.T) {
| T1 | 0 | |
+`},
+ {name: "Enums", args: args{
+ enums: []*Enum{{
+ Qualified: &Qualified{
+ Qualifier: "test.Service",
+ Name: "TestEnum",
+ Comment: "",
+ },
+ Values: []*EnumValue{NewEnumValue("test.Service.TestEnum", "0", "T1", "")},
+ }},
+ wc: &WriterConfig{
+ visualize: false,
+ pureMarkdown: true,
+ },
+ }, wantBody: `## Enum: TestEnum
+* **FQN**: test.Service
+
+
+
+| Name | Ordinal | Description |
+|------|---------|-------------|
+| T1 | 0 | |
+
+
`},
}
for _, tt := range tests {
@@ -177,6 +229,44 @@ func TestHandleMessages(t *testing.T) {
| Name | 1 | string | | |
+`},
+ {name: "Handle Message", args: args{
+ messages: []*Message{&Message{
+ Qualified: &Qualified{
+ Qualifier: "test.Service.Message",
+ Name: "Message",
+ Comment: "",
+ },
+ Attributes: []*Attribute{{
+ Qualified: &Qualified{
+ Qualifier: "test.Service.Message.Name",
+ Name: "Name",
+ Comment: "",
+ },
+ Repeated: false,
+ Map: false,
+ Kind: []string{"string"},
+ Ordinal: 1,
+ Annotations: []*Annotation{},
+ }},
+ Messages: []*Message{},
+ Enums: []*Enum{},
+ Reserved: []*Reserved{},
+ }},
+ wc: &WriterConfig{
+ visualize: false,
+ pureMarkdown: true,
+ },
+ }, wantBody: `## Message: Message
+* **FQN**: test.Service.Message
+
+
+
+| Field | Ordinal | Type | Label | Description |
+|-------|---------|--------|-------|-------------|
+| Name | 1 | string | | |
+
+
`},
}
for _, tt := range tests {
@@ -233,6 +323,44 @@ func TestMessageToMarkdown(t *testing.T) {
| Name | 1 | string | | |
+`, wantDiagram: "\n### Message Diagram\n\n```mermaid\nclassDiagram\ndirection LR\n\n%% \n\nclass Message {\n + string Name\n}\n\n```"},
+ {name: "Handle Message", args: args{
+ message: &Message{
+ Qualified: &Qualified{
+ Qualifier: "test.Service.Message",
+ Name: "Message",
+ Comment: "",
+ },
+ Attributes: []*Attribute{{
+ Qualified: &Qualified{
+ Qualifier: "test.Service.Message.Name",
+ Name: "Name",
+ Comment: "",
+ },
+ Repeated: false,
+ Map: false,
+ Kind: []string{"string"},
+ Ordinal: 1,
+ Annotations: []*Annotation{},
+ }},
+ Messages: []*Message{},
+ Enums: []*Enum{},
+ Reserved: []*Reserved{},
+ },
+ wc: &WriterConfig{
+ visualize: true,
+ pureMarkdown: true,
+ },
+ }, wantBody: `## Message: Message
+* **FQN**: test.Service.Message
+
+
+
+| Field | Ordinal | Type | Label | Description |
+|-------|---------|--------|-------|-------------|
+| Name | 1 | string | | |
+
+
`, wantDiagram: "\n### Message Diagram\n\n```mermaid\nclassDiagram\ndirection LR\n\n%% \n\nclass Message {\n + string Name\n}\n\n```"},
}
for _, tt := range tests {
@@ -355,6 +483,43 @@ func TestPackageToMarkDown(t *testing.T) {
+
+
+`},
+ {name: "Package", args: args{
+ p: &Package{
+ Path: "test/location/model.proto",
+ Name: "test.package",
+ Comment: "",
+ Options: []*Option{},
+ Imports: []*Import{},
+ Messages: []*Message{},
+ Enums: []*Enum{},
+ Services: []*Service{},
+ },
+ wc: &WriterConfig{
+ pureMarkdown: true,
+ },
+ }, want: `# Package: test.package
+
+
+
+## Imports
+
+| Import | Description |
+|--------|-------------|
+
+
+
+## Options
+
+| Name | Value | Description |
+|------|-------|-------------|
+
+
+
+
+
`},
@@ -392,6 +557,25 @@ func TestServiceToMarkdown(t *testing.T) {
|--------|----------------|-----------------|-------------|
+`},
+ {name: "Service", args: args{s: &Service{
+ Qualified: &Qualified{
+ Qualifier: "test.Service",
+ Name: "Service",
+ Comment: "",
+ },
+ Methods: []*Rpc{},
+ }, wc: &WriterConfig{
+ pureMarkdown: true,
+ }}, want: `## Service: Service
+* **FQN**: test.Service
+
+
+
+| Method | Parameter (In) | Parameter (Out) | Description |
+|--------|----------------|-----------------|-------------|
+
+
`},
}
for _, tt := range tests {