Repository: gohugoio/hugo (language: go)

Issue:
Markdown render hook for tables doesn't recognize unset column alignment
As of [v0.134.0](https://github.com/gohugoio/hugo/releases/tag/v0.134.0) (via #12809), [Markdown render hooks for tables](https://gohugo.io/render-hooks/tables/) are supported.

While there are **four possible [column alignment syntaxes](https://www.markdownguide.org/extended-syntax/#alignment)** (see the table below), only three are reported: the `---` (unset) syntax isn't recognized as distinct from left alignment `:---`.

When rendered, a cell from an unset column should have **no `text-align` style** set, but unfortunately, the following hook override fragment won't work:

```liquid
{{- range . }}
  <th
    {{- with .Alignment -}}
      {{ printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
    {{- end -}}
    >
    {{- .Text | safeHTML -}}
  </th>
{{- end }}
```

References:

- #9316
- #12809

| Column alignment | Syntax |
--- | --- 
**Unset** | `-----`
Left | `:----`
Right | `----:`
Centered | `:---:`





Discussion / hints:
Goldmark handles this as expected (see [playground example](https://yuin.github.io/goldmark/playground/?m=a%257Cb%257Cc%257Cd%250A---%257C%253A--%257C%253A-%253A%257C--%253A%250A1%257C2%257C3%257C4%250A%250A&o=1&v=v1.7.4)).

We should set the default to an empty string.

https://github.com/gohugoio/hugo/blob/d0dca656250d0a04f3a5051ec067022df4b37738/markup/goldmark/tables/tables.go#L123-L133
>We should set the default to an empty string.

Agree.

Fix patch:
diff --git a/markup/goldmark/tables/tables.go b/markup/goldmark/tables/tables.go
index 0aa6ee26947..a7dfb8ee6ed 100644
--- a/markup/goldmark/tables/tables.go
+++ b/markup/goldmark/tables/tables.go
@@ -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}
diff --git a/tpl/tplimpl/embedded/templates/_default/_markup/render-table.html b/tpl/tplimpl/embedded/templates/_default/_markup/render-table.html
index a0b0cc34d4c..5fdd79ddb9a 100644
--- a/tpl/tplimpl/embedded/templates/_default/_markup/render-table.html
+++ b/tpl/tplimpl/embedded/templates/_default/_markup/render-table.html
@@ -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 }}
@@ -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 }}


Test patch:
diff --git a/markup/goldmark/tables/tables_integration_test.go b/markup/goldmark/tables/tables_integration_test.go
index dadce5c81fe..85cf81c9d04 100644
--- a/markup/goldmark/tables/tables_integration_test.go
+++ b/markup/goldmark/tables/tables_integration_test.go
@@ -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"}
@@ -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|$",
 	)
 }