Repository navigation
Expand file tree
/
Copy pathexample_test.go
More file actions
115 lines (103 loc) · 3.66 KB
/
Copy pathexample_test.go
File metadata and controls
115 lines (103 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package crossrefapi_test
import (
"fmt"
"os"
"github.com/caltechlibrary/crossrefapi"
)
func ExamplePlainText() {
// Publishers indent their markup; the newline and spaces are layout, not text.
title, warnings := crossrefapi.PlainText("<i>Euclid</i>\n preparation")
fmt.Println(title, len(warnings))
// Output: Euclid preparation 0
}
func ExamplePlainText_scripts() {
title, _ := crossrefapi.PlainText("Irradiation of H\n <sub>2</sub>\n O:NH\n <sub>3</sub>\n :CO ices")
fmt.Println(title)
// Output: Irradiation of H₂O:NH₃:CO ices
}
func ExamplePlainText_formula() {
const mathML = `a loop model with<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">` +
`<mml:mn>1</mml:mn><mml:mo>/</mml:mo><mml:msup><mml:mi>r</mml:mi><mml:mn>2</mml:mn></mml:msup>` +
`</mml:math>current-current interactions`
title, _ := crossrefapi.PlainText(mathML)
fmt.Println(title)
// Output: a loop model with 1/r² current-current interactions
}
func ExamplePlainText_warning() {
// Unicode has no subscript N, so the formula is written in a linear form
// and a warning says so.
const mathML = `with <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML">` +
`<mml:msub><mml:mi>Z</mml:mi><mml:mi>N</mml:mi></mml:msub></mml:math> symmetry`
title, warnings := crossrefapi.PlainText(mathML)
fmt.Println(title)
for _, w := range warnings {
fmt.Println(w)
}
// Output:
// with Z_N symmetry
// math-linear: Z_N
}
func ExampleHTMLAbstract() {
html, warnings := crossrefapi.HTMLAbstract(
"<jats:title>Abstract</jats:title>\n <jats:p>Water is H<jats:sub>2</jats:sub>O.</jats:p>")
fmt.Println(html, len(warnings))
// Output: <p>Water is H<sub>2</sub>O.</p> 0
}
func ExampleHTMLAbstract_formula() {
const abstract = `<jats:p>The <jats:italic>Euclid</jats:italic> mission, with ` +
`<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>J</mml:mi><mml:mo>/</mml:mo>` +
`<mml:mi>ψ</mml:mi></mml:math> data.</jats:p>`
html, _ := crossrefapi.HTMLAbstract(abstract)
fmt.Println(html)
// Output: <p>The <i>Euclid</i> mission, with \(J/\psi\) data.</p>
}
func ExampleMessage_FullTitle() {
msg := &crossrefapi.Message{
Title: []string{"<i>Euclid</i>\n preparation"},
SubTitle: []string{"CII. Non-Gaussianity of two-point statistics likelihood"},
}
title, _ := msg.FullTitle()
fmt.Println(title)
// Output: Euclid preparation: CII. Non-Gaussianity of two-point statistics likelihood
}
func ExampleMessage_AlternateTitles() {
msg := &crossrefapi.Message{
Title: []string{"X-chromosomale juvenile Retinoschisis", "X-linked juvenile retinoschisis"},
}
// FullTitle uses the first title and reports the others...
title, warnings := msg.FullTitle()
fmt.Println(title)
fmt.Println(warnings[0])
// ...and AlternateTitles returns them.
others, _ := msg.AlternateTitles()
fmt.Println(others)
// Output:
// X-chromosomale juvenile Retinoschisis
// multiple-titles: X-linked juvenile retinoschisis
// [X-linked juvenile retinoschisis]
}
func ExampleNewNormalizer() {
// An override file adds to or replaces entries in the default table. This one
// stops the "Abstract" heading from being dropped.
f, err := os.CreateTemp("", "symbols-*.json")
if err != nil {
fmt.Println(err)
return
}
defer os.Remove(f.Name())
f.WriteString(`{"dropped_headings": []}`)
f.Close()
n, err := crossrefapi.NewNormalizer(f.Name())
if err != nil {
fmt.Println(err)
return
}
const abstract = "<jats:title>Abstract</jats:title><jats:p>Text.</jats:p>"
withOverride, _ := n.HTMLAbstract(abstract)
withDefault, _ := crossrefapi.HTMLAbstract(abstract)
fmt.Println(withOverride)
fmt.Println(withDefault)
// Output:
// <p><b>Abstract</b></p><p>Text.</p>
// <p>Text.</p>
}