Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: charmbracelet/glamour
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.0
Choose a base ref
...
head repository: charmbracelet/glamour
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.8.0
Choose a head ref
  • 13 commits
  • 118 files changed
  • 9 contributors

Commits on Jul 9, 2024

  1. chore: update CODEOWNERS (#308)

    meowgorithm authored Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    joyeecheung Joyee Cheung
    Copy the full SHA
    f16d73d View commit details
  2. deps: update all deps, go version (#307)

    * deps: update all deps, go version
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * ci: fix
    
    * test: fix
    
    * deps: update
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    ---------
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    caarlos0 authored Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    joyeecheung Joyee Cheung
    Copy the full SHA
    95b5dc8 View commit details
  3. chore(deps): bump github.com/microcosm-cc/bluemonday (#309)

    Bumps [github.com/microcosm-cc/bluemonday](https://github.com/microcosm-cc/bluemonday) from 1.0.26 to 1.0.27.
    - [Release notes](https://github.com/microcosm-cc/bluemonday/releases)
    - [Commits](microcosm-cc/bluemonday@v1.0.26...v1.0.27)
    
    ---
    updated-dependencies:
    - dependency-name: github.com/microcosm-cc/bluemonday
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 9, 2024
    Copy the full SHA
    359aef4 View commit details
  4. chore(deps): bump golangci/golangci-lint-action from 4 to 6 (#301)

    Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 4 to 6.
    - [Release notes](https://github.com/golangci/golangci-lint-action/releases)
    - [Commits](golangci/golangci-lint-action@v4...v6)
    
    ---
    updated-dependencies:
    - dependency-name: golangci/golangci-lint-action
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    aduh95 Antoine du Hamel
    Copy the full SHA
    2878d38 View commit details
  5. ci: scan vulns and common errors (#310)

    * ci: scan vulns and common errors
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: use go fuzz
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: using io.WriteString when it makes sense
    
    ---------
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    caarlos0 authored Jul 9, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    aduh95 Antoine du Hamel
    Copy the full SHA
    8abcfb0 View commit details

Commits on Jul 31, 2024

  1. chore: cleanup useless comments (#302)

    nervo authored and bashbunni committed Jul 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4620e19 View commit details
  2. feat: Add Tokyo Night theme (#229)

    basilioss authored and bashbunni committed Jul 31, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    aduh95 Antoine du Hamel
    Copy the full SHA
    47b99e4 View commit details
  3. fix: many rendering issues (#317)

    * wip
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * wip
    
    * wip
    
    * wip
    
    * fix: autolink
    
    closes #290
    
    * fix: escape characters
    
    closes #106
    closes #274
    closes #311
    
    * fix: table
    
    * ci: golangci lint update
    
    * feat: use x/golden
    
    * test: #106
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: #290
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: #312
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: #257
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * test: #149
    
    * fix: #239
    
    * feat: use lipgloss table
    
    closes #262
    
    Co-authored-by: bashbunni <bunni@bashbunni.dev>
    
    * fix: codespan is not a block
    
    * test: #315
    
    * test: #316
    
    * fix: #316
    
    * test: table
    
    * fix: codespans, tables
    
    * test: table
    
    * test: #117
    
    * test: #60
    
    * fix: rm stylewriter
    
    * fix: #313
    
    * fix: margin
    
    * fix: blocks and word wrap
    
    * fix: build
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * chore: gitattributes
    
    * fix: test opt
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: stable lipgloss
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * fix: double styles
    
    * fix: tables
    
    * fix: tables
    
    ---------
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    Co-authored-by: bashbunni <bunni@bashbunni.dev>
    caarlos0 and bashbunni committed Jul 31, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    aduh95 Antoine du Hamel
    Copy the full SHA
    5f5965e View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    aduh95 Antoine du Hamel
    Copy the full SHA
    26f0bd4 View commit details
  5. feat(auto): auto NoTTY style (#268)

    Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    2 people authored and bashbunni committed Jul 31, 2024
    Copy the full SHA
    c3e9140 View commit details
  6. chore: go mod tidy

    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    caarlos0 authored and bashbunni committed Jul 31, 2024
    Copy the full SHA
    dad25dc View commit details

Commits on Aug 2, 2024

  1. refactor(gallery): use freeze for gallery images (#322)

    bashbunni authored Aug 2, 2024
    Copy the full SHA
    1fcce6f View commit details

Commits on Aug 5, 2024

  1. fix(styles): tokyo night (#320)

    * fix: tokyo night
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    
    * docs: contributing styles
    
    * refactor(styles): move to styles package
    
    * feat(examples): add stdin/stdout example with env styles detection
    
    * chore: clean commented code
    
    * fix: fix errors
    
    * docs(gallery): add tokyo night image
    
    * fix: update generate-style-json path
    
    Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
    
    * docs: how to create a new style
    
    ---------
    
    Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
    Co-authored-by: bashbunni <bunni@bashbunni.dev>
    Co-authored-by: bashbunni <15822994+bashbunni@users.noreply.github.com>
    Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
    4 people authored Aug 5, 2024
    Copy the full SHA
    29b800e View commit details
Showing with 1,617 additions and 741 deletions.
  1. +1 βˆ’0 .gitattributes
  2. +1 βˆ’1 .github/CODEOWNERS
  3. +17 βˆ’5 .github/workflows/build.yml
  4. +5 βˆ’9 .github/workflows/coverage.yml
  5. +5 βˆ’5 .github/workflows/lint.yml
  6. +1 βˆ’0 .gitignore
  7. +1 βˆ’1 .golangci.yml
  8. +8 βˆ’0 CONTRIBUTING.md
  9. +45 βˆ’12 ansi/baseelement.go
  10. +9 βˆ’6 ansi/blockelement.go
  11. +2 βˆ’2 ansi/blockstack.go
  12. +1 βˆ’0 ansi/codeblock.go
  13. +14 βˆ’0 ansi/codespan.go
  14. +69 βˆ’65 ansi/elements.go
  15. +44 βˆ’0 ansi/emphasis.go
  16. +25 βˆ’52 ansi/link.go
  17. +2 βˆ’2 ansi/paragraph.go
  18. +4 βˆ’7 ansi/renderer.go
  19. +46 βˆ’86 ansi/renderer_test.go
  20. +25 βˆ’10 ansi/style.go
  21. +0 βˆ’33 ansi/stylewriter.go
  22. +97 βˆ’52 ansi/table.go
  23. +2 βˆ’0 ansi/testdata/TestRenderer/block_quote.golden
  24. 0 testdata/code.test β†’ ansi/testdata/TestRenderer/code.golden
  25. +3 βˆ’0 ansi/testdata/TestRenderer/code_block.golden
  26. 0 testdata/emoji.test β†’ ansi/testdata/TestRenderer/emoji.golden
  27. 0 testdata/emph.test β†’ ansi/testdata/TestRenderer/emph.golden
  28. 0 testdata/enumeration.test β†’ ansi/testdata/TestRenderer/enumeration.golden
  29. +3 βˆ’0 ansi/testdata/TestRenderer/heading.golden
  30. 0 testdata/hr.test β†’ ansi/testdata/TestRenderer/hr.golden
  31. 0 testdata/image.test β†’ ansi/testdata/TestRenderer/image.golden
  32. 0 testdata/link.test β†’ ansi/testdata/TestRenderer/link.golden
  33. +1 βˆ’1 testdata/list.test β†’ ansi/testdata/TestRenderer/list.golden
  34. 0 testdata/ordered_list.test β†’ ansi/testdata/TestRenderer/ordered_list.golden
  35. 0 testdata/strikethrough.test β†’ ansi/testdata/TestRenderer/strikethrough.golden
  36. 0 testdata/strong.test β†’ ansi/testdata/TestRenderer/strong.golden
  37. +5 βˆ’0 ansi/testdata/TestRenderer/table.golden
  38. +5 βˆ’0 ansi/testdata/TestRenderer/table_align.golden
  39. 0 testdata/task.test β†’ ansi/testdata/TestRenderer/task.golden
  40. +17 βˆ’0 ansi/testdata/TestRendererIssues/106.golden
  41. +7 βˆ’0 ansi/testdata/TestRendererIssues/107.golden
  42. +6 βˆ’0 ansi/testdata/TestRendererIssues/117.golden
  43. +5 βˆ’0 ansi/testdata/TestRendererIssues/149.golden
  44. +6 βˆ’0 ansi/testdata/TestRendererIssues/172.golden
  45. +9 βˆ’0 ansi/testdata/TestRendererIssues/237.golden
  46. +9 βˆ’0 ansi/testdata/TestRendererIssues/239.golden
  47. +4 βˆ’0 ansi/testdata/TestRendererIssues/257.golden
  48. +6 βˆ’0 ansi/testdata/TestRendererIssues/290.golden
  49. +17 βˆ’0 ansi/testdata/TestRendererIssues/312.golden
  50. +8 βˆ’0 ansi/testdata/TestRendererIssues/313.golden
  51. +6 βˆ’0 ansi/testdata/TestRendererIssues/315.golden
  52. +7 βˆ’0 ansi/testdata/TestRendererIssues/316.golden
  53. +4 βˆ’4 testdata/issues/42.test β†’ ansi/testdata/TestRendererIssues/42.golden
  54. +8 βˆ’8 testdata/issues/43.test β†’ ansi/testdata/TestRendererIssues/43.golden
  55. +9 βˆ’0 ansi/testdata/TestRendererIssues/44.golden
  56. +4 βˆ’4 testdata/issues/46_1.test β†’ ansi/testdata/TestRendererIssues/46_1.golden
  57. +14 βˆ’0 ansi/testdata/TestRendererIssues/46_2.golden
  58. +1 βˆ’1 testdata/issues/47.test β†’ ansi/testdata/TestRendererIssues/47.golden
  59. +15 βˆ’15 testdata/issues/48.test β†’ ansi/testdata/TestRendererIssues/48.golden
  60. +28 βˆ’0 ansi/testdata/TestRendererIssues/60.golden
  61. +9 βˆ’0 ansi/testdata/TestRendererIssues/79.golden
  62. +68 βˆ’0 examples/artichokes/artichokes.md
  63. +45 βˆ’0 examples/artichokes/main.go
  64. +46 βˆ’0 examples/stdin-stdout-custom-styles/main.go
  65. +46 βˆ’0 examples/stdin-stdout/main.go
  66. +15 βˆ’12 gallery.sh
  67. +11 βˆ’17 glamour.go
  68. +25 βˆ’67 glamour_test.go
  69. +18 βˆ’14 go.mod
  70. +39 βˆ’74 go.sum
  71. +2 βˆ’2 internal/generate-style-json/main.go
  72. +1 βˆ’5 styles/ascii.json
  73. +1 βˆ’5 styles/dark.json
  74. +2 βˆ’4 { β†’ styles}/dracula.go
  75. +1 βˆ’5 styles/dracula.json
  76. +8 βˆ’4 styles/gallery/README.md
  77. BIN styles/gallery/ascii.png
  78. BIN styles/gallery/auto.png
  79. BIN styles/gallery/dark.png
  80. BIN styles/gallery/dracula.png
  81. BIN styles/gallery/light.png
  82. BIN styles/gallery/notty.png
  83. BIN styles/gallery/pink.png
  84. BIN styles/gallery/tokyo-night.png
  85. +1 βˆ’5 styles/light.json
  86. +4 βˆ’8 styles/notty.json
  87. +1 βˆ’5 styles/pink.json
  88. +30 βˆ’27 { β†’ styles}/styles.go
  89. +209 βˆ’0 styles/tokyo-night.go
  90. +182 βˆ’0 styles/tokyo_night.json
  91. +5 βˆ’5 testdata/{capitalization.test β†’ TestCapitalization.golden}
  92. +37 βˆ’38 testdata/{readme.test β†’ TestRenderHelpers.golden}
  93. +39 βˆ’0 testdata/TestTermRenderer.golden
  94. +39 βˆ’0 testdata/TestTermRendererWriter.golden
  95. 0 testdata/{preserved_newline.test β†’ TestWithPreservedNewLines.golden}
  96. +0 βˆ’3 testdata/block_quote.test
  97. +0 βˆ’2 testdata/code_block.test
  98. +0 βˆ’11 testdata/fuzz/fuzz.go
  99. +0 βˆ’3 testdata/heading.test
  100. +14 βˆ’0 testdata/issues/106.md
  101. +4 βˆ’0 testdata/issues/107.md
  102. +3 βˆ’0 testdata/issues/117.md
  103. +3 βˆ’0 testdata/issues/149.md
  104. +3 βˆ’0 testdata/issues/172.md
  105. +3 βˆ’0 testdata/issues/237.md
  106. +5 βˆ’0 testdata/issues/239.md
  107. +3 βˆ’0 testdata/issues/257.md
  108. +3 βˆ’0 testdata/issues/290.md
  109. +15 βˆ’0 testdata/issues/312.md
  110. +5 βˆ’0 testdata/issues/313.md
  111. +3 βˆ’0 testdata/issues/315.md
  112. +4 βˆ’0 testdata/issues/316.md
  113. +0 βˆ’13 testdata/issues/44.test
  114. +0 βˆ’21 testdata/issues/46_2.test
  115. +25 βˆ’0 testdata/issues/60.md
  116. +9 βˆ’0 testdata/issues/79.md
  117. +0 βˆ’5 testdata/table.test
  118. +0 βˆ’5 testdata/table_align.test
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.golden linguist-generated
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @muesli
* @caarlos0 @aymanbagabas
22 changes: 17 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ jobs:
build:
strategy:
matrix:
go-version: [~1.17, ^1]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
@@ -13,13 +12,13 @@ jobs:
COLORFGBG: "7;0"
TERM: "xterm-256color"
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4
go-version: stable

- name: Download Go modules
run: go mod download
@@ -30,3 +29,16 @@ jobs:
- name: Test
run: go test ./...
if: matrix.os != 'windows-latest'

govulncheck:
uses: charmbracelet/meta/.github/workflows/govulncheck.yml@main
with:
go-version: stable

semgrep:
uses: charmbracelet/meta/.github/workflows/semgrep.yml@main

ruleguard:
uses: charmbracelet/meta/.github/workflows/ruleguard.yml@main
with:
go-version: stable
14 changes: 5 additions & 9 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -3,21 +3,17 @@ on: [push, pull_request]

jobs:
coverage:
strategy:
matrix:
go-version: [^1]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
env:
GO111MODULE: "on"
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4
go-version: stable

- name: Coverage
env:
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -13,14 +13,14 @@ jobs:
name: lint-soft
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: ^1
go-version: stable

- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
# Optional: golangci-lint command line arguments.
args: --issues-exit-code=0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cmd/
!*.test
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ linters:
- godot
- godox
- goimports
- gomnd
- mnd
- goprintffuncname
- gosec
- misspell
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -7,3 +7,11 @@ Please submit a pull request for minor changes and submit issues for major chang
## Testing

When providing a new feature or bug fix, please provide tests that demonstrate the issue along with your fix.

## Themes

New styles need to be implemented in `styles/<style-name>.go`, and then `go generate
./...` will create the JSON files from it.

You can look up all references of another theme (e.g. Dracula), and add your
theme accordingly.
57 changes: 45 additions & 12 deletions ansi/baseelement.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ func renderText(w io.Writer, p termenv.Profile, rules StylePrimitive, s string)
}

out := termenv.String(s)

if rules.Upper != nil && *rules.Upper {
out = termenv.String(strings.ToUpper(s))
}
@@ -76,38 +75,72 @@ func renderText(w io.Writer, p termenv.Profile, rules StylePrimitive, s string)
out = out.Blink()
}

_, _ = w.Write([]byte(out.String()))
_, _ = io.WriteString(w, out.String())
}

func (e *BaseElement) StyleOverrideRender(w io.Writer, ctx RenderContext, style StylePrimitive) error {
bs := ctx.blockStack
st1 := cascadeStylePrimitives(bs.Current().Style.StylePrimitive, style)
st2 := cascadeStylePrimitives(bs.With(e.Style), style)

return e.doRender(w, ctx.options.ColorProfile, st1, st2)
}

func (e *BaseElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
st1 := bs.Current().Style.StylePrimitive
st2 := bs.With(e.Style)
return e.doRender(w, ctx.options.ColorProfile, st1, st2)
}

renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, e.Prefix)
func (e *BaseElement) doRender(w io.Writer, p termenv.Profile, st1, st2 StylePrimitive) error {
renderText(w, p, st1, e.Prefix)
defer func() {
renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, e.Suffix)
renderText(w, p, st1, e.Suffix)
}()

rules := bs.With(e.Style)
// render unstyled prefix/suffix
renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
renderText(w, p, st1, st2.BlockPrefix)
defer func() {
renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockSuffix)
renderText(w, p, st1, st2.BlockSuffix)
}()

// render styled prefix/suffix
renderText(w, ctx.options.ColorProfile, rules, rules.Prefix)
renderText(w, p, st2, st2.Prefix)
defer func() {
renderText(w, ctx.options.ColorProfile, rules, rules.Suffix)
renderText(w, p, st2, st2.Suffix)
}()

s := e.Token
if len(rules.Format) > 0 {
if len(st2.Format) > 0 {
var err error
s, err = formatToken(rules.Format, s)
s, err = formatToken(st2.Format, s)
if err != nil {
return err
}
}
renderText(w, ctx.options.ColorProfile, rules, s)
renderText(w, p, st2, escapeReplacer.Replace(s))
return nil
}

// https://www.markdownguide.org/basic-syntax/#characters-you-can-escape
var escapeReplacer = strings.NewReplacer(
"\\\\", "\\",
"\\`", "`",
"\\*", "*",
"\\_", "_",
"\\{", "{",
"\\}", "}",
"\\[", "[",
"\\]", "]",
"\\<", "<",
"\\>", ">",
"\\(", "(",
"\\)", ")",
"\\#", "#",
"\\+", "+",
"\\-", "-",
"\\.", ".",
"\\!", "!",
"\\|", "|",
)
15 changes: 9 additions & 6 deletions ansi/blockelement.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"bytes"
"io"

"github.com/muesli/reflow/wordwrap"
"github.com/charmbracelet/x/ansi"
)

// BlockElement provides a render buffer for children of a block element.
@@ -30,16 +30,19 @@ func (e *BlockElement) Finish(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack

if e.Margin {
s := ansi.Wordwrap(
bs.Current().Block.String(),
int(bs.Width(ctx)),
" ,.;-+|",
)

mw := NewMarginWriter(ctx, w, bs.Current().Style)
_, err := mw.Write(
wordwrap.Bytes(bs.Current().Block.Bytes(), int(bs.Width(ctx))))
if err != nil {
if _, err := io.WriteString(mw, s); err != nil {
return err
}

if e.Newline {
_, err = mw.Write([]byte("\n"))
if err != nil {
if _, err := io.WriteString(mw, "\n"); err != nil {
return err
}
}
4 changes: 2 additions & 2 deletions ansi/blockstack.go
Original file line number Diff line number Diff line change
@@ -59,10 +59,10 @@ func (s BlockStack) Margin() uint {

// Width returns the available rendering width.
func (s BlockStack) Width(ctx RenderContext) uint {
if s.Indent()+s.Margin()*2 > uint(ctx.options.WordWrap) {
if s.Indent()*s.Margin() > uint(ctx.options.WordWrap) {
return 0
}
return uint(ctx.options.WordWrap) - s.Indent() - s.Margin()*2
return uint(ctx.options.WordWrap) - s.Indent()*s.Margin()
}

// Parent returns the current BlockElement's parent.
1 change: 1 addition & 0 deletions ansi/codeblock.go
Original file line number Diff line number Diff line change
@@ -124,6 +124,7 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {

if len(theme) > 0 {
renderText(iw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)

err := quick.Highlight(iw, e.Code, e.Language, "terminal256", theme)
if err != nil {
return err
14 changes: 14 additions & 0 deletions ansi/codespan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ansi

import "io"

// A CodeSpanElement is used to render codespan.
type CodeSpanElement struct {
Text string
Style StylePrimitive
}

func (e *CodeSpanElement) Render(w io.Writer, ctx RenderContext) error {
renderText(w, ctx.options.ColorProfile, e.Style, e.Style.Prefix+e.Text+e.Style.Suffix)
return nil
}
Loading