[Golang] Wrap Pāli Words in Span Element


Wrap Pāli words in span element via regular expression and Golang (Go programming language).

Source code:

Run Code on Go Playground

pali.go | repository | view raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
package wrappali

import "regexp"

var paliWord = regexp.MustCompile(`[AaBbCcDdEeGgHhIiJjKkLlMmNnOoPpRrSsTtUuVvYyĀāĪīŪūṀṁṂṃŊŋṆṇṄṅÑñṬṭḌḍḶḷ]+`)

func WrapPaliWordsInSpan(html string) string {
	return paliWord.ReplaceAllStringFunc(html, func(match string) string {
		return "<span>" + match + "</span>"
	})
}
pali_test.go | repository | view raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
package wrappali

import "testing"

const html = `1.
Manopubbaṅgamā dhammā, manoseṭṭhā manomayā;
Manasā ce paduṭṭhena, bhāsati vā karoti vā;
Tato naṃ dukkhamanveti, cakkaṃva vahato padaṃ.`

func TestWrapPaliWordsInSpan(t *testing.T) {
	t.Log(WrapPaliWordsInSpan(html))
}

Output:

=== RUN   TestWrapPaliWordsInSpan
--- PASS: TestWrapPaliWordsInSpan (0.00s)
      pali_test.go:11: 1.
              <span>Manopubbaṅgamā</span> <span>dhammā</span>, <span>manoseṭṭhā</span> <span>manomayā</span>;
              <span>Manasā</span> <span>ce</span> <span>paduṭṭhena</span>, <span>bhāsati</span> <span>vā</span> <span>karoti</span> <span>vā</span>;
              <span>Tato</span> <span>naṃ</span> <span>dukkhamanveti</span>, <span>cakkaṃva</span> <span>vahato</span> <span>padaṃ</span>.
PASS

Tested on: Ubuntu Linux 16.04, Go 1.6.2.


References:

[1][JavaScript] Wrap Pāli Words in Span Element
[2]regexp - The Go Programming Language
[3][Golang] Find Pāli Word in Velthuis Scheme