Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions disco/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type DiscoOptions struct {
RemoveExtraSpaces bool `default:"true" aliases:"removeExtraSpaces" help:"remove extraneous spaces" group:"Discoballing:"`
NormalizeFeatureNames bool `default:"true" aliases:"normalizeFeatureNames" help:"correct invalid feature names" group:"Discoballing:"`
DisambiguateConformanceChoice bool `default:"true" aliases:"disambiguateConformanceChoice" help:"ensure conformance choices are only used once per document" group:"Discoballing:"`
NormalizeAnchors bool `default:"false" aliases:"normalizeAnchors" help:"rewrite anchors and references without labels" group:"Discoballing:"`
NormalizeAnchors bool `default:"true" aliases:"normalizeAnchors" help:"rewrite anchors and references without labels" group:"Discoballing:"`
RemoveMandatoryFallbacks bool `default:"true" aliases:"removeMandatoryFallbacks" help:"remove fallback values for mandatory fields" group:"Discoballing:"`
RenameSections bool `default:"false" help:"rename sections to disco-ball standard names" group:"Discoballing:"`
XrefStyleOnlyInRoot bool `default:"true" aliases:"xrefStyleOnlyInRoot" help:"enforce xrefstyle: basic only in root" group:"Discoballing:"`
Expand All @@ -42,7 +42,7 @@ var DefaultOptions = DiscoOptions{
RemoveExtraSpaces: true,
NormalizeFeatureNames: true,
DisambiguateConformanceChoice: true,
NormalizeAnchors: false,
NormalizeAnchors: true,
RemoveMandatoryFallbacks: true,
RenameSections: false,
XrefStyleOnlyInRoot: true,
Expand Down
19 changes: 15 additions & 4 deletions disco/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ func (an AnchorNormalizer) rewriteCrossReferences(doc *asciidoc.Document) {
}
continue
}
anchorLabel := labelText(anchor.LabelElements)
var anchorLabel string
if an.options.NormalizeAnchors {
if _, isSection := anchor.Element.(*asciidoc.Section); isSection {
anchorLabel = library.SectionName(anchor.Element.(*asciidoc.Section))
}
}
if anchorLabel == "" {
section, isSection := anchor.Element.(*asciidoc.Section)
if isSection {
anchorLabel = library.SectionName(section)
anchorLabel = labelText(anchor.LabelElements)
if anchorLabel == "" {
section, isSection := anchor.Element.(*asciidoc.Section)
if isSection {
anchorLabel = library.SectionName(section)
}
}
}
Comment thread
AryaHassanli marked this conversation as resolved.
// We're going to be modifying the underlying array, so we need to make a copy of the slice
Expand Down Expand Up @@ -96,6 +104,9 @@ func (an AnchorNormalizer) rewriteCrossReferences(doc *asciidoc.Document) {
}

func removeCrossReferenceStutter(library *spec.Library, doc *asciidoc.Document, icr *asciidoc.CrossReference, parent asciidoc.Parent, index int) {
if parent == nil {
return
}
if len(icr.Elements) > 0 {
return
}
Expand Down
Loading