Not logged in

is it possible add css to filter or settings.ini

(1) By css on 2020-01-30 12:57:28

Thank you! for great plugin it helps me alot, i work on some templates and my code use external stylesheet, so every time when edit page i must add css to it , to be able to se it properly, and remove it again when done editing, i like to add the css code to Preview html in filter or settings.ini, so it use it on my code. would be nice if it had option to add css.

(2) By tinus on 2020-01-30 18:25:26 [link] in reply to 1


I’m not quite certain what you mean by "add css to it".

Do you mean that you can't preview the page while editing a relevant CSS file? Doesn't that work if you check the "Freeze" checkbox, below the preview?

If that's not what you mean, could you clarify what your problem is?

(3) By wdpk on 2020-03-20 06:37:19 [link] in reply to 1

Aloha css & tinus,

I'm operating under this interpretation of this request. You have a master stylesheet you like to use while editing pages. To use your stylesheet, you have to reference in the code of the file itself, either with a <link> to somewhere else, or with <style> to insert the entire sheet.

However, you do not want the final file to contain a reference to this sheet. So after editing, you must remove the <link> and/or <style>.

It would be ideal if the preview window always used your style sheet, without you having to reference each time.

All this said, it is my understanding this is exactly what the filter function is for, processing code before it is previewed in the window. 

Now I'm relatively new to this plugin myself, but I was able to hack together a solution that works for this situation. I also tend to be a very slap-it-together programmer who writes poorly optimized code. Perhaps tinus would be able to improve upon what I've got here. This solution assumes Windows and was developed using npp 7.8.1 64-bit using 1.3.2 of preview html.

From filters.ini
Command=cmd /c "(echo ^<link rel="stylesheet" type="text/css" href="/%YourPathHere%/sheet.css"^>&&type "%1")>"%2""

This inserts the <link> to the stylesheet, then passes the current (edited) code.

Unfortunately, I couldn't get it to consistently add it to the end, where your sheet would take precedence. It works when flipped, but only unedited(i.e. currently saved version), correctly adding the sheet to the end. However, when you edit with it in that arrangement, it seems to skip adding it to the end and just displays the current modified version of the file. You have to save and refresh the preview for the edited sheet to be correctly added to the end again.

So any styles declared within the page will be displayed instead of your external style sheet.

To tinus: I would be interested in a working version of adding it to the end, if you've got a better way to do what I've done here. I've been testing with a file of length 31,353 and 376 lines for reference.