Skip to content

Commit

Permalink
feat(parser): blockquote titles
Browse files Browse the repository at this point in the history
- implemented support for blockquotes with titles (info, warning, danger)
- if newline is encountered in blockquote, replace it with br
  • Loading branch information
xNaCly committed Apr 19, 2023
1 parent 538674e commit 7ce7333
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 5 additions & 3 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func FlagCombinationSensible() {
// TODO: implement this
// TODO: document this in doc/Usage.md
func LivePreview(fileName string) {
// logger.LInfo("starting live preview")
// compile source
// start webserver at 12345
logger.LInfo("starting live preview")
Run(fileName)
// DONE: compile source

// start webserver at 12345, maybe a flag? --port
// inject js into html with websocket connection
// open default browser at localhost:12345
// if change -> send notification via websocket to html file
Expand Down
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (p *Parser) quote() Tag {
continue
case scanner.BANG:
children = append(children, p.img())
case scanner.NEWLINE:
children = append(children, Br{})
p.advance()
case scanner.HASH:
children = append(children, p.heading())
case scanner.STRAIGHTBRACEOPEN:
Expand Down
22 changes: 20 additions & 2 deletions parser/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ func (p Quote) String() string {
b := strings.Builder{}
b.WriteString("<blockquote>")
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"
}
b.WriteString(t.String())
continue
}

b.WriteString(c.String())
}
b.WriteString("</blockquote>")
Expand Down Expand Up @@ -133,11 +150,12 @@ func (p CodeInline) String() string {

// <strong></strong>, bold text
type Bold struct {
text string
className string
text string
}

func (p Bold) String() string {
return "<strong>" + p.text + "</strong>"
return fmt.Sprintf("<strong class=\"%s\">%s</strong>", p.className, p.text)
}

// <em></em>, italic text
Expand Down

0 comments on commit 7ce7333

Please sign in to comment.