mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-14 06:07:36 +08:00
feat: throw errors instead of passing unknown aligns through
This commit is contained in:
parent
99dbcd9383
commit
ec6a718c76
@ -133,15 +133,7 @@ func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool, titleFromFi
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HeaderImageAlign:
|
case HeaderImageAlign:
|
||||||
align := strings.ToLower(strings.TrimSpace(value))
|
meta.ImageAlign = strings.ToLower(strings.TrimSpace(value))
|
||||||
if align != "left" && align != "center" && align != "right" {
|
|
||||||
log.Warningf(
|
|
||||||
nil,
|
|
||||||
`unknown image alignment %q, expected one of: left, center, right; passing through to Confluence`,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
meta.ImageAlign = align
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
|
|||||||
37
util/cli.go
37
util/cli.go
@ -217,13 +217,19 @@ func processFile(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageAlign, err := getImageAlign(cmd, meta)
|
||||||
|
if err != nil {
|
||||||
|
fatalErrorHandler.Handle(err, "unable to determine image-align")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
cfg := types.MarkConfig{
|
cfg := types.MarkConfig{
|
||||||
MermaidScale: cmd.Float("mermaid-scale"),
|
MermaidScale: cmd.Float("mermaid-scale"),
|
||||||
D2Scale: cmd.Float("d2-scale"),
|
D2Scale: cmd.Float("d2-scale"),
|
||||||
DropFirstH1: cmd.Bool("drop-h1"),
|
DropFirstH1: cmd.Bool("drop-h1"),
|
||||||
StripNewlines: cmd.Bool("strip-linebreaks"),
|
StripNewlines: cmd.Bool("strip-linebreaks"),
|
||||||
Features: cmd.StringSlice("features"),
|
Features: cmd.StringSlice("features"),
|
||||||
ImageAlign: getImageAlign(cmd, meta),
|
ImageAlign: imageAlign,
|
||||||
}
|
}
|
||||||
html, _ := mark.CompileMarkdown(markdown, stdlib, file, cfg)
|
html, _ := mark.CompileMarkdown(markdown, stdlib, file, cfg)
|
||||||
fmt.Println(html)
|
fmt.Println(html)
|
||||||
@ -297,13 +303,19 @@ func processFile(
|
|||||||
"the leading H1 heading will be excluded from the Confluence output",
|
"the leading H1 heading will be excluded from the Confluence output",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageAlign, err := getImageAlign(cmd, meta)
|
||||||
|
if err != nil {
|
||||||
|
fatalErrorHandler.Handle(err, "unable to determine image-align")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
cfg := types.MarkConfig{
|
cfg := types.MarkConfig{
|
||||||
MermaidScale: cmd.Float("mermaid-scale"),
|
MermaidScale: cmd.Float("mermaid-scale"),
|
||||||
D2Scale: cmd.Float("d2-scale"),
|
D2Scale: cmd.Float("d2-scale"),
|
||||||
DropFirstH1: cmd.Bool("drop-h1"),
|
DropFirstH1: cmd.Bool("drop-h1"),
|
||||||
StripNewlines: cmd.Bool("strip-linebreaks"),
|
StripNewlines: cmd.Bool("strip-linebreaks"),
|
||||||
Features: cmd.StringSlice("features"),
|
Features: cmd.StringSlice("features"),
|
||||||
ImageAlign: getImageAlign(cmd, meta),
|
ImageAlign: imageAlign,
|
||||||
}
|
}
|
||||||
|
|
||||||
html, inlineAttachments := mark.CompileMarkdown(markdown, stdlib, file, cfg)
|
html, inlineAttachments := mark.CompileMarkdown(markdown, stdlib, file, cfg)
|
||||||
@ -476,26 +488,25 @@ func determineLabelsToAdd(meta *metadata.Meta, labelInfo *confluence.LabelInfo)
|
|||||||
return labels
|
return labels
|
||||||
}
|
}
|
||||||
|
|
||||||
func getImageAlign(cmd *cli.Command, meta *metadata.Meta) string {
|
func getImageAlign(cmd *cli.Command, meta *metadata.Meta) (string, error) {
|
||||||
// Header comment takes precedence over CLI flag
|
// Header comment takes precedence over CLI flag
|
||||||
|
align := cmd.String("image-align")
|
||||||
if meta != nil && meta.ImageAlign != "" {
|
if meta != nil && meta.ImageAlign != "" {
|
||||||
return meta.ImageAlign
|
align = meta.ImageAlign
|
||||||
}
|
}
|
||||||
|
|
||||||
cliAlign := cmd.String("image-align")
|
if align != "" {
|
||||||
if cliAlign != "" {
|
align = strings.ToLower(strings.TrimSpace(align))
|
||||||
align := strings.ToLower(strings.TrimSpace(cliAlign))
|
|
||||||
if align != "left" && align != "center" && align != "right" {
|
if align != "left" && align != "center" && align != "right" {
|
||||||
log.Warningf(
|
return "", fmt.Errorf(
|
||||||
nil,
|
`unknown image-align %q, expected one of: left, center, right`,
|
||||||
"unknown --image-align value %q, expected one of: left, center, right; passing through to Confluence",
|
align,
|
||||||
cliAlign,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return align
|
return align, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigFilePath() string {
|
func ConfigFilePath() string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user