Skip to content

Commit 47f0d19

Browse files
authored
Allow Cross Reference Suffix (#180)
* Allow Cross Reference Suffix this allows setting the format attribute in a reference. Waiting for gomarkdown/markdown#260 Signed-off-by: Miek Gieben <[email protected]> * Update to latest markdown and fix code a little Signed-off-by: Miek Gieben <[email protected]> * Add test Signed-off-by: Miek Gieben <[email protected]> Signed-off-by: Miek Gieben <[email protected]>
1 parent 069695c commit 47f0d19

File tree

7 files changed

+62
-5
lines changed

7 files changed

+62
-5
lines changed

Syntax.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,25 @@ or
671671

672672
And then reference the same `(#myid)`, the formatter (`xml2rfc`) will do the right thing.
673673

674+
#### Cross Reference Text Suffixes
675+
676+
Just like [](#reference-text-suffices), you can add a suffix text to a reference, to influence how
677+
xml2rfc will render it, see <https://www.rfc-editor.org/materials/FAQ-xml2rfcv3.html#section-3.11>
678+
it will allow you to set the format attribute. The following is supported:
679+
680+
* counter
681+
* title
682+
* default
683+
684+
* `(#myid, use counter)` -> format="counter"
685+
* `(#myid, use title)` -> format="title"
686+
687+
Translation of these strings _is_ supported for a few languages, `(#myid, gebruik titel)` (Dutch) is
688+
supported for instance.
689+
690+
Also note these strings need to be literary typed as shown here (we may become more lenient in the
691+
future).
692+
674693
### Super- and Subscript
675694

676695
For superscript use `^` and for subscripts use `~`. For example:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ go 1.13
44

55
require (
66
github.com/BurntSushi/toml v1.2.0
7-
github.com/gomarkdown/markdown v0.0.0-20220825072242-90efaac57fb4
7+
github.com/gomarkdown/markdown v0.0.0-20220830015526-01a3c37d6f50
88
github.com/google/go-cmp v0.2.0
99
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0
22
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
33
github.com/gomarkdown/markdown v0.0.0-20220825072242-90efaac57fb4 h1:YOfiTywt9f60GzIFrnor09U0Q3PySmqnyIqvK0o6fzI=
44
github.com/gomarkdown/markdown v0.0.0-20220825072242-90efaac57fb4/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
5+
github.com/gomarkdown/markdown v0.0.0-20220830015526-01a3c37d6f50 h1:tSuUky4sFWjiIIEOefDDBjx5BUIT3kZwcXHM2CNDdTk=
6+
github.com/gomarkdown/markdown v0.0.0-20220830015526-01a3c37d6f50/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
57
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
68
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

lang/lang.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ func New(language string) Lang {
2020
WrittenBy: "Written by",
2121
See: "see",
2222
Section: "section",
23+
UseCounter: "use counter",
24+
UseTitle: "use title",
2325
},
2426
"nl": {
27+
And: "en",
2528
Bibliography: "Bibliografie",
2629
Footnotes: "Voetnoten",
2730
Index: "Index",
2831
See: "zie",
2932
Section: "sectie",
33+
UseCounter: "gebruik nummer",
34+
UseTitle: "gebruik titel",
3035
},
3136
"de": {
37+
And: "und",
3238
Bibliography: "Literaturverzeichnis",
3339
Footnotes: "Fußnoten",
3440
Index: "Index",
@@ -71,9 +77,11 @@ type Term struct {
7177
Index string
7278
WrittenBy string
7379

74-
// The references
75-
See string
76-
Section string
80+
// for cross references
81+
See string
82+
Section string
83+
UseCounter string
84+
UseTitle string
7785
}
7886

7987
func (l Lang) Footnotes() string {
@@ -139,3 +147,19 @@ func (l Lang) Section() string {
139147
}
140148
return t.Section
141149
}
150+
151+
func (l Lang) UseCounter() string {
152+
t, ok := l.m[l.language]
153+
if !ok {
154+
return l.m["en"].UseCounter
155+
}
156+
return t.UseCounter
157+
}
158+
159+
func (l Lang) UseTitle() string {
160+
t, ok := l.m[l.language]
161+
if !ok {
162+
return l.m["en"].UseTitle
163+
}
164+
return t.UseTitle
165+
}

render/xml/renderer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,17 @@ func (r *Renderer) callout(w io.Writer, callout *ast.Callout) {
567567

568568
func (r *Renderer) crossReference(w io.Writer, cr *ast.CrossReference, entering bool) {
569569
if entering {
570-
r.outTag(w, "<xref", []string{"target=\"" + string(cr.Destination) + "\""})
570+
attr := []string{fmt.Sprintf(`target="%s"`, cr.Destination)}
571+
if len(cr.Suffix) > 0 {
572+
switch {
573+
case string(cr.Suffix) == r.opts.Language.UseCounter():
574+
attr = append(attr, `format="counter"`)
575+
576+
case string(cr.Suffix) == r.opts.Language.UseTitle():
577+
attr = append(attr, `format="title"`)
578+
}
579+
}
580+
r.outTag(w, "<xref", attr)
571581
return
572582
}
573583
r.outs(w, "</xref>")

testdata/ref.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See (#myid, use counter), to check.

testdata/ref.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<t>See <xref target="myid" format="counter"></xref>, to check.</t>

0 commit comments

Comments
 (0)