diff options
author | Wim <wim@42.be> | 2019-01-06 22:25:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-06 22:25:19 +0100 |
commit | 04567c765e92ad60c685c1b2fe7e77c46e065645 (patch) | |
tree | 34a587a6545c8e71e991e2a1551885faa0075738 /vendor/golang.org/x/text/unicode/rangetable/rangetable.go | |
parent | 048158ad6db08cd714f39467fc0066ce41cfe6c5 (diff) | |
download | matterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.tar.gz matterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.tar.bz2 matterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.zip |
Add support for markdown to HTML conversion (matrix). Closes #663 (#670)
This uses our own gomatrix lib with the SendHTML function which
adds HTML to formatted_body in matrix.
golang-commonmark is used to convert markdown into valid HTML.
Diffstat (limited to 'vendor/golang.org/x/text/unicode/rangetable/rangetable.go')
-rw-r--r-- | vendor/golang.org/x/text/unicode/rangetable/rangetable.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/golang.org/x/text/unicode/rangetable/rangetable.go b/vendor/golang.org/x/text/unicode/rangetable/rangetable.go new file mode 100644 index 00000000..187882cc --- /dev/null +++ b/vendor/golang.org/x/text/unicode/rangetable/rangetable.go @@ -0,0 +1,70 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package rangetable provides utilities for creating and inspecting +// unicode.RangeTables. +package rangetable + +import ( + "sort" + "unicode" +) + +// New creates a RangeTable from the given runes, which may contain duplicates. +func New(r ...rune) *unicode.RangeTable { + if len(r) == 0 { + return &unicode.RangeTable{} + } + + sort.Sort(byRune(r)) + + // Remove duplicates. + k := 1 + for i := 1; i < len(r); i++ { + if r[k-1] != r[i] { + r[k] = r[i] + k++ + } + } + + var rt unicode.RangeTable + for _, r := range r[:k] { + if r <= 0xFFFF { + rt.R16 = append(rt.R16, unicode.Range16{Lo: uint16(r), Hi: uint16(r), Stride: 1}) + } else { + rt.R32 = append(rt.R32, unicode.Range32{Lo: uint32(r), Hi: uint32(r), Stride: 1}) + } + } + + // Optimize RangeTable. + return Merge(&rt) +} + +type byRune []rune + +func (r byRune) Len() int { return len(r) } +func (r byRune) Swap(i, j int) { r[i], r[j] = r[j], r[i] } +func (r byRune) Less(i, j int) bool { return r[i] < r[j] } + +// Visit visits all runes in the given RangeTable in order, calling fn for each. +func Visit(rt *unicode.RangeTable, fn func(rune)) { + for _, r16 := range rt.R16 { + for r := rune(r16.Lo); r <= rune(r16.Hi); r += rune(r16.Stride) { + fn(r) + } + } + for _, r32 := range rt.R32 { + for r := rune(r32.Lo); r <= rune(r32.Hi); r += rune(r32.Stride) { + fn(r) + } + } +} + +// Assigned returns a RangeTable with all assigned code points for a given +// Unicode version. This includes graphic, format, control, and private-use +// characters. It returns nil if the data for the given version is not +// available. +func Assigned(version string) *unicode.RangeTable { + return assigned[version] +} |