Commit c3fa7e8c authored by Ma_124's avatar Ma_124

added OFFHtml

parent f035125d
......@@ -59,7 +59,7 @@ For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issu
`[1:]
Compile(strings.NewReader(in), len(in), out, IFFMarkdown, OFFTabSep, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, awesomeAwesomeShortOut, out.String()))
assert.Equal(t, awesomeAwesomeShortOut, out.String())
}
func TestCompileFile_TmpFile(t *testing.T) {
......
......@@ -31,7 +31,7 @@ func TestCompile_TabSepTabSep(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFTabSep, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
assert.Equal(t, `
'# Awesome
" Awesome
"
......@@ -46,14 +46,14 @@ awesome-shell https://github.com/alebcay/awesome-shell Command-line frameworks,
awesome-sysadmin https://github.com/kahun/awesome-sysadmin Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more.
"
"For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:], out.String()))
`[1:], out.String())
}
func TestCompile_TabSepSimpleMarkdown(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFSimpleMarkdown, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
assert.Equal(t, `
# Awesome Awesome
A curated list of awesome curated lists of many topics.
......@@ -70,14 +70,14 @@ A curated list of awesome curated lists of many topics.
| [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:], out.String()))
`[1:], out.String())
}
func TestCompile_TabSepMarkdown(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFMarkdown, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, `
assert.Equal(t, `
# Awesome Awesome
A curated list of awesome curated lists of many topics.
......@@ -94,14 +94,14 @@ A curated list of awesome curated lists of many topics.
| 7654 | 32 | 1 | 2019-01-20 | [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:], out.String()))
`[1:], out.String())
}
func TestCompile_TabSepSimpleMarkdownHtml(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFSimpleMarkdownHtml, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, string(blackfriday.Run([]byte(`
assert.Equal(t, string(blackfriday.Run([]byte(`
# Awesome Awesome
A curated list of awesome curated lists of many topics.
......@@ -118,14 +118,14 @@ A curated list of awesome curated lists of many topics.
| [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]))), out.String()))
`[1:]))), out.String())
}
func TestCompile_TabSepMarkdownHtml(t *testing.T) {
out := &strings.Builder{}
Compile(strings.NewReader(awesomeAwesomeShortInp), len(awesomeAwesomeShortInp), out, IFFTabSep, OFFMarkdownHtml, &ApisCfg{&ApiCfg{}})
t.Log(assert.Equal(t, string(blackfriday.Run([]byte(`
assert.Equal(t, string(blackfriday.Run([]byte(`
# Awesome Awesome
A curated list of awesome curated lists of many topics.
......@@ -142,5 +142,47 @@ A curated list of awesome curated lists of many topics.
| 7654 | 32 | 1 | 2019-01-20 | [awesome-sysadmin](https://github.com/kahun/awesome-sysadmin) | Backups, configuration management, DNS, IMAP/POP3, LDAP, monitoring, SSH, statistics, troubleshooting, virtualization, VPN and more. |
For contributing, [open an issue](https://github.com/emijrp/awesome-awesome/issues) and/or a [pull request](https://github.com/emijrp/awesome-awesome/pulls). Above there are some ideas for missing lists, be bold!
`[1:]))), out.String()))
`[1:]))), out.String())
}
func TestCompile_TabSepHtml(t *testing.T) {
out := &strings.Builder{}
in := `
"<html>
" <head>
" <meta charset="UTF-8">
" </head>
" <body>
" <main>
a b c
d e f
"<h2>Section 2</h2>
g h i
j k l
" </main>
" </body>
"</html>`[1:]
Compile(strings.NewReader(in), len(in), out, IFFTabSep, OFFHtml, &ApisCfg{&ApiCfg{}})
assert.Equal(t, `
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<main>
<table><thead><tr><th>Stars</th><th>Forks</th><th>Issues</th><th>Last Commit</th><th>Name</th><th>Desc</th></tr></thead><tbody>
<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td><a href="b">a</a></td><td>c</td></tr>
<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td><a href="e">d</a></td><td>f</td></tr>
</tbody></table>
<h2>Section 2</h2>
<table><thead><tr><th>Stars</th><th>Forks</th><th>Issues</th><th>Last Commit</th><th>Name</th><th>Desc</th></tr></thead><tbody>
<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td><a href="h">g</a></td><td>i</td></tr>
<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td><a href="k">j</a></td><td>l</td></tr>
</tbody></table>
</main>
</body>
</html>
`[1:], out.String())
}
package awesomefw
import "io"
var OFFHtml = &OutputFileFormat{ writeLiteralHtml, writeItemHtml, startHtml, nil }
func startHtml(out io.Writer, ctx *Ctx) {
ctx.OutFFCtx["writeTblHead"] = true
}
func writeLiteralHtml(out io.Writer, l string, ctx *Ctx) {
if ctx.OutFFCtx["prevWasItem"] == true {
ctx.OutFFCtx["prevWasItem"] = false
out.Write([]byte(`</tbody></table>` + "\n"))
}
ctx.OutFFCtx["writeTblHead"] = true
out.Write([]byte(l))
}
func writeItemHtml(out io.Writer, name, url, desc string, ctx *Ctx) {
if ctx.OutFFCtx["writeTblHead"] == true {
ctx.OutFFCtx["writeTblHead"] = false
out.Write([]byte(`<table><thead><tr><th>Stars</th><th>Forks</th><th>Issues</th><th>Last Commit</th><th>Name</th><th>Desc</th></tr></thead><tbody>` + "\n"))
}
meta := FetchMeta(url, ctx)
out.Write([]byte("<tr><td>"))
out.Write([]byte(meta.Stars()))
out.Write([]byte("</td><td>"))
out.Write([]byte(meta.Forks()))
out.Write([]byte("</td><td>"))
out.Write([]byte(meta.Issues()))
out.Write([]byte("</td><td>"))
out.Write([]byte(meta.LastCommit()))
out.Write([]byte("</td><td><a href=\""))
out.Write([]byte(url))
out.Write([]byte("\">"))
out.Write([]byte(name))
out.Write([]byte("</a></td><td>"))
out.Write([]byte(desc))
out.Write([]byte("</td></tr>\n"))
ctx.OutFFCtx["prevWasItem"] = true
}
......@@ -136,3 +136,7 @@ func testTestOFF(t *testing.T, name string, off *OutputFileFormat, fail bool, in
}()
Compile(strings.NewReader(in), len(in), ioutil.Discard, IFFTabSep, off, &ApisCfg{&ApiCfg{}})
}
func TestNoopLiteral(t *testing.T) {
noopLiteral(nil, "", nil)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment