Rename Prefix|Suffix & Styled[Prefix|Suffix] => Block[Prefix|Suffix] & Prefix|Suffix

This commit is contained in:
Christian Muehlhaeuser
2019-12-13 23:11:15 +01:00
parent 46f0b9dbbd
commit 02b1904804
19 changed files with 129 additions and 121 deletions
+4 -4
View File
@@ -146,15 +146,15 @@ func (e *BaseElement) Render(w io.Writer, ctx RenderContext) error {
rules := bs.With(e.Style)
// render unstyled prefix/suffix
renderText(w, bs.Current().Style.StylePrimitive, rules.Prefix)
renderText(w, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
defer func() {
renderText(w, bs.Current().Style.StylePrimitive, rules.Suffix)
renderText(w, bs.Current().Style.StylePrimitive, rules.BlockSuffix)
}()
// render styled prefix/suffix
renderText(w, rules, rules.StyledPrefix)
renderText(w, rules, rules.Prefix)
defer func() {
renderText(w, rules, rules.StyledSuffix)
renderText(w, rules, rules.Suffix)
}()
s := e.Token
+4 -4
View File
@@ -18,8 +18,8 @@ func (e *BlockElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
bs.Push(*e)
renderText(w, bs.Parent().Style.StylePrimitive, e.Style.Prefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, e.Style.StyledPrefix)
renderText(w, bs.Parent().Style.StylePrimitive, e.Style.BlockPrefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, e.Style.Prefix)
return nil
}
@@ -47,8 +47,8 @@ func (e *BlockElement) Finish(w io.Writer, ctx RenderContext) error {
}
}
renderText(w, bs.Current().Style.StylePrimitive, e.Style.StyledSuffix)
renderText(w, bs.Parent().Style.StylePrimitive, e.Style.Suffix)
renderText(w, bs.Current().Style.StylePrimitive, e.Style.Suffix)
renderText(w, bs.Parent().Style.StylePrimitive, e.Style.BlockSuffix)
bs.Current().Block.Reset()
bs.Pop()
+2 -2
View File
@@ -36,9 +36,9 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {
}
if len(theme) > 0 {
renderText(iw, bs.Current().Style.StylePrimitive, rules.Prefix)
renderText(iw, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
err := quick.Highlight(iw, e.Code, e.Language, "terminal16m", theme)
renderText(iw, bs.Current().Style.StylePrimitive, rules.Suffix)
renderText(iw, bs.Current().Style.StylePrimitive, rules.BlockSuffix)
return err
}
+4 -4
View File
@@ -41,8 +41,8 @@ func (e *HeadingElement) Render(w io.Writer, ctx RenderContext) error {
}
bs.Push(be)
renderText(w, bs.Parent().Style.StylePrimitive, rules.Prefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, rules.StyledPrefix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.BlockPrefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, rules.Prefix)
return nil
}
@@ -81,8 +81,8 @@ func (e *HeadingElement) Finish(w io.Writer, ctx RenderContext) error {
return err
}
renderText(w, bs.Current().Style.StylePrimitive, rules.StyledSuffix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.Suffix)
renderText(w, bs.Current().Style.StylePrimitive, rules.Suffix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.BlockSuffix)
bs.Current().Block.Reset()
bs.Pop()
+2 -2
View File
@@ -56,8 +56,8 @@ func (e *LinkElement) Render(w io.Writer, ctx RenderContext) error {
style := ctx.styles.Link
if !textRendered {
pre = ""
style.Prefix = ""
style.Suffix = ""
style.BlockPrefix = ""
style.BlockSuffix = ""
}
el := &BaseElement{
+4 -4
View File
@@ -22,8 +22,8 @@ func (e *ParagraphElement) Render(w io.Writer, ctx RenderContext) error {
}
bs.Push(be)
renderText(w, bs.Parent().Style.StylePrimitive, rules.Prefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, rules.StyledPrefix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.BlockPrefix)
renderText(bs.Current().Block, bs.Current().Style.StylePrimitive, rules.Prefix)
return nil
}
@@ -45,8 +45,8 @@ func (e *ParagraphElement) Finish(w io.Writer, ctx RenderContext) error {
_, _ = mw.Write([]byte("\n"))
}
renderText(w, bs.Current().Style.StylePrimitive, rules.StyledSuffix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.Suffix)
renderText(w, bs.Current().Style.StylePrimitive, rules.Suffix)
renderText(w, bs.Parent().Style.StylePrimitive, rules.BlockSuffix)
bs.Current().Block.Reset()
bs.Pop()
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -2
View File
@@ -12,10 +12,10 @@ import (
)
type StylePrimitive struct {
BlockPrefix string `json:"block_prefix"`
BlockSuffix string `json:"block_suffix"`
Prefix string `json:"prefix"`
Suffix string `json:"suffix"`
StyledPrefix string `json:"styled_prefix"`
StyledSuffix string `json:"styled_suffix"`
Color *string `json:"color"`
BackgroundColor *string `json:"background_color"`
Underline *bool `json:"underline"`
@@ -143,6 +143,8 @@ func cascadeStyle(parent StyleBlock, child StyleBlock, onlyColors bool) StyleBlo
s.Overlined = parent.Overlined
s.Inverse = parent.Inverse
s.Blink = parent.Blink
s.BlockPrefix = parent.BlockPrefix
s.BlockSuffix = parent.BlockSuffix
s.Prefix = parent.Prefix
s.Suffix = parent.Suffix
s.Format = parent.Format
@@ -187,6 +189,12 @@ func cascadeStyle(parent StyleBlock, child StyleBlock, onlyColors bool) StyleBlo
if child.Blink != nil {
s.Blink = child.Blink
}
if child.BlockPrefix != "" {
s.BlockPrefix = child.BlockPrefix
}
if child.BlockSuffix != "" {
s.BlockSuffix = child.BlockSuffix
}
if child.Prefix != "" {
s.Prefix = child.Prefix
}
+25 -25
View File
@@ -5,16 +5,16 @@
Block elements contain other elements and are rendered around them. All block
elements support the following style settings:
| Attribute | Value | Description |
| ---------------- | ------ | -------------------------------------------------- |
| prefix | string | Printed before the block's first element |
| suffix | string | Printed after the block's last element |
| styled_prefix | string | Printed before the block's first element |
| styled_suffix | string | Printed after the block's last element |
| indent | number | Specifies the indentation of the block |
| margin | number | Specifies the margin around the block |
| color | color | Defines the default text color for the block |
| background_color | color | Defines the default background color for the block |
| Attribute | Value | Description |
| ---------------- | ------ | ------------------------------------------------------------ |
| block_prefix | string | Printed before the block's first element (in parent's style) |
| block_suffix | string | Printed after the block's last element (in parent's style) |
| prefix | string | Printed before the block's first element |
| suffix | string | Printed after the block's last element |
| indent | number | Specifies the indentation of the block |
| margin | number | Specifies the margin around the block |
| color | color | Defines the default text color for the block |
| background_color | color | Defines the default background color for the block |
Elements inside a block inherit the block's following style settings:
@@ -44,8 +44,8 @@ Style:
"document": {
"indent": 2,
"background_color": "234",
"prefix": "\n",
"suffix": "\n"
"block_prefix": "\n",
"block_suffix": "\n"
}
```
@@ -99,18 +99,18 @@ Style:
"background_color": "57"
},
"h1": {
"styled_prefix": "=> ",
"styled_suffix": " <=",
"prefix": "=> ",
"suffix": " <=",
"margin": 2,
"bold": true,
"background_color": "69"
},
"h2": {
"styled_prefix": "## ",
"prefix": "## ",
"margin": 4
},
"h3": {
"styled_prefix": "### ",
"prefix": "### ",
"margin": 6
}
```
@@ -223,10 +223,10 @@ All inline elements support the following style settings:
| Attribute | Value | Description |
| ---------------- | ------ | ----------------------------------------------------- |
| block_prefix | string | Printed before the element (in parent's style) |
| block_suffix | string | Printed after the element (in parent's style) |
| prefix | string | Printed before the element |
| suffix | string | Printed after the element |
| styled_prefix | string | Printed before the element |
| styled_suffix | string | Printed after the element |
| color | color | Defines the default text color for the document |
| background_color | color | Defines the default background color for the document |
| bold | bool | Increases text intensity |
@@ -275,7 +275,7 @@ Style:
```
"item": {
"prefix": "• "
"block_prefix": "• "
}
```
@@ -302,7 +302,7 @@ Style:
```
"enumeration": {
"prefix": ". "
"block_prefix": ". "
}
```
@@ -363,8 +363,8 @@ Style:
"link": {
"color": "123",
"underline": true,
"prefix": "(",
"suffix": ")"
"block_prefix": "(",
"block_suffix": ")"
}
```
@@ -408,8 +408,8 @@ Style:
```
"image": {
"color": "123",
"prefix": "[Image: ",
"suffix": "]"
"block_prefix": "[Image: ",
"block_suffix": "]"
}
```
@@ -523,7 +523,7 @@ Style:
```
"hr": {
"prefix": "---"
"block_prefix": "---"
}
```
+18 -18
View File
@@ -1,38 +1,38 @@
{
"document": {
"indent": 4,
"prefix": "\n\n",
"suffix": "\n\n",
"block_prefix": "\n\n",
"block_suffix": "\n\n",
"color": "252"
},
"heading": {
"suffix": "\n",
"block_suffix": "\n",
"color": "39",
"bold": true
},
"h1": {
"suffix": "\n\n",
"styled_prefix": " ",
"styled_suffix": " ",
"block_suffix": "\n\n",
"prefix": " ",
"suffix": " ",
"background_color": "63",
"color": "228",
"bold": true
},
"h2": {
"prefix": "\n",
"styled_prefix": "## "
"block_prefix": "\n",
"prefix": "## "
},
"h3": {
"styled_prefix": "### "
"prefix": "### "
},
"h4": {
"styled_prefix": "#### "
"prefix": "#### "
},
"h5": {
"styled_prefix": "##### "
"prefix": "##### "
},
"h6": {
"styled_prefix": "###### ",
"prefix": "###### ",
"color": "35",
"bold": false
},
@@ -41,10 +41,10 @@
"level_indent": 4
},
"item": {
"prefix": "• "
"block_prefix": "• "
},
"enumeration": {
"prefix": ". "
"block_prefix": ". "
},
"link_text": {
"color": "35",
@@ -63,8 +63,8 @@
"color": "212"
},
"code": {
"styled_prefix": " ",
"styled_suffix": " ",
"prefix": " ",
"suffix": " ",
"background_color": "236",
"color": "203"
},
@@ -91,12 +91,12 @@
"color": "240"
},
"block_quote": {
"prefix": "> "
"block_prefix": "> "
},
"definition_list": {},
"definition_term": {},
"definition_description": {
"prefix": "\n🠶 "
"block_prefix": "\n🠶 "
},
"html_block": {},
"html_span": {}
+2 -2
View File
@@ -2,7 +2,7 @@
"document": {
"indent": 2,
"background_color": "234",
"prefix": "\n",
"suffix": "\n"
"block_prefix": "\n",
"block_suffix": "\n"
}
}
+1 -1
View File
@@ -4,6 +4,6 @@
"background_color": "52"
},
"enumeration": {
"prefix": ". "
"block_prefix": ". "
}
}
+4 -4
View File
@@ -4,18 +4,18 @@
"background_color": "57"
},
"h1": {
"styled_prefix": "=> ",
"styled_suffix": " <=",
"prefix": "=> ",
"suffix": " <=",
"margin": 2,
"bold": true,
"background_color": "69"
},
"h2": {
"styled_prefix": "## ",
"prefix": "## ",
"margin": 4
},
"h3": {
"styled_prefix": "### ",
"prefix": "### ",
"margin": 6
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
{
"image": {
"color": "123",
"prefix": "[Image: ",
"suffix": "]"
"block_prefix": "[Image: ",
"block_suffix": "]"
},
"image_text": {
"color": "8"
+2 -2
View File
@@ -2,8 +2,8 @@
"link": {
"color": "123",
"underline": true,
"prefix": "(",
"suffix": ")"
"block_prefix": "(",
"block_suffix": ")"
},
"link_text": {
"color": "123",
+1 -1
View File
@@ -5,6 +5,6 @@
"level_indent": 4
},
"item": {
"prefix": "• "
"block_prefix": "• "
}
}
+18 -18
View File
@@ -1,38 +1,38 @@
{
"document": {
"indent": 4,
"prefix": "\n\n",
"suffix": "\n\n",
"block_prefix": "\n\n",
"block_suffix": "\n\n",
"color": "234"
},
"heading": {
"suffix": "\n",
"block_suffix": "\n",
"color": "27",
"bold": true
},
"h1": {
"suffix": "\n\n",
"styled_prefix": " ",
"styled_suffix": " ",
"block_suffix": "\n\n",
"prefix": " ",
"suffix": " ",
"background_color": "63",
"color": "228",
"bold": true
},
"h2": {
"prefix": "\n",
"styled_prefix": "## "
"block_prefix": "\n",
"prefix": "## "
},
"h3": {
"styled_prefix": "### "
"prefix": "### "
},
"h4": {
"styled_prefix": "#### "
"prefix": "#### "
},
"h5": {
"styled_prefix": "##### "
"prefix": "##### "
},
"h6": {
"styled_prefix": "###### ",
"prefix": "###### ",
"bold": false
},
"text": {},
@@ -40,10 +40,10 @@
"level_indent": 4
},
"item": {
"prefix": "• "
"block_prefix": "• "
},
"enumeration": {
"prefix": ". "
"block_prefix": ". "
},
"link_text": {
"color": "29",
@@ -62,8 +62,8 @@
"color": "205"
},
"code": {
"styled_prefix": " ",
"styled_suffix": " ",
"prefix": " ",
"suffix": " ",
"background_color": "254",
"color": "203"
},
@@ -86,12 +86,12 @@
"color": "240"
},
"block_quote": {
"prefix": "> "
"block_prefix": "> "
},
"definition_list": {},
"definition_term": {},
"definition_description": {
"prefix": "\n🠶 "
"block_prefix": "\n🠶 "
},
"html_block": {},
"html_span": {}
+23 -23
View File
@@ -1,41 +1,41 @@
{
"document": {
"indent": 4,
"prefix": "\n\n",
"suffix": "\n\n"
"block_prefix": "\n\n",
"block_suffix": "\n\n"
},
"heading": {
"suffix": "\n"
"block_suffix": "\n"
},
"h1": {
"suffix": "\n\n",
"styled_prefix": "# "
"block_suffix": "\n\n",
"prefix": "# "
},
"h2": {
"prefix": "\n",
"styled_prefix": "## "
"block_prefix": "\n",
"prefix": "## "
},
"h3": {
"styled_prefix": "### "
"prefix": "### "
},
"h4": {
"styled_prefix": "#### "
"prefix": "#### "
},
"h5": {
"styled_prefix": "##### "
"prefix": "##### "
},
"h6": {
"styled_prefix": "###### "
"prefix": "###### "
},
"text": {},
"list": {
"level_indent": 4
},
"item": {
"prefix": "• "
"block_prefix": "• "
},
"enumeration": {
"prefix": ". "
"block_prefix": ". "
},
"link_text": {},
"link": {},
@@ -44,35 +44,35 @@
},
"image": {},
"code": {
"prefix": "`",
"suffix": "`"
"block_prefix": "`",
"block_suffix": "`"
},
"code_block": {
"margin": 4
},
"table": {},
"strikethrough": {
"prefix": "~~",
"suffix": "~~"
"block_prefix": "~~",
"block_suffix": "~~"
},
"emph": {
"prefix": "*",
"suffix": "*"
"block_prefix": "*",
"block_suffix": "*"
},
"strong": {
"prefix": "**",
"suffix": "**"
"block_prefix": "**",
"block_suffix": "**"
},
"hr": {
"format": "\n--------\n"
},
"block_quote": {
"prefix": "> "
"block_prefix": "> "
},
"definition_list": {},
"definition_term": {},
"definition_description": {
"prefix": "\n🠶 "
"block_prefix": "\n🠶 "
},
"html_block": {},
"html_span": {}
+2 -2
View File
@@ -47,7 +47,7 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
},
}
renderText(ctx.table.indentWriter, bs.Current().Style.StylePrimitive, rules.Prefix)
renderText(ctx.table.indentWriter, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
ctx.table.writer = tablewriter.NewWriter(ctx.table.indentWriter)
return nil
}
@@ -57,7 +57,7 @@ func (e *TableElement) Finish(w io.Writer, ctx RenderContext) error {
ctx.table.writer = nil
rules := ctx.styles.Table
renderText(ctx.table.indentWriter, ctx.blockStack.Current().Style.StylePrimitive, rules.Suffix)
renderText(ctx.table.indentWriter, ctx.blockStack.Current().Style.StylePrimitive, rules.BlockSuffix)
return nil
}