Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions disco/baller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,35 @@ func (b *Baller) disco(cxt context.Context, doc *asciidoc.Document) error {
}

func (b *Baller) discoBallTopLevelSection(dc *discoContext, top *asciidoc.Section, docType matter.DocType) error {
if b.options.AddXrefstyle {
var xrefstyleEntry *asciidoc.AttributeEntry
var topIndex int = -1

for i, el := range dc.doc.Elements {
if el == top {
topIndex = i
break
}
if ae, ok := el.(*asciidoc.AttributeEntry); ok && ae.Name == "xrefstyle" {
xrefstyleEntry = ae
}
Comment thread
AryaHassanli marked this conversation as resolved.
}

if xrefstyleEntry == nil {
ae := asciidoc.NewAttributeEntry("xrefstyle")
ae.Elements = asciidoc.Elements{asciidoc.NewString("basic")}
if topIndex != -1 {
newElements := make(asciidoc.Elements, 0, len(dc.doc.Elements)+2)
newElements = append(newElements, dc.doc.Elements[:topIndex]...)
newElements = append(newElements, ae, &asciidoc.NewLine{})
newElements = append(newElements, dc.doc.Elements[topIndex:]...)
dc.doc.Elements = newElements
Comment thread
AryaHassanli marked this conversation as resolved.
Outdated
} else {
dc.doc.Elements = append(asciidoc.Elements{ae, &asciidoc.NewLine{}}, dc.doc.Elements...)
}
}
}

if b.options.ReorderSections {
sectionOrder, ok := matter.TopLevelSectionOrders[docType]
if !ok {
Expand Down
2 changes: 2 additions & 0 deletions disco/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type DiscoOptions struct {
NormalizeAnchors bool `default:"false" 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:"`
AddXrefstyle bool `default:"true" aliases:"addXrefstyle" help:"add xrefstyle attribute before the first section" group:"Discoballing:"`
}

var DefaultOptions = DiscoOptions{
Expand All @@ -44,4 +45,5 @@ var DefaultOptions = DiscoOptions{
NormalizeAnchors: false,
RemoveMandatoryFallbacks: true,
RenameSections: false,
AddXrefstyle: true,
}
Loading