|
|
#1 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,528
Karma: 6774048
Join Date: Nov 2009
Device: many
|
where to put user editable css-like file for ease of editing
Quick question:
Should it be okay for plugins to store things into the Sigil's Preferences folder at its root level or should it only write files to its own prefs folder? I am designing a PrettyPrinter plugin for Sigil where users will need easy access to change/edit a css-lile file that controls how specific tags are handled when prettyprinting. This prettyprinter.pcss (extention is short for pseudo css) of course uses braces "{" "}" everywhere (as these are selectors) making storing it inside a json file a bit of a pain that would also inhibit easy editing with any text editor. I could of course write a gui editor for the plugin to directly edit that pcss file but I am really do not want to make this tool user interactive but instead be an auto-open auto-close plugin quick and silent tool that can reformat any number of selected xhtml files (just like an internal Sigil tool). So my first thought was tp put the prettyprinter.pcss file at the root of the Sigil Preferences folder but now feel that it may be setting a dangerous precedent for plugins. Should I just store this file in the plugins_prefs folder inside the plugin's folder? It would be easy to do based on code I found in a number of existing plugins: Code:
prefs_folder = os.path.join(os.path.dirname(bk._w.plugin_dir), "plugins_prefs", bk._w.plugin_name) Where should non-json files that the plugin user needs to easily access be stored? Thoughts? |
|
|
|
|
|
#2 |
|
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 82,839
Karma: 153071045
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
I suggest making a button in the plugin to access the non-jason file.
|
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,528
Karma: 6774048
Join Date: Nov 2009
Device: many
|
Unfortunately, the whole goal of this project was to create a fast tool that was NOT to use a gui (as I said, ... "really do not want to make this tool user interactive") so there can be no button.
Last edited by KevinH; Yesterday at 11:37 AM. |
|
|
|
|
|
#4 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,674
Karma: 64144480
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Why not follow Kovids lead and put them in the sigil config / plugin folder?
That way, There is only 1 Sigil folder backup that is needed to take everything with you. FWIW I just did that when My W10 SSD popped errors. I installed Linux Mint, Sigil, then copied the old config folder over. Sigil was up and running again in less time than it took to replace the drive (and install Linux) |
|
|
|
|
|
#5 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 29,274
Karma: 211540138
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I don't know of any specific dangers, but I do feel that having plugins that write configs to anywhere other than their own prefs folder could potentially lead to naming clashes. Probably pretty rare, but still.
|
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,528
Karma: 6774048
Join Date: Nov 2009
Device: many
|
@theducks,
We kinda already do that as each plugin has its own folder inside the Sigil Preferences folder inside its plugins folder. Each plugin also has its own preferences folder in the folder plugins_prefs (again inside the Sigil Preferences folder). So if the user wants to create a full backup, then all they need do is zip up Sigil's Preferences folder. They will get all plugins, all preferences, all ini files, all checkmark repos, ... everything. @DiapDealer, Okay that makes sense and what I thought. So for right now I have just placed the prettyprinter.pcss file inside the plugins own prefs folder. I have created an alpha of the plugin just to play with. I will attach it to this thread. So if a user installs it and runs it they can then look in its Sigil Preferences folder for the plugins_prefs/PrettyPrinter/prettyprinter.pcss file. Here is the default version of that file. It uses css-like tag selectors and a limited set of properties to control things. It is a simplification of that gitee/sigil-modified codebase that does its prettify. Code:
/* global settings */
@indent 2;
/* block-level elements */
html, body, p, div, h1, h2, h3, h4, h5, h6, ol, ul, li, address, blockquote, dd, dl, fieldset, form, hr, nav, menu, pre, table, tr, td, th, article {
opentag-br : 1 0;
closetag-br: 0 1;
}
p, div {
opentag-br : 1 0;
closetag-br: 0 2;
}
/* head elements */
head, meta, link, title, style, script {
opentag-br : 1 0;
closetag-br: 0 1;
}
/* xml header */
?xml {
opentag-br: 0 1;
}
/* doctype */
!DOCTYPE {
opentag-br : 1 2;
attr-fm-resv: true;
}
/* xhtml element */
html {
inner-ind-adj:-1;
}
/* comment */
!-- {
attr-fm-resv: true;
}
/* main */
body {
opentag-br : 2 1;
closetag-br: 1 1;
}
h1, h2, h3, h4, h5, h6 {
opentag-br : 2 0;
closetag-br: 0 2;
}
pre, script, style {
text-fm-resv: true;
}
/*
The prettyprinter.pcss is a pseudo-CSS file whose selectors may only
include element (tag) names and immediate child-descendant combinators that
are also element names.
There is a single global parameters that must appear at the top of the file before
any selectors. It is *not* used inside braces '{'.
@indent: int1; # number of spaces per indentation level.
# Range 0–4, default 2.
There are 6 possible per-selector properties:
opentag-br: int1 int2; # new lines before(int1) and after (int2)
# an opening tag. Each 0–9, default 0.
closetag-br: int1 int2; # new lines before (int1) and after (int2)
# a closing tag. Each 0–9, default 0.
ind-adj: int1; # adjusts the indent level of the node.
# Range -9 to 9.
inner-ind-adj: int1; # adjusts the indentation level within a node
# but excluding the node itself. Range -9 to 9.
attr-fm-resv: true|false; # preserve spaces/newlines inside the opening
# tag. Default false.
text-fm-resv: true|false; # preserve spaces/newlines in the node's text.
# Default false.
*/
I am thinking of hard coding some of this to prevent the user from making a bad mistake. Particularly this snippet: Code:
pre, script, style {
text-fm-resv: true;
}
I should probably hard code that somehow. Also if you use the css property white-space anyplace in your style attributes, css files, or inline style tags, you will not want to run this PrettyPrinter as it can not detect those cases. Last edited by KevinH; Yesterday at 02:13 PM. |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assess if a pdf file is editable | RotAnal | Plugins | 3 | 06-06-2018 06:54 PM |
| Where to put userStyle.css? | GeoffR | Kobo Reader | 15 | 04-06-2013 04:57 PM |
| User-Editable HTML in Templates? | marcot | Calibre | 0 | 06-15-2010 09:19 AM |