fix(paragraphs): fix ordered list rendering

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2023-05-28 17:53:19 +05:30
parent f1ec8f7729
commit de151f4895
5 changed files with 54 additions and 29 deletions

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ .Title }}</title>
<link rel="stylesheet" href="/assets/index-d9a17752.css">
<link rel="stylesheet" href="/assets/index-1eb94859.css">
</head>
<body>
<h1 class="text-2xl">Hello, World!</h1>

View File

@ -14,13 +14,13 @@
rel="stylesheet">
<title>{{ .Title }}</title>
<link rel="stylesheet" href="/assets/show-9b4da228.css">
<link rel="stylesheet" href="/assets/show-d7d0e271.css">
</head>
<body class="flex flex-col h-full w-full items-center">
<article class="prose lg:prose-xl p-20">
<h2 class="text-2xl">{{.Title}}</h2>
<p><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
<article class="prose lg:prose-lg sm:prose-sm py-20">
<h1 class="text-2xl">{{.Title}}</h1>
<p class="pb-8"><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
{{.Paragraphs}}
</article>
</body>

View File

@ -17,9 +17,9 @@
</head>
<body class="flex flex-col h-full w-full items-center">
<article class="prose lg:prose-xl p-20">
<h2 class="text-2xl">{{.Title}}</h2>
<p><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
<article class="prose lg:prose-lg sm:prose-sm py-20">
<h1 class="text-2xl">{{.Title}}</h1>
<p class="pb-8"><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
{{.Paragraphs}}
</article>
</body>

8
go.mod
View File

@ -2,13 +2,13 @@ module github.com/medium.rip
go 1.20
require github.com/sirupsen/logrus v1.9.2
require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gofiber/template v1.8.1 // indirect
github.com/gofiber/template v1.8.1
github.com/sirupsen/logrus v1.9.2
)
require github.com/fsnotify/fsnotify v1.6.0 // indirect
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/gofiber/fiber/v2 v2.46.0

View File

@ -62,7 +62,13 @@ func ConvertParagraphs(paragraphs []entities.Paragraph) string {
var ps strings.Builder
skipCount := 0
for i, p := range paragraphs {
if skipCount > 0 {
skipCount--
continue
}
switch p.Type {
case "BQ", "MIXTAPE_EMBED", "PQ":
children := ConvertMarkup(p.Text, p.Markups)
@ -92,10 +98,12 @@ func ConvertParagraphs(paragraphs []entities.Paragraph) string {
case "IMG":
ps.WriteString(convertImg(p))
case "OLI":
listItems := convertOli(paragraphs[i:])
listItems, skip := convertOli(paragraphs[i:])
skipCount = skip
ps.WriteString(fmt.Sprintf("<ol>%s</ol>", listItems))
case "ULI":
listItems := convertUli(paragraphs[i:])
listItems, skip := convertUli(paragraphs[i:])
skipCount = skip
ps.WriteString(fmt.Sprintf("<ul>%s</ul>", listItems))
case "P":
children := ConvertMarkup(p.Text, p.Markups)
@ -123,22 +131,39 @@ func convertImg(p entities.Paragraph) string {
}
}
func convertOli(ps []entities.Paragraph) string {
if len(ps) != 0 && ps[0].Type == "OLI" {
p := ps[0]
func convertOli(ps []entities.Paragraph) (string, int) {
var sb strings.Builder
count := 0
for _, p := range ps {
if p.Type == "OLI" {
children := ConvertMarkup(p.Text, p.Markups)
return fmt.Sprintf("<li>%s</li>", children) + convertOli(ps[1:])
sb.WriteString(fmt.Sprintf("<li>%s</li>", children))
count++
} else {
return ""
break
}
}
func convertUli(ps []entities.Paragraph) string {
if len(ps) != 0 && ps[0].Type == "ULI" {
p := ps[0]
return sb.String(), count
}
func convertUli(ps []entities.Paragraph) (string, int) {
var sb strings.Builder
count := 0
for _, p := range ps {
if p.Type == "ULI" {
if p.Text == "Rename the example.env to .env." {
fmt.Println("HERE")
}
children := ConvertMarkup(p.Text, p.Markups)
return fmt.Sprintf("<li>%s</li>", children) + convertUli(ps[1:])
sb.WriteString(fmt.Sprintf("<li>%s</li>", children))
count++
} else {
return ""
break
}
}
return sb.String(), count
}