mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2024-11-16 11:25:57 +00:00
fix(paragraphs): fix ordered list rendering
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
parent
f1ec8f7729
commit
de151f4895
2
frontend/dist/index.html
vendored
2
frontend/dist/index.html
vendored
@ -6,7 +6,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
<link rel="stylesheet" href="/assets/index-d9a17752.css">
|
<link rel="stylesheet" href="/assets/index-1eb94859.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 class="text-2xl">Hello, World!</h1>
|
<h1 class="text-2xl">Hello, World!</h1>
|
||||||
|
8
frontend/dist/show.html
vendored
8
frontend/dist/show.html
vendored
@ -14,13 +14,13 @@
|
|||||||
rel="stylesheet">
|
rel="stylesheet">
|
||||||
|
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
<link rel="stylesheet" href="/assets/show-9b4da228.css">
|
<link rel="stylesheet" href="/assets/show-d7d0e271.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="flex flex-col h-full w-full items-center">
|
<body class="flex flex-col h-full w-full items-center">
|
||||||
<article class="prose lg:prose-xl p-20">
|
<article class="prose lg:prose-lg sm:prose-sm py-20">
|
||||||
<h2 class="text-2xl">{{.Title}}</h2>
|
<h1 class="text-2xl">{{.Title}}</h1>
|
||||||
<p><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
|
<p class="pb-8"><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
|
||||||
{{.Paragraphs}}
|
{{.Paragraphs}}
|
||||||
</article>
|
</article>
|
||||||
</body>
|
</body>
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="flex flex-col h-full w-full items-center">
|
<body class="flex flex-col h-full w-full items-center">
|
||||||
<article class="prose lg:prose-xl p-20">
|
<article class="prose lg:prose-lg sm:prose-sm py-20">
|
||||||
<h2 class="text-2xl">{{.Title}}</h2>
|
<h1 class="text-2xl">{{.Title}}</h1>
|
||||||
<p><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
|
<p class="pb-8"><a href="https://medium.com/u/{{.UserId}}">{{.Author}}</a> on {{.PublishDate}}</p>
|
||||||
{{.Paragraphs}}
|
{{.Paragraphs}}
|
||||||
</article>
|
</article>
|
||||||
</body>
|
</body>
|
||||||
|
8
go.mod
8
go.mod
@ -2,13 +2,13 @@ module github.com/medium.rip
|
|||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require github.com/sirupsen/logrus v1.9.2
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/gofiber/template v1.8.1
|
||||||
github.com/gofiber/template v1.8.1 // indirect
|
github.com/sirupsen/logrus v1.9.2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||||
github.com/gofiber/fiber/v2 v2.46.0
|
github.com/gofiber/fiber/v2 v2.46.0
|
||||||
|
@ -62,7 +62,13 @@ func ConvertParagraphs(paragraphs []entities.Paragraph) string {
|
|||||||
|
|
||||||
var ps strings.Builder
|
var ps strings.Builder
|
||||||
|
|
||||||
|
skipCount := 0
|
||||||
for i, p := range paragraphs {
|
for i, p := range paragraphs {
|
||||||
|
if skipCount > 0 {
|
||||||
|
skipCount--
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
switch p.Type {
|
switch p.Type {
|
||||||
case "BQ", "MIXTAPE_EMBED", "PQ":
|
case "BQ", "MIXTAPE_EMBED", "PQ":
|
||||||
children := ConvertMarkup(p.Text, p.Markups)
|
children := ConvertMarkup(p.Text, p.Markups)
|
||||||
@ -92,10 +98,12 @@ func ConvertParagraphs(paragraphs []entities.Paragraph) string {
|
|||||||
case "IMG":
|
case "IMG":
|
||||||
ps.WriteString(convertImg(p))
|
ps.WriteString(convertImg(p))
|
||||||
case "OLI":
|
case "OLI":
|
||||||
listItems := convertOli(paragraphs[i:])
|
listItems, skip := convertOli(paragraphs[i:])
|
||||||
|
skipCount = skip
|
||||||
ps.WriteString(fmt.Sprintf("<ol>%s</ol>", listItems))
|
ps.WriteString(fmt.Sprintf("<ol>%s</ol>", listItems))
|
||||||
case "ULI":
|
case "ULI":
|
||||||
listItems := convertUli(paragraphs[i:])
|
listItems, skip := convertUli(paragraphs[i:])
|
||||||
|
skipCount = skip
|
||||||
ps.WriteString(fmt.Sprintf("<ul>%s</ul>", listItems))
|
ps.WriteString(fmt.Sprintf("<ul>%s</ul>", listItems))
|
||||||
case "P":
|
case "P":
|
||||||
children := ConvertMarkup(p.Text, p.Markups)
|
children := ConvertMarkup(p.Text, p.Markups)
|
||||||
@ -123,22 +131,39 @@ func convertImg(p entities.Paragraph) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertOli(ps []entities.Paragraph) string {
|
func convertOli(ps []entities.Paragraph) (string, int) {
|
||||||
if len(ps) != 0 && ps[0].Type == "OLI" {
|
var sb strings.Builder
|
||||||
p := ps[0]
|
count := 0
|
||||||
|
|
||||||
|
for _, p := range ps {
|
||||||
|
if p.Type == "OLI" {
|
||||||
children := ConvertMarkup(p.Text, p.Markups)
|
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 {
|
} else {
|
||||||
return ""
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertUli(ps []entities.Paragraph) string {
|
return sb.String(), count
|
||||||
if len(ps) != 0 && ps[0].Type == "ULI" {
|
}
|
||||||
p := ps[0]
|
|
||||||
|
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)
|
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 {
|
} else {
|
||||||
return ""
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sb.String(), count
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user