scrivo / highlight.php

A port of highlight.js by Ivan Sagalaev to PHP
BSD 3-Clause "New" or "Revised" License
695 stars 45 forks source link

Get style method #46

Closed zhkuskov closed 5 years ago

zhkuskov commented 5 years ago

Hello! Can you add a method for getting styles? For example, the path to the style file? Or would the method return a style sheet from a file?

allejo commented 5 years ago

What's your intended use case for this functionality? Do you plan on delivering the CSS file via PHP?

If you're using stuff like Webpack you could just include the CSS file directly with its path:

vendor/scrivo/highlight.php/styles/a11y-dark.css
zhkuskov commented 5 years ago

Hi, sorry for the late reply. This will be convenient because, firstly, I do not need to know how and where the necessary style files are located. And maybe in the future you will change the path to the style files or the names of the files themselves.

allejo commented 5 years ago

What do you see the API for this functionality looking like? Would something like this work?

/** @var string */
$filePath = HighlightUtilities\getStyleSheet("a11y-dark");

// When $fileNames is true, it'll return just the filenames. When false, absolute paths.
/** @var string[] */
$cssPaths = HighlightUtilities\getAvailableStyleSheets($fileNames = true);
zhkuskov commented 5 years ago

Yes, it will be cool :) You can also add a method to get the text styles from the file: /** @var string */ $rawCSS = HighlightUtilities\getRawCss("a11y-dark"); for example, it is convenient when you need to get styles for the AMP version of the site