Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(){
- var trim = function (string) {
- return string.replace(/(^\s+)|(\s+$)/g, '');
- }
- var re = {
- size : /^\d+(em|px|%)$/i,
- size4 : /^(\d+(em|px|%) ?){1,4}$/i,
- borderStyle : /^(dotted|dashed|solid|double|groove|ridge|inset|outset|none)$/i,
- colorNames : /^(aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow|cyan|magenta)$/,
- rgbColor : /^(rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\))$/,
- hexColor : /^(#[a-f0-9]{3}|#[a-f0-9]{6})$/i
- };
- var isColor = function (string) {
- return string.match(re.hexColor) || string.match(re.rgbColor) || string.match(re.colorNames);
- };
- var lib = {
- validStyles : {
- 'text-align' : /^center|justify|left|right$/i,
- 'border' : function (arg) {
- var parts = arg.split(' ');
- var borderStyle = 'none';
- var borderColor = 'black';
- var borderWidth = '0';
- for (var i in parts) {
- if (parts[i].match(re.borderStyle)) {
- borderStyle = parts[i].toLowerCase();
- } else if (parts[i].match(re.size)) {
- borderWidth = parts[i].toLowerCase();
- } else if (isColor(parts[i])) {
- borderColor = parts[i].toLowerCase();
- }
- }
- return [borderStyle, borderColor, borderWidth].join(' ');
- },
- 'background' : function (arg) {
- return isColor(arg) ? arg.toLowerCase() : null;
- },
- 'display' : /^(block|inline|none)$/i,
- 'padding' : re.size4,
- 'margin' : re.size4,
- 'float' : /^(left|right)$/,
- 'clear' : /^(both|left|right)$/,
- 'width' : re.size4,
- 'height' : re.size4
- }
- };
- TeX.addTag({
- name : 'style',
- args : 'unlimited',
- func : function (args) {
- var text = args.pop();
- var allStyles = lib.validStyles;
- var result = '', value;
- for (var style in args) {
- style = trim(args[style]).split(':');
- if (style.length != 2) {
- continue;
- }
- var name = style[0].toLowerCase();
- var cur = allStyles[name];
- if (cur) {
- var type = typeof cur;
- if (type === 'function') {
- value = cur(style[1]);
- } else if (style[1].match(cur)) {
- value = style[1];
- }
- if (value) {
- result += name + ':' + value + ';';
- }
- }
- value = '';
- }
- return '<span style="' + result + '">' + TeX.markup(text) + '</span>';
- }
- });
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement