mirror of
https://github.com/kovetskiy/mark.git
synced 2026-05-03 05:42:35 +00:00
feat: add 'default' as valid Content-Appearance value
This commit is contained in:
committed by
Manuel Rüger
parent
13e7b496ee
commit
7fab1755d6
@@ -46,6 +46,7 @@ type Meta struct {
|
||||
const (
|
||||
FullWidthContentAppearance = "full-width"
|
||||
FixedContentAppearance = "fixed"
|
||||
DefaultContentAppearance = "default"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -122,9 +123,12 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi
|
||||
continue
|
||||
|
||||
case ContentAppearance:
|
||||
if strings.TrimSpace(value) == FixedContentAppearance {
|
||||
switch strings.TrimSpace(value) {
|
||||
case FixedContentAppearance:
|
||||
meta.ContentAppearance = FixedContentAppearance
|
||||
} else {
|
||||
case DefaultContentAppearance:
|
||||
meta.ContentAppearance = DefaultContentAppearance
|
||||
default:
|
||||
meta.ContentAppearance = FullWidthContentAppearance
|
||||
}
|
||||
|
||||
@@ -166,9 +170,12 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi
|
||||
|
||||
// Use the global content appearance flag if the header is not set in the document
|
||||
if meta != nil && defaultContentAppearance != "" && meta.ContentAppearance == "" {
|
||||
if strings.TrimSpace(defaultContentAppearance) == FixedContentAppearance {
|
||||
switch strings.TrimSpace(defaultContentAppearance) {
|
||||
case FixedContentAppearance:
|
||||
meta.ContentAppearance = FixedContentAppearance
|
||||
} else {
|
||||
case DefaultContentAppearance:
|
||||
meta.ContentAppearance = DefaultContentAppearance
|
||||
default:
|
||||
meta.ContentAppearance = FullWidthContentAppearance
|
||||
}
|
||||
} else if meta != nil && meta.ContentAppearance == "" {
|
||||
|
||||
@@ -88,4 +88,22 @@ func TestExtractMetaContentAppearance(t *testing.T) {
|
||||
assert.NotNil(t, meta)
|
||||
assert.Equal(t, FullWidthContentAppearance, meta.ContentAppearance)
|
||||
})
|
||||
|
||||
t.Run("default appearance via cli flag", func(t *testing.T) {
|
||||
data := []byte("<!-- Space: DOC -->\n<!-- Title: Example -->\n\nbody\n")
|
||||
|
||||
meta, _, err := ExtractMeta(data, "", false, false, "", nil, false, DefaultContentAppearance)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, meta)
|
||||
assert.Equal(t, DefaultContentAppearance, meta.ContentAppearance)
|
||||
})
|
||||
|
||||
t.Run("default appearance via header", func(t *testing.T) {
|
||||
data := []byte("<!-- Space: DOC -->\n<!-- Title: Example -->\n<!-- Content-Appearance: default -->\n\nbody\n")
|
||||
|
||||
meta, _, err := ExtractMeta(data, "", false, false, "", nil, false, "")
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, meta)
|
||||
assert.Equal(t, DefaultContentAppearance, meta.ContentAppearance)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user