on b5b87f2 help sign in
elk/core-js/Text.js
46 lines 1.5 kB history raw
2var Text = function() {
3 function fromString(s) { return Value.toText(s); }
5 var addTag = function(tag) { return function(text) {
6 return '<' + tag + ' style="padding:0;margin:0">' + text + '</' + tag + '>';
7 };
8 };
9 var addStyle = function(style, value) { return function(text) {
10 return "<span style='" + style + ":" + value + "'>" + text + "</span>";
11 };
12 };
14 var typeface = function(name) { return addStyle('font-family', name); };
15 var size = function(px) {
16 return addStyle('font-size', px + 'px');
17 };
18 var header = addTag('h1');
19 var height = function(h) { return addStyle('font-size', h+'em'); }
20 var italic = addStyle('font-style', 'italic');
21 var bold = addTag('b');
22 var color = function(c) {
23 return addStyle('color', Color.Internal.extract(c));
24 };
25 var underline = addStyle('text-decoration', 'underline');
26 var overline = addStyle('text-decoration', 'overline');
27 var strikeThrough = addStyle('text-decoration', 'line-through');
28 var link = function(href) { return function(text) {
29 return "<a href='" + fromString(href) + "'>" + text + "</a>";
30 };
31 };
33 return {fromString : fromString,
34 toText: fromString,
35 header : header,
36 height : height,
37 italic : italic,
38 bold : bold,
39 underline : underline,
40 overline : overline,
41 strikeThrough : strikeThrough,
42 monospace : typeface('monospace'),
43 typeface : typeface,
44 color : color,
45 link : link };
46}();