-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown/UI templating framework competition #2753
Comments
I've been working on a approach that focuses on simplicity. The idea is to bypass the traditional Markdown parsing and directly convert function calls to HTML, minimizing computation and complexity. Below is a demonstration of how this approach works and the output it produces. Example Render Function func Render(_ string) string {
md := mdify.New()
md.H1("Welcome to Gno Markdown! in h1")
md.H2("Welcome to Gno Markdown! in h2")
md.H3("Welcome to Gno Markdown! in h3")
md.P("This is a sample paragraph in markdown.")
items := []string{"Item 1", "Item 2", "Item 3"}
md.UL(items)
orderedItems := []string{"First", "Second", "Third"}
md.OL(orderedItems)
md.BR()
md.Code("go", code)
result := md.Render()
return result
} This implementation is designed to be easy to understand and use. By using this aproach we remove customization and we only focus on basic Markdown functions. API Implementation Details type HTML struct {
content []string
}
func New() *HTML {
return &HTML{}
}
func (html *HTML) H1(text string) {
html.content = append(html.content, "<h1>" + text + "</h1>")
}
func (html *HTML) UL(items []string) {
html.content = append(html.content, "<ul>")
for _, item := range items {
html.content = append(html.content, "<li>"+item+"</li>")
}
html.content = append(html.content, "</ul>")
}
func (html *HTML) Code(language, code string) {
if language == "" {
html.content = append(html.content, "<pre><code>"+code+"</code></pre>")
} else {
html.content = append(html.content, "<pre><code class=\"language-"+language+"\">"+code+"</code></pre>")
}
} Feedback Request I would appreciate any feedback on this concept. If you think this is a good approach, please feel free to reach out with ideas for optimizations and other improvements to this API. |
Continuation of #2753 (comment) To support Markdown features like bold, italic, and func (html *HTML) Bold(text string) string {
return "<b>" + text + "</b>"
} Usage example: md.P("This is a sample paragraph " + md.Bold("in markdown.")) A more elegant solution is to adopt a Sprintf-like approach. Although this method is more complex and computationally intensive, it allows for more flexibility. Instead of manual string concatenation, we can scan the entire string and replace special symbols with their corresponding HTML tags. md.P("This is a sample paragraph **in markdown.**") |
Thanks for the proposal. I would advise you create a PR with your library, and try to use it in some of the already existing realms in the examples folder. For example, you can try to make the With this, we can see the practical side of your code. You can choose another existing realm as well, or choose to make your own, showcasing the potential of your proposal. There, we can also leave comments and discuss specifics of the code, such as readability, performance, etc. |
Please open a dedicated issue or pull request with your example so we can comment on it. Be sure to reference your issue or pull request here. I have comments to provide, but I don't want to clutter this issue further. |
Note: we're not looking for a Markdown to HTML library or an HTML framework. We are seeking a Markdown framework that allows us to write idiomatic Gno and generate Markdown. |
Here are some thoughts on this requirement. Since a library that renders markdown from a go abstraction might be not enough to be considered a complete framework, here is a non-exhaustive list of ideas inspired by other UI frameworks (Hugo, Pug, Handlebars...). These ideas are meant for brainstorming and discussion purposes only.
This question is fundamental. However, do we need all of these features for the Note Disclaimer: Not all of these features or syntax suggestions are intended for implementation. Some may not fit our current scope, and others might not be appropriate. This is just a starting point for discussion to better understand the framework's boundaries/definition. Key Features for an UI Framework
BenefitsImproved Readability: Cleaner and more understandable code for generating Markdown. What it may look likeWhat it may look like as Framework (minus some templating system feature such as Render function could be used with Templating System + Ui Markdown Functions OR/AND native Markdown. package main
...
// Functions providing data
func introSection() string {
return "We’re building gno.land, the leading open-source smart contract platform..."
}
func discoverLinks() md.Element {
return md.List([]md.Element{
md.Link("About", "/about"),
md.Link("GitHub", "https://github.com/gnolang"),
md.Link("Blog", "/blog"),
md.Link("Events", "/events"),
md.Text("Tokenomics (soon)"),
md.Link("Partners, Fund, Grants", "/partners"),
md.Link("Explore the Ecosystem", "/ecosystem"),
md.Link("Careers", "https://jobs.lever.co/allinbits?department=Gno.land"),
})
}
...
// Functions for pipes (These ones are genenric and may could be embedded in the Ui lib itself)
func FormatDate(format string, date time.Time) string {
return date.Format(format)
}
func ToUpper(text string) string {
return strings.ToUpper(text)
}
...
// Render function could add Templating System + Ui Markdown Functions OR/AND native Markdown.
func Render(_ string) {
// Define the template with placeholders, control structures, and pipe modifiers
// OR directly at root of the function?
const homeTemplate = `
# Welcome to gno.land
Published on: {{ .Date | FormatDate "Jan 2, 2006" }}
{{ .Intro }}
{{ Jumbotron .DiscoverLinks }}
### Latest Blogposts
{{ range .BlogPosts }}
- [{{ .Title }}]({{ .URL }})
{{ end }}
---
### Explore New Packages and Realms
{{ range .Packages }}
{{ Header 4 .Name | ToUpper }}
{{ range .Links }}
- [{{ .Text }}]({{ .URL }})
{{ end }}
{{ end }}
`
... Generated Markdown: # Welcome to gno.land
Published on: Apr 27, 2024
We’re building gno.land, the leading open-source smart contract platform...
[Jumbotron Content Here]
### Latest Blogposts
- [Post 1](/blog/post1)
- [Post 2](/blog/post2)
---
### Explore New Packages and Realms
#### PACKAGE 1
- [Link 1](#)
- [Link 2](#)
#### PACKAGE 2
- [Link A](#)
- [Link B](#)
Do you think this Framework features would effectively integrate with our current Render function and simplify our Markdown generation process? Is it too much? Maybe some ideas are good/bad, maybe you have other ones? For the framework definition and/or the application. Finally, what makes a good templating/UI framework for GnoWeb and what do we need? Looking forward to your thoughts and feedback! |
Several aspects of this proposal excite me, particularly the However, I believe the goal of the competition is to present multiple opinionated proposals. Ultimately, usage will determine the best ones, not me or the core team. |
Besides Markdown, I've developed a UI components package designed to enhance UI designs. #2947 |
@thanhngoc541 your framework in #2947 looks pretty cool, but unfortunately, we are not looking for an HTML framework. As gnoweb should not support HTML syntax at some point (and i mean really soon), we want people to stop using HTML until that restriction has been introduced and enforced. Even if I know you were thinking more to an alternative, we cannot introduce this kind of framework until then. |
I've developed another MDUI package designed to enhance UI designs using markdown. #2976 |
Hi @moul, i have created this markdown utilities package, if you think it's a good fit for the use case i can port it to gno.land |
You haven't provided Gno code; this is go code. Please make a proper PR with Gno code that's tested. Gno doesn't support generics. |
As mentioned in #2976:
|
We are launching a bounty to find an idiomatic and straightforward Gno API for generating simple markdown, focusing on standard markdown.
While we are considering extending or flavoring markdown in the future (#439), the primary goal of this competition is to identify a library that everyone will prefer over manual string concatenation.
Participants are invited to consider principles similar to GoHugo's use of text/template, the current p/demo/ui (#903), and to analyze other implementations. As in any other language, competition for the best templating system is always intense, and we expect to find a leading framework by adoption. It may also make sense to have a "second most-favorited" or even a third implementation, particularly if the implementations are opinionated and stylistically different.
We expect multiple participants and will share the bounty based on the effort and quality of the submissions. Bounties will be distributed progressively towards the best implementations. This competition will also provide valuable insights for our ongoing work on markdown extensions.
Currently, we suggest that you open your library in p/demo/ui/; we'll eventually reorganize the examples folder later. Additionally, make sure to update at least one or some contracts using your libraries, so we can have usage examples.
Good luck!
Edit: We're not looking for a Markdown to HTML library or an HTML framework. We are seeking a Markdown framework that allows us to write idiomatic Gno and generate Markdown.
Bounty Size: M; expected maximum reward: $2,000.
Find out more on the bounty program. If you participate with intention of receiving the bounty, you must agree to the Bounty Terms and Conditions.
More bounties | Contributing guidelines
The text was updated successfully, but these errors were encountered: