File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -133,6 +133,34 @@ func (b *Baller) disco(cxt context.Context, doc *asciidoc.Document) error {
133133}
134134
135135func (b * Baller ) discoBallTopLevelSection (dc * discoContext , top * asciidoc.Section , docType matter.DocType ) error {
136+ if b .options .AddXrefstyle {
137+ var xrefstyleEntry * asciidoc.AttributeEntry
138+ var topIndex int = - 1
139+
140+ for i , el := range dc .doc .Elements {
141+ if el == top {
142+ topIndex = i
143+ break
144+ }
145+ if ae , ok := el .(* asciidoc.AttributeEntry ); ok && ae .Name == "xrefstyle" {
146+ xrefstyleEntry = ae
147+ }
148+ }
149+
150+ if xrefstyleEntry == nil {
151+ ae := asciidoc .NewAttributeEntry ("xrefstyle" )
152+ ae .Elements = asciidoc.Elements {asciidoc .NewString ("basic" )}
153+ if topIndex != - 1 {
154+ dc .doc .Elements = append (dc .doc .Elements , nil , nil )
155+ copy (dc .doc .Elements [topIndex + 2 :], dc .doc .Elements [topIndex :])
156+ dc .doc .Elements [topIndex ] = ae
157+ dc .doc .Elements [topIndex + 1 ] = & asciidoc.NewLine {}
158+ } else {
159+ dc .doc .Elements = append (asciidoc.Elements {ae , & asciidoc.NewLine {}}, dc .doc .Elements ... )
160+ }
161+ }
162+ }
163+
136164 if b .options .ReorderSections {
137165 sectionOrder , ok := matter .TopLevelSectionOrders [docType ]
138166 if ! ok {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type DiscoOptions struct {
2222 NormalizeAnchors bool `default:"false" aliases:"normalizeAnchors" help:"rewrite anchors and references without labels" group:"Discoballing:"`
2323 RemoveMandatoryFallbacks bool `default:"true" aliases:"removeMandatoryFallbacks" help:"remove fallback values for mandatory fields" group:"Discoballing:"`
2424 RenameSections bool `default:"false" help:"rename sections to disco-ball standard names" group:"Discoballing:"`
25+ AddXrefstyle bool `default:"true" aliases:"addXrefstyle" help:"add xrefstyle attribute before the first section" group:"Discoballing:"`
2526}
2627
2728var DefaultOptions = DiscoOptions {
@@ -44,4 +45,5 @@ var DefaultOptions = DiscoOptions{
4445 NormalizeAnchors : false ,
4546 RemoveMandatoryFallbacks : true ,
4647 RenameSections : false ,
48+ AddXrefstyle : true ,
4749}
You can’t perform that action at this time.
0 commit comments