mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
Include space parameter as well
This commit is contained in:
parent
21cf51efd7
commit
9840c01e8a
14
main.go
14
main.go
@ -181,7 +181,7 @@ func processFile(
|
|||||||
|
|
||||||
markdown = bytes.ReplaceAll(markdown, []byte("\r\n"), []byte("\n"))
|
markdown = bytes.ReplaceAll(markdown, []byte("\r\n"), []byte("\n"))
|
||||||
|
|
||||||
meta, markdown, err := mark.ExtractMeta(markdown, flags.TitleFromH1)
|
meta, markdown, err := mark.ExtractMeta(markdown, flags.Space, flags.TitleFromH1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -204,13 +204,9 @@ func processFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if meta.Space == "" {
|
if meta.Space == "" {
|
||||||
if flags.Space == "" {
|
log.Fatal(
|
||||||
log.Fatal(
|
"space is not set ('Space' header is not set and '--space' option is not set)",
|
||||||
"space is not set ('Space' header is not set and '--space' option is not set)",
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
meta.Space = flags.Space
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Title == "" {
|
if meta.Title == "" {
|
||||||
@ -262,7 +258,7 @@ func processFile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
links, err := mark.ResolveRelativeLinks(api, meta, markdown, filepath.Dir(file), flags.TitleFromH1)
|
links, err := mark.ResolveRelativeLinks(api, meta, markdown, filepath.Dir(file), flags.Space, flags.TitleFromH1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf(err, "unable to resolve relative links")
|
log.Fatalf(err, "unable to resolve relative links")
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ func ResolveRelativeLinks(
|
|||||||
meta *Meta,
|
meta *Meta,
|
||||||
markdown []byte,
|
markdown []byte,
|
||||||
base string,
|
base string,
|
||||||
|
spaceFromCli string,
|
||||||
titleFromH1 bool,
|
titleFromH1 bool,
|
||||||
) ([]LinkSubstitution, error) {
|
) ([]LinkSubstitution, error) {
|
||||||
matches := parseLinks(string(markdown))
|
matches := parseLinks(string(markdown))
|
||||||
@ -43,7 +44,7 @@ func ResolveRelativeLinks(
|
|||||||
match.hash,
|
match.hash,
|
||||||
)
|
)
|
||||||
|
|
||||||
resolved, err := resolveLink(api, base, match, titleFromH1)
|
resolved, err := resolveLink(api, base, match, spaceFromCli, titleFromH1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, karma.Format(err, "resolve link: %q", match.full)
|
return nil, karma.Format(err, "resolve link: %q", match.full)
|
||||||
}
|
}
|
||||||
@ -65,6 +66,7 @@ func resolveLink(
|
|||||||
api *confluence.API,
|
api *confluence.API,
|
||||||
base string,
|
base string,
|
||||||
link markdownLink,
|
link markdownLink,
|
||||||
|
spaceFromCli string,
|
||||||
titleFromH1 bool,
|
titleFromH1 bool,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
var result string
|
var result string
|
||||||
@ -95,7 +97,7 @@ func resolveLink(
|
|||||||
|
|
||||||
// This helps to determine if found link points to file that's
|
// This helps to determine if found link points to file that's
|
||||||
// not markdown or have mark required metadata
|
// not markdown or have mark required metadata
|
||||||
linkMeta, _, err := ExtractMeta(linkContents, titleFromH1)
|
linkMeta, _, err := ExtractMeta(linkContents, spaceFromCli, titleFromH1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(
|
log.Errorf(
|
||||||
err,
|
err,
|
||||||
|
@ -46,7 +46,7 @@ var (
|
|||||||
reHeaderPatternMacro = regexp.MustCompile(`<!-- Macro: .*`)
|
reHeaderPatternMacro = regexp.MustCompile(`<!-- Macro: .*`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExtractMeta(data []byte, titleFromH1 bool) (*Meta, []byte, error) {
|
func ExtractMeta(data []byte, spaceFromCli string, titleFromH1 bool) (*Meta, []byte, error) {
|
||||||
var (
|
var (
|
||||||
meta *Meta
|
meta *Meta
|
||||||
offset int
|
offset int
|
||||||
@ -146,7 +146,7 @@ func ExtractMeta(data []byte, titleFromH1 bool) (*Meta, []byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if titleFromH1 {
|
if titleFromH1 || spaceFromCli != "" {
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
meta = &Meta{}
|
meta = &Meta{}
|
||||||
}
|
}
|
||||||
@ -159,9 +159,12 @@ func ExtractMeta(data []byte, titleFromH1 bool) (*Meta, []byte, error) {
|
|||||||
meta.ContentAppearance = FullWidthContentAppearance // Default to full-width for backwards compatibility
|
meta.ContentAppearance = FullWidthContentAppearance // Default to full-width for backwards compatibility
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta.Title == "" {
|
if titleFromH1 && meta.Title == "" {
|
||||||
meta.Title = ExtractDocumentLeadingH1(data)
|
meta.Title = ExtractDocumentLeadingH1(data)
|
||||||
}
|
}
|
||||||
|
if spaceFromCli != "" && meta.Space == "" {
|
||||||
|
meta.Space = spaceFromCli
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if meta == nil {
|
if meta == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user