mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2024-12-26 17:45: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">
|
||||
|
||||
<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>
|
||||
|
8
frontend/dist/show.html
vendored
8
frontend/dist/show.html
vendored
@ -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>
|
||||
|
@ -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
8
go.mod
@ -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
|
||||
|
@ -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)
|
||||
@ -115,7 +123,7 @@ func ConvertParagraphs(paragraphs []entities.Paragraph) string {
|
||||
func convertImg(p entities.Paragraph) string {
|
||||
if p.Metadata != nil {
|
||||
captionMarkup := ConvertMarkup(p.Text, p.Markups)
|
||||
img := Image{ID : p.Metadata.ID}
|
||||
img := Image{ID: p.Metadata.ID}
|
||||
img.Initialize(&p.Metadata.OriginalWidth, &p.Metadata.OriginalHeight)
|
||||
return fmt.Sprintf("<figure><img src=\"%s\" width=\"%d\" /><figcaption>%s</figcaption></figure>", img.src(), img.width(), captionMarkup)
|
||||
} else {
|
||||
@ -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]
|
||||
children := ConvertMarkup(p.Text, p.Markups)
|
||||
return fmt.Sprintf("<li>%s</li>", children) + convertOli(ps[1:])
|
||||
} else {
|
||||
return ""
|
||||
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)
|
||||
sb.WriteString(fmt.Sprintf("<li>%s</li>", children))
|
||||
count++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return sb.String(), count
|
||||
}
|
||||
|
||||
func convertUli(ps []entities.Paragraph) string {
|
||||
if len(ps) != 0 && ps[0].Type == "ULI" {
|
||||
p := ps[0]
|
||||
children := ConvertMarkup(p.Text, p.Markups)
|
||||
return fmt.Sprintf("<li>%s</li>", children) + convertUli(ps[1:])
|
||||
} else {
|
||||
return ""
|
||||
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)
|
||||
sb.WriteString(fmt.Sprintf("<li>%s</li>", children))
|
||||
count++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return sb.String(), count
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user