зеркало из https://github.com/golang/build.git
relnote: merge link references
Merge the link references of all the markdown documents into a single map. Return an error on duplicate keys. For golang/go#64169. Change-Id: I45ce5e77084e030521ba79f463c0796d417b07d8 Reviewed-on: https://go-review.googlesource.com/c/build/+/556161 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Родитель
fdfdde09a1
Коммит
ec85f02c43
|
@ -151,34 +151,47 @@ func Merge(fsys fs.FS) (*md.Document, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc := &md.Document{}
|
||||
doc := &md.Document{Links: map[string]*md.Link{}}
|
||||
for _, filename := range filenames {
|
||||
fd, err := parseFile(fsys, filename)
|
||||
newdoc, err := parseFile(fsys, filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(fd.Blocks) == 0 {
|
||||
if len(newdoc.Blocks) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(doc.Blocks) > 0 {
|
||||
// Put a blank line between the current and new blocks.
|
||||
lastLine := lastBlock(doc).Pos().EndLine
|
||||
delta := lastLine + 2 - fd.Blocks[0].Pos().StartLine
|
||||
for _, b := range fd.Blocks {
|
||||
delta := lastLine + 2 - newdoc.Blocks[0].Pos().StartLine
|
||||
for _, b := range newdoc.Blocks {
|
||||
addLines(b, delta)
|
||||
}
|
||||
}
|
||||
// Append non-empty blocks to the result document.
|
||||
for _, b := range fd.Blocks {
|
||||
for _, b := range newdoc.Blocks {
|
||||
if _, ok := b.(*md.Empty); !ok {
|
||||
doc.Blocks = append(doc.Blocks, b)
|
||||
}
|
||||
}
|
||||
// TODO(jba): merge links
|
||||
// Merge link references.
|
||||
for key, link := range newdoc.Links {
|
||||
if doc.Links[key] != nil {
|
||||
return nil, fmt.Errorf("duplicate link reference %q; second in %s", key, filename)
|
||||
}
|
||||
doc.Links[key] = link
|
||||
}
|
||||
// TODO(jba): add headings for package sections under "Minor changes to the library".
|
||||
}
|
||||
// Remove headings with empty contents.
|
||||
doc.Blocks = removeEmptySections(doc.Blocks)
|
||||
if len(doc.Blocks) > 0 && len(doc.Links) > 0 {
|
||||
// Add a blank line to separate the links.
|
||||
lastPos := doc.Blocks[len(doc.Blocks)-1].Pos()
|
||||
lastPos.StartLine += 2
|
||||
lastPos.EndLine += 2
|
||||
doc.Blocks = append(doc.Blocks, &md.Empty{Position: lastPos})
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
-- f1.md --
|
||||
First.
|
||||
|
||||
Second.
|
||||
|
||||
[a]: u1
|
||||
[b]: u2
|
||||
-- f2.md --
|
||||
Third.
|
||||
|
||||
[c]: u3
|
||||
[d]: u4
|
||||
-- want --
|
||||
First.
|
||||
|
||||
Second.
|
||||
|
||||
Third.
|
||||
|
||||
[a]: u1
|
||||
[b]: u2
|
||||
[c]: u3
|
||||
[d]: u4
|
Загрузка…
Ссылка в новой задаче