File tree 4 files changed +67
-1
lines changed
4 files changed +67
-1
lines changed Original file line number Diff line number Diff line change
1
+ var textToUrlMapping = {
2
+ "世尊譯詞的探討" : "http://agama.buddhason.org/book/bb/bb21.htm" ,
3
+ } ;
4
+
5
+ function TextToLink ( elm ) {
6
+ elm . innerHTML = elm . innerHTML . replace ( / 〈 ( .+ ) 〉 / g, function ( text , str1 ) {
7
+ if ( textToUrlMapping . hasOwnProperty ( str1 ) ) {
8
+ return '〈<a href="' + textToUrlMapping [ str1 ] +
9
+ '" target="_blank">' + str1 +
10
+ '</a>〉' ;
11
+ }
12
+ return str1 ;
13
+ } ) ;
14
+ }
15
+
16
+ var t = document . querySelector ( ".line-block" ) ;
17
+ TextToLink ( t ) ;
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ . "github.com/siongui/godom"
5
+ "regexp"
6
+ )
7
+
8
+ var textUrl = map [string ]string {
9
+ "世尊譯詞的探討" : "http://agama.buddhason.org/book/bb/bb21.htm" ,
10
+ }
11
+
12
+ var text = regexp .MustCompile (`〈.+〉` )
13
+
14
+ func TextToLink (elm * Object ) {
15
+ h := text .ReplaceAllStringFunc (elm .InnerHTML (), func (match string ) string {
16
+ key := match [3 : len (match )- 3 ]
17
+ url , ok := textUrl [key ]
18
+ if ok {
19
+ return `〈<a href="` + url +
20
+ `" target="_blank">` + key + `</a>〉`
21
+ }
22
+ return match
23
+ })
24
+ elm .SetInnerHTML (h )
25
+ }
26
+
27
+ func main () {
28
+ b := Document .QuerySelector (".line-block" )
29
+ TextToLink (b )
30
+ }
Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Convert Text to Link in HTML</ title >
6
+ </ head >
7
+ < body >
8
+
9
+ < div class ="line-block ">
10
+ < div class ="line "> 「世尊;眾祐」,南傳作「世尊」</ div >
11
+ < div class ="line "> (bhagavā,音譯為「婆伽婆;婆伽梵;薄伽梵」,</ div >
12
+ < div class ="line "> 義譯為「有幸者」,古譯為「尊祐」),</ div >
13
+ < div class ="line "> 菩提比丘長老英譯為「幸福者」(the Blessed One)。</ div >
14
+ < div class ="line "> 請參看〈世尊譯詞的探討〉。</ div >
15
+ </ div >
16
+
17
+ < script src ="app.js "> </ script >
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change 9
9
10
10
GO_VERSION =1.9.2
11
11
12
- WEBSITE_DIR =019-tooltip-with-close-delay
12
+ WEBSITE_DIR =020-convert-text-to-link
13
13
14
14
default : fmt js devserver
15
15
godom : fmt domjs devserver
You can’t perform that action at this time.
0 commit comments