I have the following string taken from the atom one-dark syntax:
one_dark_syn = """
@hue-1: hsl(187, 47%, 55%); // <-cyan
@hue-2: hsl(207, 82%, 66%); // <-blue
@hue-3: hsl(286, 60%, 67%); // <-purple
@hue-4: hsl( 95, 38%, 62%); // <-green
@hue-5: hsl(355, 65%, 65%); // <-red 1
@hue-5-2: hsl( 5, 48%, 51%); // <-red 2
@hue-6: hsl( 29, 54%, 61%); // <-orange 1
@hue-6-2: hsl( 39, 67%, 69%); // <-orange 2
"""
I would like to use python to exchange the hsl values for hex. So far I've concocted a pretty nasty looking set of loops to parse out the values into a numpy array:
od_colors = [i.split(";")[0].split(":")[1] for i in one_dark_syn.split("\n") if "hsl" in i]
od_colors = [i.strip().replace("%","").replace("hsl","").replace(" ","") for i in od_colors]
od_colors = [i.replace("(","").replace(")","").split(",") for i in od_colors]
od_colors = np.array(od_colors,dtype="int32")
See like I said nasty. Does anyone have a more pythonic way of parsing this? and most importantly how would you recommend I go about converting hsl to hex?
I would use regular expressions:
Finally, convert RGB triplets to a HEX string: