From cannabis to quinoa, ruby to low-sugar: This is not your grandmother's chocolate.

With the market for traditional candy bars in developed countries flagging as consumers shun sugary items for healthier treats, food companies are trying to make chocolate more appealing. Their tactics include gimmicks such as Ritter Sport's hemp-infused Chocolate and Grass bars (they don't get you high), new flavors and colors, as well as formulas that cut down on sugar.

Some chocolatiers are even diversifying away from candy. Pennsylvania-based Hershey Co., which began selling its classic bar 120 years ago, is moving into popcorn and potato chips, while Mars said in November that it will buy a stake in health-snack firm Kind. Just two months later, Nestle agreed to sell its U.S. confectionery unit amid falling revenue and a focus on such products as coffee and water.

"Sugar is portrayed as the new tobacco," said Eric Bergman, a commodities broker at Jenkins Sugar Group. "Consumers are now shifting away from the iconic, sugar-filled chocolate brands that we know and into healthier foods. The largest chocolate companies have followed suit and they are transitioning from chocolate companies into snack companies."

Although lower cocoa prices helped improve demand more recently, there's a growing push to discourage consumption of sugar, which makes up almost half of an average chocolate bar. Advocacy groups are urging people to cut back and governments, such as Philadelphia, are taxing sugary drinks.

To counter health concerns, Nestle is selling slimmed-down Milkybars in the U.K. and Ireland as part of a program to use 30 percent less sugar. The bars include a type of sugar that dissolves quicker in the mouth, but produces a similar taste to before.

Hershey's almost $1 billion purchase of Amplify Snack Brands, which also sells protein bars, shows how the industry is branching out as it contends with falling demand for sugary products. The moves come as Euromonitor International sees 2018 chocolate sales growth in western Europe and North America below levels of several years ago.

There are some bright spots for chocolate consumption. Sales of premium brands such as Lindt & Spruengli are on the rise, demand in developing countries is growing, and consumers are increasingly willing to pay more for dark chocolate, which contains more cocoa and less sugar, Bergman said. Millennials are also keen to try new varieties, prompting more flavors and artisan brands.

Ruby chocolate is one example. Nestle has been quick to adopt the first new color in eight decades, which was introduced by No. 1 cocoa processor Barry Callebaut last year and is shaded pink using only natural ingredients. Germany's Ritter Sport, which sold out of its limited cannabis bars in just two days, has also offered quinoa bars in the country. Cargill Inc. markets caramel-flavored white chocolate and also makes lactose-free dark chocolate.

"People are beginning to look at different tastes, different flavors," Gerry Manley, head of cocoa at Olam International, said in an interview in Berlin. "They are beginning to want ingredients to mix together themselves. You are getting a lot more artisan type of chocolate."

Consumers also want to understand how the cocoa in their products was produced and whether it meets ethical standards, said John George, an analyst at Euromonitor. Mars said this month that it will spend $1 billion on sustainability, including making operations more energy and water efficient as well as making an effort to buy directly from farmers.

Some customers even want more say over what they buy, according to Andreas Ronken, chief executive officer of Ritter Sport, which lets consumers vote on future limited editions.

"Consumers are increasingly asking themselves 'where does my food come from?'" Wyatt Elder, director of research and development at Cargill Cocoa & Chocolate, and Ilco Kwast, marketing director at the company, said by email. "There is a change going on in the marketplace, not just among millennials but across age groups and geographies, which will impact on us and other manufacturers. Standing still is not an option."