Skip to content

Commit

Permalink
markup/goldmark: Change default cell alignment in table render hook
Browse files Browse the repository at this point in the history
Change the default table cell alignment from "left" to an empty string.

Closes #12886
  • Loading branch information
jmooring authored and bep committed Sep 30, 2024
1 parent d1ba52f commit 1158e63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion markup/goldmark/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (r *htmlRenderer) renderCell(w util.BufWriter, source []byte, node ast.Node
case gast.AlignCenter:
alignment = "center"
default:
alignment = "left"
alignment = ""
}

cell := hooks.TableCell{Text: hstring.HTML(text), Alignment: alignment}
Expand Down
6 changes: 3 additions & 3 deletions markup/goldmark/tables/tables_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ title = true
| Item | In Stock | Price |
| :---------------- | :------: | ----: |
| Python Hat | True | 23.99 |
| SQL **Hat** | True | 23.99 |
| SQL **Hat** | True | 23.99 |
| Codecademy Tee | False | 19.99 |
| Codecademy Hoodie | False | 42.99 |
{.foo foo="bar"}
Expand Down Expand Up @@ -65,8 +65,8 @@ Attributes: {{ .Attributes }}|
)

b.AssertFileContent("public/p1/index.html",
"table-1-thead: 0: 0: left: Month| 1: left: Savings|$",
"table-1-tbody: 0: 0: left: January| 1: left: $250| 1: 0: left: February| 1: left: $80| 2: 0: left: March| 1: left: $420|$",
"table-1-thead: 0: 0: : Month| 1: : Savings|$",
"table-1-tbody: 0: 0: : January| 1: : $250| 1: 0: : February| 1: : $80| 2: 0: : March| 1: : $420|$",
)
}

Expand Down
12 changes: 10 additions & 2 deletions tpl/tplimpl/embedded/templates/_default/_markup/render-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
{{- range .THead }}
<tr>
{{- range . }}
<th {{ printf "style=%q" (printf "text-align: %s" .Alignment) | safeHTMLAttr }}>
<th
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
{{- end -}}
>
{{- .Text -}}
</th>
{{- end }}
Expand All @@ -19,7 +23,11 @@
{{- range .TBody }}
<tr>
{{- range . }}
<td {{ printf "style=%q" (printf "text-align: %s" .Alignment) | safeHTMLAttr }}>
<td
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
{{- end -}}
>
{{- .Text -}}
</td>
{{- end }}
Expand Down

0 comments on commit 1158e63

Please sign in to comment.