Skip to content

Commit ad42943

Browse files
committed
feat(parser): improve quote parsing and design
1 parent bd037f1 commit ad42943

File tree

6 files changed

+78
-34
lines changed

6 files changed

+78
-34
lines changed

cli/cli.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package cli
22

3-
// INFO: flags pkg is weird, the file always has to be at the end of the arguments list,
4-
// due to the fact that the flag pkg won't recognize options after encountering an option it does not recognize
5-
// :(
6-
73
import (
84
"flag"
95
"fmt"

doc/assets/blockquote.png

10.1 KB
Loading

generator/generator.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ const DEFAULT_TEMPLATE = `<!DOCTYPE html><html lang="en"><head><meta charset="UT
2323
--gray: #d0d7de;
2424
--light-gray: #f2f1f1;
2525
--lighter-gray: #f3f2f2;
26-
--info: #0969da;
27-
--warning: #ccb700;
28-
--danger: #ff0400;
26+
--info: rgb(2, 122, 255);
27+
--info-lighter: rgba(2, 122, 255, 0.1);
28+
--warning: rgb(224, 220, 0);
29+
--warning-lighter: rgba(224, 222, 113, 0.2);
30+
--danger: rgb(251, 70, 76);
31+
--danger-lighter: rgba(251, 70, 76, 0.1);
32+
--note: rgb(83, 223, 221);
33+
--note-lighter: rgb(83, 223, 221, 0.2);
2934
}
3035
* {
3136
box-sizing: border-box;
@@ -101,28 +106,47 @@ blockquote {
101106
padding-right: 2rem;
102107
padding-left: 1.25rem;
103108
margin: 0;
104-
margin-top: 0.5rem;
105-
margin-bottom: 0.5rem;
109+
margin-top: 1rem;
110+
margin-bottom: 1rem;
106111
border-top-right-radius: 0.2rem;
107112
border-bottom-right-radius: 0.2rem;
108113
}
109114
blockquote .warning {
110115
color: var(--warning);
111116
}
112-
blockquote .warning:before {
113-
margin-right: 0.25rem;
114-
}
115117
blockquote .info {
116118
color: var(--info);
117119
}
118-
blockquote .info:before {
119-
margin-right: 0.25rem;
120+
blockquote .info {
121+
color: var(--info);
120122
}
121123
blockquote .danger {
122124
color: var(--danger);
123125
}
124-
blockquote .danger:before {
125-
margin-right: 0.25rem;
126+
blockquote .note {
127+
color: var(--note);
128+
}
129+
.callout {
130+
padding: 1rem;
131+
border-radius: 0.25rem;
132+
color: black;
133+
}
134+
.blockquote-info {
135+
border: 0;
136+
background-color: var(--info-lighter);
137+
}
138+
.blockquote-danger {
139+
border: 0;
140+
background-color: var(--danger-lighter);
141+
}
142+
.blockquote-warning {
143+
border-radius: 0.5rem;
144+
border: 0;
145+
background-color: var(--warning-lighter);
146+
}
147+
.blockquote-note {
148+
border: 0;
149+
background-color: var(--note-lighter);
126150
}
127151
hr {
128152
height: 0.15rem;

parser/parser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func (p *Parser) quote() Tag {
136136
case scanner.BANG:
137137
children = append(children, p.img())
138138
case scanner.NEWLINE:
139-
children = append(children, Br{})
139+
if p.prev().Kind == scanner.GREATERTHAN {
140+
children = append(children, Br{})
141+
}
140142
p.advance()
141143
case scanner.HASH:
142144
children = append(children, p.heading())

parser/tags.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,43 @@ type Quote struct {
5858

5959
func (p Quote) String() string {
6060
b := strings.Builder{}
61-
b.WriteString("<blockquote>")
61+
var callout bool
62+
var cType string
6263
for _, c := range p.children {
63-
switch c.(type) {
64-
case Bold:
65-
t := c.(Bold)
66-
switch strings.ToLower(t.text) {
67-
case "warning":
68-
t.className = "warning"
69-
case "info":
70-
t.className = "info"
71-
case "danger":
72-
t.className = "danger"
73-
case "tip":
74-
t.className = "tip"
64+
if !callout {
65+
switch c.(type) {
66+
case Bold:
67+
t := c.(Bold)
68+
switch strings.ToLower(t.text) {
69+
case "warning":
70+
t.className = "warning"
71+
case "info":
72+
t.className = "info"
73+
case "danger":
74+
t.className = "danger"
75+
case "note":
76+
t.className = "note"
77+
default:
78+
b.WriteString(t.String())
79+
continue
80+
}
81+
b.WriteString(t.String())
82+
// used to stop checking for callouts
83+
callout = true
84+
cType = t.className
85+
continue
7586
}
76-
b.WriteString(t.String())
77-
continue
7887
}
7988

8089
b.WriteString(c.String())
8190
}
82-
b.WriteString("</blockquote>")
83-
return b.String()
91+
prefix := "<blockquote>"
92+
93+
if callout {
94+
prefix = "<blockquote class=\"callout blockquote-" + cType + "\">"
95+
}
96+
97+
return prefix + b.String() + "</blockquote>"
8498
}
8599

86100
// <ul></ul>, contains ListItem

test.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Heading 1
22

3+
> **Test**
4+
>
5+
> fleck does not support inline html.
6+
37
> **Info**
48
>
59
> fleck does not support inline html.
@@ -12,6 +16,10 @@
1216
>
1317
> fleck does not support inline html.
1418
19+
> **Note**
20+
>
21+
> fleck does not support inline html.
22+
1523
```js
1624
// `npm run this-shit`
1725
console.log("🤬");

0 commit comments

Comments
 (0)