Skip to content

Commit

Permalink
Add syntax in html format (#6)
Browse files Browse the repository at this point in the history
* Add syntax in html format

* Update version
  • Loading branch information
arpith-f5 authored Aug 31, 2023
1 parent ff25e44 commit ebe73d8
Show file tree
Hide file tree
Showing 10 changed files with 3,369 additions and 839 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Thumbs.db
.DS_Store
.vscode
.idea

# Logs #
########
Expand Down
6 changes: 4 additions & 2 deletions reference-converter/internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type Directive struct {
Name string `json:"name"`
Default string `json:"default"`
Contexts []string `json:"contexts"`
Syntax []string `json:"syntax"`
SyntaxMd []string `json:"syntax_md"`
SyntaxHtml []string `json:"syntax_html"`
IsBlock bool `json:"isBlock"`
DescriptionMd string `json:"description_md"`
DescriptionHtml string `json:"description_html"`
Expand All @@ -37,7 +38,8 @@ func toModule(m *parse.Module) Module {
Name: directive.Name,
Default: directive.Default,
Contexts: directive.Contexts,
Syntax: directive.Syntax.ToMarkdown(),
SyntaxMd: directive.Syntax.ToMarkdown(),
SyntaxHtml: directive.Syntax.ToHTML(),
IsBlock: directive.Syntax.IsBlock(),
DescriptionMd: directive.Prose.ToMarkdown(),
DescriptionHtml: directive.Prose.ToHTML(),
Expand Down
6 changes: 4 additions & 2 deletions reference-converter/internal/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestNew(t *testing.T) {
Name: "directive 2",
Default: "default 2",
Contexts: []string{"context 1", "context 2"},
Syntax: []string{"syntax 1", "syntax 2"},
SyntaxMd: []string{"syntax 1", "syntax 2"},
SyntaxHtml: []string{"<p>syntax 1</p>\n", "<p>syntax 2</p>\n"},
DescriptionMd: "Test",
DescriptionHtml: "<p>Test</p>\n",
},
Expand All @@ -66,7 +67,8 @@ func TestWrite(t *testing.T) {
Name: "Directive 1",
Default: "Default",
Contexts: []string{"Context 1", "Context 2"},
Syntax: []string{"I am Syntax"},
SyntaxMd: []string{"I am Syntax"},
SyntaxHtml: []string{"<p>I am Syntax</p>"},
DescriptionMd: "It is a directive",
DescriptionHtml: "<p>It is a directive</p>",
},
Expand Down
13 changes: 13 additions & 0 deletions reference-converter/internal/parse/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ func (ss Syntaxes) ToMarkdown() []string {
return ret
}

func (ss Syntaxes) ToHTML() []string {
if len(ss) == 0 {
return nil
}

ret := make([]string, 0, len(ss))
for _, s := range ss {
md := []byte(s.ToMarkdown())
ret = append(ret, string(mdToHTML(md)))
}
return ret
}

func (ss Syntaxes) IsBlock() bool {
isBlock := false
for _, s := range ss {
Expand Down
2 changes: 1 addition & 1 deletion reference-lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getDirectives(format=Format.HTML): Directive[] {
name: d.name,
module: d.module,
description: format === Format.HTML ? d.description_html : d.description_md,
syntax: d.syntax,
syntax: format === Format.HTML ? d.syntax_html : d.syntax_md,
contexts: d.contexts,
isBlock: d.isBlock,
default: d.default
Expand Down
4 changes: 2 additions & 2 deletions reference-lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion reference-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nginxinc/reference-lib",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion reference-lib/src/__mocks__/reference_mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
"location",
"limit_except"
],
"syntax": [
"syntax_md": [
"*`address`* | *`CIDR`* | `unix:` | `all`"
],
"syntax_html": [
"<p><em><code>address</code></em> | <em><code>CIDR</code></em> | <code>unix:</code> | <code>all</code></p>\n"
],
"isBlock": false,
"description_md": "Allows access for the specified network or address.",
"description_html": "\u003cp\u003eAllows access for the specified network or address\u003c/p\u003e"
Expand Down
4,165 changes: 3,337 additions & 828 deletions reference-lib/src/reference.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions reference-lib/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Directive Helper', () => {
const expected = [{ name: directive?.name,
module: module?.name,
description: directive?.description_html,
syntax: directive?.syntax,
syntax: directive?.syntax_html,
contexts: directive?.contexts,
isBlock: directive?.isBlock,
default: directive?.default,
Expand All @@ -50,7 +50,7 @@ describe('Directive Helper', () => {
const expected = [{ name: directive?.name,
module: module?.name,
description: directive?.description_md,
syntax: directive?.syntax,
syntax: directive?.syntax_md,
contexts: directive?.contexts,
isBlock: directive?.isBlock,
default: directive?.default,
Expand Down

0 comments on commit ebe73d8

Please sign in to comment.