protected String replaceCallsToRgb(String line) {
		if (line.contains("rgb(") && line.contains(")")) {
			// simplify text like rgb(35,32,32)
			int start = line.indexOf("rgb(") + 4;
			int end = line.indexOf(")");
			String sub = line.substring(start, end); // gets a string that looks like: 0,0,0
			String comp[] = sub.split(",");

			// Code to ensure we don't try and turn calls containing percentages into hex colours e.g. rgb(100%, 0%, 10)
			// TODO: code for percentages inside rgb() see http://en.wikipedia.org/wiki/Web_colors#CSS_colors
			boolean containsPercent = false;
			for (String s : comp) {
				if (s.contains("%")) {
					containsPercent = true;
					break;
				}
			}

			if (!containsPercent) {
				int r, g, b;
				r = Integer.parseInt(comp[0]);
				g = Integer.parseInt(comp[1]);
				b = Integer.parseInt(comp[2]);


				Color c = new Color(r, g, b);
				String hexString = Integer.toHexString(c.getRGB() & 0xFFFFFF);
				if (hexString.length() < 6) {
					for (int i = 0; i <= 6 - hexString.length(); i++) {
						hexString = "0" + hexString;
					}
				}
				//				System.out.println(hexString + " = " + sub);
				line = line.replace(line.substring(start - 4, end + 1), "#" + hexString);
			}
		}
		return line;
	}