Skip to content

Commit

Permalink
feat(parser): improve quote parsing and design
Browse files Browse the repository at this point in the history
  • Loading branch information
xNaCly committed Apr 25, 2023
1 parent bd037f1 commit ad42943
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 34 deletions.
4 changes: 0 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package cli

// INFO: flags pkg is weird, the file always has to be at the end of the arguments list,
// due to the fact that the flag pkg won't recognize options after encountering an option it does not recognize
// :(

import (
"flag"
"fmt"
Expand Down
Binary file modified doc/assets/blockquote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 36 additions & 12 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ const DEFAULT_TEMPLATE = `<!DOCTYPE html><html lang="en"><head><meta charset="UT
--gray: #d0d7de;
--light-gray: #f2f1f1;
--lighter-gray: #f3f2f2;
--info: #0969da;
--warning: #ccb700;
--danger: #ff0400;
--info: rgb(2, 122, 255);
--info-lighter: rgba(2, 122, 255, 0.1);
--warning: rgb(224, 220, 0);
--warning-lighter: rgba(224, 222, 113, 0.2);
--danger: rgb(251, 70, 76);
--danger-lighter: rgba(251, 70, 76, 0.1);
--note: rgb(83, 223, 221);
--note-lighter: rgb(83, 223, 221, 0.2);
}
* {
box-sizing: border-box;
Expand Down Expand Up @@ -101,28 +106,47 @@ blockquote {
padding-right: 2rem;
padding-left: 1.25rem;
margin: 0;
margin-top: 0.5rem;
margin-bottom: 0.5rem;
margin-top: 1rem;
margin-bottom: 1rem;
border-top-right-radius: 0.2rem;
border-bottom-right-radius: 0.2rem;
}
blockquote .warning {
color: var(--warning);
}
blockquote .warning:before {
margin-right: 0.25rem;
}
blockquote .info {
color: var(--info);
}
blockquote .info:before {
margin-right: 0.25rem;
blockquote .info {
color: var(--info);
}
blockquote .danger {
color: var(--danger);
}
blockquote .danger:before {
margin-right: 0.25rem;
blockquote .note {
color: var(--note);
}
.callout {
padding: 1rem;
border-radius: 0.25rem;
color: black;
}
.blockquote-info {
border: 0;
background-color: var(--info-lighter);
}
.blockquote-danger {
border: 0;
background-color: var(--danger-lighter);
}
.blockquote-warning {
border-radius: 0.5rem;
border: 0;
background-color: var(--warning-lighter);
}
.blockquote-note {
border: 0;
background-color: var(--note-lighter);
}
hr {
height: 0.15rem;
Expand Down
4 changes: 3 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ func (p *Parser) quote() Tag {
case scanner.BANG:
children = append(children, p.img())
case scanner.NEWLINE:
children = append(children, Br{})
if p.prev().Kind == scanner.GREATERTHAN {
children = append(children, Br{})
}
p.advance()
case scanner.HASH:
children = append(children, p.heading())
Expand Down
48 changes: 31 additions & 17 deletions parser/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,43 @@ type Quote struct {

func (p Quote) String() string {
b := strings.Builder{}
b.WriteString("<blockquote>")
var callout bool
var cType string
for _, c := range p.children {
switch c.(type) {
case Bold:
t := c.(Bold)
switch strings.ToLower(t.text) {
case "warning":
t.className = "warning"
case "info":
t.className = "info"
case "danger":
t.className = "danger"
case "tip":
t.className = "tip"
if !callout {
switch c.(type) {
case Bold:
t := c.(Bold)
switch strings.ToLower(t.text) {
case "warning":
t.className = "warning"
case "info":
t.className = "info"
case "danger":
t.className = "danger"
case "note":
t.className = "note"
default:
b.WriteString(t.String())
continue
}
b.WriteString(t.String())
// used to stop checking for callouts
callout = true
cType = t.className
continue
}
b.WriteString(t.String())
continue
}

b.WriteString(c.String())
}
b.WriteString("</blockquote>")
return b.String()
prefix := "<blockquote>"

if callout {
prefix = "<blockquote class=\"callout blockquote-" + cType + "\">"
}

return prefix + b.String() + "</blockquote>"
}

// <ul></ul>, contains ListItem
Expand Down
8 changes: 8 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Heading 1

> **Test**
>
> fleck does not support inline html.
> **Info**
>
> fleck does not support inline html.
Expand All @@ -12,6 +16,10 @@
>
> fleck does not support inline html.
> **Note**
>
> fleck does not support inline html.
```js
// `npm run this-shit`
console.log("🤬");
Expand Down

0 comments on commit ad42943

Please sign in to comment.