on cbecda2 help sign in
elk/core-js/Text.js
53 lines 1.6 kB history raw
2var Text = function() {
3 var fromString = function(elmList) {
4 if (typeof elmList === "string") return elmList;
5 var a = [];
6 while (elmList[0] === "Cons") {
7 a.push(elmList[1]);
8 elmList = elmList[2];
9 }
10 return Data.String.properEscape(a.join(''));
11 };
13 var addTag = function(tag) { return function(text) {
14 return '<' + tag + '>' + text + '</' + tag + '>';
15 };
16 };
17 var addStyle = function(style, value) { return function(text) {
18 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
19 };
20 };
22 var typeface = function(name) { return addStyle('font-family', name); };
23 var size = function(px) {
24 return addStyle('font-size', px + 'px');
25 };
26 var header = addTag('h1');
27 var height = function(h) { return addStyle('font-size', h+'em'); }
28 var italic = addStyle('font-style', 'italic');
29 var bold = addTag('b');
30 var color = function(c) {
31 return addStyle('color', Color.Internal.extract(c));
32 };
33 var underline = addStyle('text-decoration', 'underline');
34 var overline = addStyle('text-decoration', 'overline');
35 var strikeThrough = addStyle('text-decoration', 'line-through');
36 var link = function(href) { return function(text) {
37 return "<a href='" + fromString(href) + "'>" + text + "</a>";
38 };
39 };
41 return {fromString : fromString,
42 toText: fromString,
43 header : header,
44 height : height,
45 italic : italic,
46 bold : bold,
47 underline : underline,
48 overline : overline,
49 strikeThrough : strikeThrough,
50 monospace : typeface('monospace'),
51 color : color,
52 link : link };
53}();