Lone Wolf Development Forums

Lone Wolf Development Forums (http://forums.wolflair.com/index.php)
-   Realm Works Discussion (http://forums.wolflair.com/forumdisplay.php?f=67)
-   -   XML Transformation Script (PowerShell) (http://forums.wolflair.com/showthread.php?t=57418)

EightBitz January 27th, 2017 07:02 AM

Quote:

Originally Posted by tmilktoast (Post 242698)
Regarding those Edge of the Empire fonts, I imagine none of you are seeing them in your browser because you probably don't have them installed on your PC.

EightBitz, do you still want me to send you those things you asked for, or were you just going to work on Parody's suggestions?

Hey, here's something you might find interesting. Remember how there are two types of bulleted lists? One of them isn't actually formatted as a bulleted list. It just throws in a wingdings bullet followed by text.

*Shakes finger at Rob*

tmilktoast January 27th, 2017 07:14 AM

I've been meaning to make a post asking about these somewhat competing formatting options under Paragraph and Styles.

tmilktoast January 27th, 2017 07:15 AM

Quote:

Originally Posted by EightBitz (Post 242701)
I'm working on Parody's suggestion, and I'm pretty far along with the div tags. Had a few hiccups along the way, but things are going well now.

Good to hear.

EightBitz January 27th, 2017 07:34 AM

CSS question for Parody or anyone who's willing to answer. Regarding the following divisions, is there, generally speaking, a preferred order they should be listed in the CSS file, or does it not matter?

.snippet TABLE {}
.snippet TABLE TR {}
.snippet TABLE TR TD {}
.snippet TABLE TR TD P {}

Parody January 27th, 2017 09:44 AM

Practically: the order doesn't matter for what you're doing here. I generally do the same thing as your example for those sorts of selectors.

Technically: there's an order of precedence and specificity that determines what order CSS rules are applied to matching elements; rules with higher precedence and/or more specificity override earlier ones. Order of appearance in an external CSS file only matters if two selectors have identical precedence and specificity.

EightBitz January 27th, 2017 10:31 AM

Quote:

Originally Posted by Parody (Post 242714)
Practically: the order doesn't matter for what you're doing here. I generally do the same thing as your example for those sorts of selectors.

Technically: there's an order of precedence and specificity that determines what order CSS rules are applied to matching elements; rules with higher precedence and/or more specificity override earlier ones. Order of appearance in an external CSS file only matters if two selectors have identical precedence and specificity.

I thought that in that order of precedence, inline formatting always took precedence. But that doesn't seem to be the case. With tmilktoast's output, it has the following line (just including the relevant portion):

Code:

<td class="RWSnippet" style="background-color:#8B0000;...
That's kind of a rusty, reddish color. In my CSS file, I have the following elements (again, just including the relevant portions):

Code:

.snippet {--main-background-color:white;}
.snippet P {background-color:var(--main-background-color);}
.snippet TABLE {background-color:var(--main-background-color);}
.snippet TABLE TR {background-color:var(--main-background-color);}
.snippet TABLE TR TD {background-color:var(--main-background-color);}
.snippet TABLE TR TD P {background-color:var(--main-background-color);}

When I opened the html file, the background for the text in the table was white. Working my way up from TABLE TR TD P, I commented out each background-color in turn, and when I commented out the one for .snippet P, I saw the proper color in the table.

In the TABLE TR TD P section, I had him change the background-color to transparent, and that worked.

So that was unexpected ... to me anyway. Like I said, I'm still learning. :-)

kbs666 January 27th, 2017 12:59 PM

Was the it rendered white or was the code fore the element color white? If it was just rendered white that could be a browser thing. Different browsers handle CSS differently.

Parody January 27th, 2017 02:21 PM

There's a <p> inside of an element with "snippet" as one of its classes, which matches your ".snippet p" selector. It doesn't matter how deep the containment hierarchy goes:
Code:

<div class="snippet">
  <p>This matches.</p>
  <div class="whatever">
    <p>As does this.</p>
    <table><tr><td><p>And this too.</p></td></tr></table>
  </div>
</div>
<p>But not this.</p>

That particular <p> should also match ".snippet table tr td p". ".snippet table tr td p" is more specific than ".snippet p", so ".snippet p" should be applied first, then ".snippet table tr td p". The inline style would have precedence if it was on the <p>, but it's not; it's on a <td> that happens to contain a <p>, and both of the selectors that match the <p> also set the background-color.

Let's take a step back. Your goal is to not have a background-color for the text in the cell and let the cell's background-color show through. The term for that for background-colors is "transparent". It's also the default, which is usually specified in CSS with "initial". Something like this might work for you:

Code:

.snippet {
  background-color: white;
}

.snippet p { /* default formatting for regular paragraphs */ }

.snippet table { /* default table formatting */ }

.snippet table p {
  /* reset the background color */
  background-color: transparent;
}

This doesn't do much by itself, but if you do specify a different background-color for a <table> or <tr> or <td> or whatever and they happen to contain <p>s, then hopefully this will make it do what you actually want.

Note that this is only needed because something is overriding the default. If your ".snippet p" selector doesn't include a background-color, then you don't need to override it for tables containing <p>s. The less you specify, the better. :)

FWIW, if you want a selector that means "only <p>s directly contained inside an element with the 'snippet' class", you could try try ".snippet + p". Also you don't need to use <p>s inside of <td>s or <th>s, so if there's only one <p> in a cell or header you could strip it.

EightBitz January 27th, 2017 04:06 PM

Quote:

Originally Posted by Parody (Post 242737)
There's a <p> inside of an element with "snippet" as one of its classes, which matches your ".snippet p" selector. It doesn't matter how deep the containment hierarchy goes:
Code:

<div class="snippet">
  <p>This matches.</p>
  <div class="whatever">
    <p>As does this.</p>
    <table><tr><td><p>And this too.</p></td></tr></table>
  </div>
</div>
<p>But not this.</p>

That particular <p> should also match ".snippet table tr td p". ".snippet table tr td p" is more specific than ".snippet p", so ".snippet p" should be applied first, then ".snippet table tr td p". The inline style would have precedence if it was on the <p>, but it's not; it's on a <td> that happens to contain a <p>, and both of the selectors that match the <p> also set the background-color.

Let's take a step back. Your goal is to not have a background-color for the text in the cell and let the cell's background-color show through. The term for that for background-colors is "transparent". It's also the default, which is usually specified in CSS with "initial". Something like this might work for you:

Code:

.snippet {
  background-color: white;
}

.snippet p { /* default formatting for regular paragraphs */ }

.snippet table { /* default table formatting */ }

.snippet table p {
  /* reset the background color */
  background-color: transparent;
}

This doesn't do much by itself, but if you do specify a different background-color for a <table> or <tr> or <td> or whatever and they happen to contain <p>s, then hopefully this will make it do what you actually want.

Note that this is only needed because something is overriding the default. If your ".snippet p" selector doesn't include a background-color, then you don't need to override it for tables containing <p>s. The less you specify, the better. :)

FWIW, if you want a selector that means "only <p>s directly contained inside an element with the 'snippet' class", you could try try ".snippet + p". Also you don't need to use <p>s inside of <td>s or <th>s, so if there's only one <p> in a cell or header you could strip it.

Yep, that's exactly how I fixed it for him. Then he has to go and ask if it's possible to extract the images and such instead of leaving them embedded.

So guess what I've been working on... That's the thanks I get for helping him out. Jerk. ;-p

Parody January 27th, 2017 06:43 PM

Yeah, that's a little bit more of a pain. I've been working on a tool to unpack MHT files (think "web site saved as an email with attachments") which has to deal with the same thing.

EightBitz January 27th, 2017 06:56 PM

Quote:

Originally Posted by Parody (Post 242749)
Yeah, that's a little bit more of a pain. I've been working on a tool to unpack MHT files (think "web site saved as an email with attachments") which has to deal with the same thing.

With PowerShell, the deed itself is just two lines of script.
Code:

$bytes = [Convert]::FromBase64String($Contents)
[IO.File]::WriteAllBytes($FilePath,$bytes)

The painful part is integrating it with everything around it.

Parody January 27th, 2017 07:03 PM

Well, yeah. Also you have to know you don't mind spending the RAM for it. (RW's 30MB limit helps there.)

I keep wanting to make a more fully fleshed out tool instead of just a quick-and-dirty thing that does what I'm actually trying to accomplish. :)

EightBitz January 27th, 2017 07:46 PM

Quote:

Originally Posted by Parody (Post 242751)
Well, yeah. Also you have to know you don't mind spending the RAM for it. (RW's 30MB limit helps there.)

I keep wanting to make a more fully fleshed out tool instead of just a quick-and-dirty thing that does what I'm actually trying to accomplish. :)

Meh, these days everyone as an extra jigawatt or two of RAM.

tmilktoast January 28th, 2017 04:21 AM

Quote:

Originally Posted by EightBitz (Post 242742)
Yep, that's exactly how I fixed it for him. Then he has to go and ask if it's possible to extract the images and such instead of leaving them embedded.

So guess what I've been working on... That's the thanks I get for helping him out. Jerk. ;-p

You're very welcome.

I mean, thank you. :D

daplunk January 28th, 2017 05:55 PM

Anyone else seeing this go non-responsive when it runs the script? It works don't get me wrong. And it looks great. But the GUI freezes up and I need to close it out manually.

EightBitz January 28th, 2017 06:30 PM

Quote:

Originally Posted by daplunk (Post 242821)
Anyone else seeing this go non-responsive when it runs the script? It works don't get me wrong. And it looks great. But the GUI freezes up and I need to close it out manually.

The GUI disables itself while the script is running. When the script completes, the GUI reactivates itself. This happens to indicate when the script starts and when it completes, so you're not left wondering. There are probably better ways to manage this, and I can work on that later, but for now, that's how it works.

If the GUI remains greyed out and non-responsive, there's an issue with the script, or at least with that particular run of it. I'd need more details, of course, to determine exactly what's happening here.

Maybe something is getting caught in a loop, or maybe something is happening to prevent the form from reactivating itself. Maybe the script is taking longer to run than you realize. Various possibilities exist.

EightBitz January 28th, 2017 06:39 PM

In the next release, I'll just disable the run button instead. That will still offer an indicator that the script is active without disabling the whole form.

daplunk January 28th, 2017 06:40 PM

I did the same export twice and it appears to have completed but just stays disabled. Ill try it with a different file and see if the export is the cause.

EightBitz January 29th, 2017 11:11 AM

New version up.

https://github.com/EightBitz/RWExpor...Version-0.9.1b

EightBitz January 29th, 2017 11:00 PM

I just updated the GUI. I got the "Load" button working, and I added a "Save Defaults" button. The Load button will only work properly with scripts saved by the GUI.

I figure these two changes will make life immensely easier for anyone using the GUI.

EDIT: Click the link in the first post. I didn't change version numbers or anything. This one's just a quickie with no changes to the primary script.

EightBitz January 31st, 2017 10:38 AM

You can look forward to linked topics in the next version. Not in the body text, but in the topic details, where the linkage currently appears.

Putting the links in the body text invokes various issues I'm not sure how to deal with right now. It may sound simple and straightforward, but when one considers the potential for duplicate topic names and alias names, it becomes much more problematic. I don't see any clear indication of how to deal with this in the XML, so that would leave me to make my best guesses when writing the code, and that's probably not going to be good enough.

So for now, at least, it'll all be in the section with topic details.

I should have that ready by the end of the week. I want to test and tighten up some other things before I post it.

ShadowChemosh January 31st, 2017 01:15 PM

Quote:

Originally Posted by EightBitz (Post 243025)
It may sound simple and straightforward, but when one considers the potential for duplicate topic names and alias names, it becomes much more problematic. I don't see any clear indication of how to deal with this in the XML, so that would leave me to make my best guesses when writing the code, and that's probably not going to be good enough.

Its so weird. Your almost starting to sound like Rob! :D :eek: :)

Update: Adding that the above is 100% meant as a "complement" not a insult at all. Rob is awesome and sounding like him in my world is a "GOOD" thing!

EightBitz January 31st, 2017 01:49 PM

Quote:

Originally Posted by ShadowChemosh (Post 243041)
Its so weird. Your almost starting to sound like Rob! :D :eek: :)

Rob is obviously much better at this than I am.

Farling January 31st, 2017 03:14 PM

Quote:

Originally Posted by EightBitz (Post 243025)
Putting the links in the body text invokes various issues I'm not sure how to deal with right now. It may sound simple and straightforward, but when one considers the potential for duplicate topic names and alias names, it becomes much more problematic. I don't see any clear indication of how to deal with this in the XML, so that would leave me to make my best guesses when writing the code, and that's probably not going to be good enough.

Links seem to be stored in the XML export as <link target_id="Topic_24"...

where "Topic_24" is the name given to a <topic topic_Id="Topic_24"...

so with enough mapping information in your script, you might be able to map back from the link to the originating topic. (Another issue would be mapping the "span_info/span_List/span" information to the correct position within the contents element.)

EightBitz January 31st, 2017 03:55 PM

Quote:

Originally Posted by Farling (Post 243057)
Links seem to be stored in the XML export as <link target_id="Topic_24"...

where "Topic_24" is the name given to a <topic topic_Id="Topic_24"...

so with enough mapping information in your script, you might be able to map back from the link to the originating topic. (Another issue would be mapping the "span_info/span_List/span" information to the correct position within the contents element.)

Right. I figured out the link targets and topic IDs, as well as the direction, which is how I got the links working in the topic details section of my output.

I haven't figured out how to apply that information to the content. For instance, I have one topic that has three links to two other topics. The third link is to an alias of one of the other two topics. There are only two "linkage" properties. The both reference the topic's public_name (neither of them reference the alias name).

The alias is the third link the content, and it refers to the first topic. So when I look at the content, there's a link for topic 1, then a link for topic 2, then a link to the alias of topic 1.

When I look at the XML, there's one linkage entry for topic 1 and one linkage entry for topic 2. There is nothing obvious in the content section of the XML (at least, not obvious to me) that indicates which text refers to which linkage entry.

This leads me to believe (I'm not stating a fact here, just a summary conclusion based on what I've been able to reverse engineer so far) that the extra linkage information is stored in the full export, but not the compact one.

Or, there's always the very real possibility that I'm missing something.

EightBitz January 31st, 2017 04:38 PM

The linkage info in the full export is indeed more detailed. There are "start" and "length" attributes that direct them the proper points in the content.

Farling January 31st, 2017 11:56 PM

Quote:

Originally Posted by EightBitz (Post 243068)
The linkage info in the full export is indeed more detailed. There are "start" and "length" attributes that direct them the proper points in the content.

Ah, sorry about that. I've always been looking at the full export XML data format. I'd forgotten that you were working with the simpler export format.

EightBitz February 1st, 2017 01:40 AM

I was trying to add in some input validation, but what I had in mind just doesn't want to work. :-(

You guys seem OK so far. I just wanted to add it for some polish. But I'm very frustrated, and I'm giving up on it ... at least for now. I swear, input validation has vexed me more than everything else I've done with the script, and it's time to just let it go, I think.

So I'll make sure everything else still works and post the update.

Bidmaron February 1st, 2017 03:21 AM

What do you mean input validation?

EightBitz February 1st, 2017 03:31 AM

Quote:

Originally Posted by Bidmaron (Post 243094)
What do you mean input validation?

Making sure the folders and filenames provided are good, asking for overwrite confirmation, making sure the sort and image scale values are in range ... things like that.

Also, new version is up.

https://github.com/EightBitz/RWExpor.../Version-0.95b

Bidmaron February 1st, 2017 04:47 AM

Great work again, EightBitz!

EightBitz February 1st, 2017 06:19 AM

Quote:

Originally Posted by Bidmaron (Post 243098)
Great work again, EightBitz!

Thanks!

Shortly after I posted, I figured out why my input validation script wasn't working. So there will be a version 1.0. :-)

Have to tidy some things up before I post it. And I got some errands to run. So, not right now.

EightBitz February 1st, 2017 11:09 AM

Version 1.0 is up. It's like Chief O'Brien having his own asteroid. It's a Mile's stone!

https://github.com/EightBitz/RWExport/tree/Version-1.0

EightBitz February 1st, 2017 11:17 AM

Also, please don't examine the validation script. I'm a little embarrassed about it. :-o

I might clean it up later, but right now, I just wanted the darn thing to work. :-)

EightBitz February 6th, 2017 03:02 AM

Didn't want to say anything earlier, but I'm close enough to done now where I think it's safe to say this ...

I've been working on an option to export to a word file i stead of HTML. Complete with collapsible headings and an automatically generated table of contents.

It's not retaining any formatting right now. That's going to be a task I'm not up to right now. Maybe later.

Topics, unfortunately, will not be nested, but sections will be.

Should be ready in a few days, unless I just jinxed myself by posting this prematurely.

Bidmaron February 6th, 2017 05:51 AM

Yo are a treasure to the community, Eight.

Zaphod Beebledoc February 6th, 2017 10:59 AM

Quote:

Originally Posted by Bidmaron (Post 243477)
Yo are a treasure to the community, Eight.

Hear, hear!

AEIOU February 6th, 2017 12:57 PM

@ Bidmaron, motion made.

@Zaphod Beebledoc, motion carried.

@EightBitz, by the power granted to this forum by the internet, you may officially add "Treasure to the Community" to your signature line. You are entitled to all the praise and encouragement it may bring. We appreciate the huge amount of work you have undertaken on our behalf. Thank you!

Acenoid February 6th, 2017 01:20 PM

Have not used the script yet, but surely will do so soon!
Thank you for the work and thanks again for sharing it with us.

EightBitz February 8th, 2017 08:12 AM

New version up! Please read the release notes, and please read the "Exporting to Word" section in the main doc.

https://github.com/EightBitz/RWExport/tree/Version-1.5


All times are GMT -8. The time now is 02:13 AM.

Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.