Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion _datafiles/world/default/ansi-aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ colors:
mob-corpse: 67
user-corpse: 143
tip-text: 219
character-joined: 120
character-joined: 120
md-h1-prefix: black-bold
md-h1: magenta
md-h2: yellow-bold
md-li: white-bold
md-sp1: command
md-bold: 9
md-em: 208
md-hr1: 4
md-hr2: 4
20 changes: 20 additions & 0 deletions _datafiles/world/default/templates/help/attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Help for ~attack~

The ~attack~ command engages in combat with a player or NPC.
Once started, combat continues until someone flees or someone dies.

## Usage:

~attack goblin~
This would start combat with the goblin.

*Chance to Hit* is calculated as follows:

- **attackersSpeed** / (**atackerSpeed** + **defenderSpeed**) * **70** + **30**

You always have a minimum 5% chance to miss, and a minimum 5% chance to hit.

*Crit Chance* is calculated as follows:

- (**Strength** + **Speed**) / (**attackerLevel** - **defenderLevel**) + **5**

3 changes: 2 additions & 1 deletion _datafiles/world/default/templates/help/attack.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ until someone flees or someone dies.

<ansi fg="yellow">Usage: </ansi>

<ansi fg="command">attack goblin</ansi>
<ansi fg="command">attack goblin</ansi>
This would start combat with the goblin

When in combat your chance to hit is: <ansi fg="red">attackersSpeed / (atackerSpeed+defenderSpeed) * 70 + 30</ansi>
You always have a minimum 5% chance to miss and a minimum 5% chance to hit

Crits Chance is calculated as follows: <ansi fg="red">(Strength+Speed) / (attackerLevel-defenderLevel) + 5</ansi>

11 changes: 10 additions & 1 deletion _datafiles/world/empty/ansi-aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ colors:
mob-corpse: 67
user-corpse: 143
tip-text: 219
character-joined: 120
character-joined: 120
md-h1-prefix: black-bold
md-h1: magenta
md-h2: yellow-bold
md-li: white-bold
md-sp1: command
md-bold: 9
md-em: 208
md-hr1: 4
md-hr2: 4
20 changes: 20 additions & 0 deletions _datafiles/world/empty/templates/help/attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Help for ~attack~

The ~attack~ command engages in combat with a player or NPC.
Once started, combat continues until someone flees or someone dies.

## Usage:

~attack goblin~
This would start combat with the goblin.

*Chance to Hit* is calculated as follows:

- **attackersSpeed** / (**atackerSpeed** + **defenderSpeed**) * **70** + **30**

You always have a minimum 5% chance to miss, and a minimum 5% chance to hit.

*Crit Chance* is calculated as follows:

- (**Strength** + **Speed**) / (**attackerLevel** - **defenderLevel**) + **5**

143 changes: 143 additions & 0 deletions internal/markdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
## Supported Markdown

### Rules

* Two line breaks starts a new paragraph of text.
* Single line breaks collapse into a single line, UNLESS the previous line ended with a double space (Not my convention!)
* Most wrapping markdown can be nested, bold within emphasis inside of a Heading, etc.

### Headings

Markdown:

`# Heading`

Html:

```
Html tag output: <h1>Heading</h1>
```

Ansitags:

```
<ansi fg="md-h1" bg="md-h1-bg"><ansi fg="md-h1-prefix" bg="md-h1-prefix-bg">.:</ansi> This is a <ansi fg="md-bold" bg="md-bold-bg">HEADING</ansi></ansi>
```

Note: Adding additional #'s will increment the `<h#>`
Note: Ansitags only add the prefix for h1

### Horizontal Lines

Markdown:

```
---
===
:::
```

Html:

```
<hr />
```

Ansitags:

```
<ansi fg="md-hr1" bg="md-hr1-bg">--------------------------------------------------------------------------------</ansi>
<ansi fg="md-hr2" bg="md-hr2-bg">================================================================================</ansi>
<ansi fg="md-hr3" bg="md-hr3-bg">::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</ansi>
```

### Lists

**Markdown:**

```
- List Item 1
- List Sub 1
- List Item 2
- List Item 3
```

**Html:**

```
<ul>
<li>List Item 1
<ul>
<li>List Sub 1</li>
</ul>
</li>
<li>List Item 2</li>
<li>List Item 3</li>
</ul>
```

**Ansitags:**

```
<ansi fg="md-li" bg="md-li-bg">- List Item 1
<ansi fg="md-li" bg="md-li-bg">- List Sub 1</ansi></ansi>
<ansi fg="md-li" bg="md-li-bg">- List Item 2</ansi>
<ansi fg="md-li" bg="md-li-bg">- List Item 3</ansi>
```

### Emphasis

**Markdown:**

`*Emphasize me*`

**Html:**

```
<em>Emphasize me</em>
```

**Ansitags:**

```
<ansi fg="md-em" bg="md-em-bg">Emphasize me</ansi>
```

### Bold

**Markdown:**

`**Bold me**`

**Html:**

```
<strong>Bold me</strong>
```

**Ansitags:**

```
<ansi fg="md-bold" bg="md-bold-bg">Bold me</ansi>
```

### Special

**Markdown:**

`~I'm Special~`

**Html:**

```
<span data-special="1">I'm Special</span>
```

**Ansitags:**

```
<ansi fg="md-sp1" bg="md-sp1-bg">I'm Special</ansi>
```

**Notes:** Additional wrapping ~'s increment the number: `~~I'm Special~~`, `~~~I'm Special~~~` and so on.
**Notes:** `~~` is typically treated as a strikethrough in markdown.
86 changes: 86 additions & 0 deletions internal/markdown/ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package markdown

import (
"fmt"
)

// NodeType identifies the kind of AST node.
type NodeType string

const (
DocumentNode NodeType = "Document"
HeadingNode NodeType = "Heading"
ParagraphNode NodeType = "Paragraph"
HorizontalLineNode NodeType = "HorizontalLine"
HardBreakNode NodeType = "HardBreak"
ListNode NodeType = "List"
ListItemNode NodeType = "ListItem"
TextNode NodeType = "Text"
StrongNode NodeType = "Strong"
EmphasisNode NodeType = "Emphasis"
SpecialNode NodeType = "Special"
)

var (
activeFormatter Formatter = ReMarkdown{}
)

func SetFormatter(newFormatter Formatter) {
activeFormatter = newFormatter
}

// Node is an element in the AST.
type Node interface {
Type() NodeType
Children() []Node
String(int) string
}

// baseNode provides common fields.
type baseNode struct {
nodeType NodeType
nodeChildren []Node
level int
content string
}

func (n *baseNode) Type() NodeType { return n.nodeType }
func (n *baseNode) Children() []Node { return n.nodeChildren }
func (n *baseNode) String(depth int) string {
ret := ``
for _, c := range n.Children() {
if n.Type() == ListNode {
ret += c.String(depth - 1)
} else {
ret += c.String(depth + 1)
}

}

switch n.Type() {
case DocumentNode:
return activeFormatter.Document(ret, depth)
case HeadingNode:
return activeFormatter.Heading(ret, n.level)
case ParagraphNode:
return activeFormatter.Paragraph(ret, depth)
case HorizontalLineNode:
return activeFormatter.HorizontalLine(n.content, depth)
case HardBreakNode:
return activeFormatter.HardBreak(ret, depth)
case ListNode:
return activeFormatter.List(ret, depth)
case ListItemNode:
return activeFormatter.ListItem(ret, depth)
case TextNode:
return activeFormatter.Text(n.content+ret, depth)
case StrongNode:
return activeFormatter.Strong(ret, depth)
case EmphasisNode:
return activeFormatter.Emphasis(ret, depth)
case SpecialNode:
return activeFormatter.Special(ret, n.level)
default:
return fmt.Sprintf(`[INVALID Node: type=%s depth=%d text=%s]`, n.Type(), depth, n.content+"/"+ret)
}
}
Loading
Loading