I'm still struggling with getting jqgrid's viewGridRow function to handle grids that have column names that include spaces. I came up with a hack to replace spaces with underscores but was told that that I should be using jqID instead. Specifically,
If you want modify the code you should better use $.jgrid.jqID instead of replacement of blanks to undescores. The function $.jgrid.jqID are used in the most places of jqGrid code, but still not everywhere. The problem it very easy. It one have meta-characters as the part of id and one want to use the id as a part of the jQuery selector one have to escape the characters. The method $.jgrid.jqID do exactly the job.
Upon looking at the source code inside grid.base.js, I see that the function is defined as
$.extend($.jgrid,{
jqID : function(sid){
return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?#\[\\\]\^`{|}~]/g,"\\$&");
}
});
which leads me to believe that it should be perhaps used in the beforeProcessing() function to modify the cell IDs? Regardless, I don't see that the regex, as it currently exists, specifically handles spaces.
Oleg, if you're out there, help!!! :)
D'oh!! As soon as I hit submit, I realized that Oleg meant to modify the jqID function to add spaces to the regex string. That seems to do the trick.
Related
I am using the html/template functionality to assemble a page and on of the variables I'm supplying to the template is URI in the form "/some/path/etc" which is used as a parameter to a JS function called in a onClick="..".
No matter what, the string used in this configuration will be escaped with backslashes : "\/some\/path\/etc"
As you can see in the playground example below, I tried all the .HTML(), .JS() etc. functions but nothing seems to stop the escaping.
See Go Playground example here: https://play.golang.org/p/2gdghTpQHKP
How can I get this URI "as is" into the template result?
Thanks to mkopriva for his comment.
As far as I could see there is no way (as mkopriva mentioned) to handling a HRML attribute value fragment in a Go HTML template.
So the options are:
Leave it as is (it seems that at least in my use case the URI even works in the further processing with the escaped forward slashes)
first concatenate the complete attribute, so that the "HTML Attribute" way will accept it
Write a construction function that takes parts and assembles the final attribute value inside the template execution
Hardcode the value in some form
I have created a custom directive for a documentation project of mine which is built using Sphinx and reStructuredText. The directive is used like this:
.. xpath-try:: //xpath[#expression="here"]
This will render the XPath expression as a simple code block, but with the addition of a link that the user can click to execute the expression against a sample XML document and view the matches (example link, example rendered page).
My directive specifies that it does not have content, takes one mandatory argument (the xpath expression) and recognises a couple of options:
class XPathTryDirective(Directive):
has_content = False
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {
'filename': directives.unchanged,
'ns_args': directives.unchanged,
}
def run(self):
xpath_expr = self.arguments[0]
node = xpath_try(xpath_expr, xpath_expr)
...
return [node]
Everything seems to be working exactly as intended except that if the XPath expression contains a * then the syntax highlighting in my editor (gVim) gets really messed up. If I escape the * with a backslash, then that makes my editor happy, but the backslash comes through in the output.
My questions are:
Are special characters in an argument to a directive supposed to be escaped?
If so, does the directive API provide a way to get the unescaped version?
Or is it working fine and the only problem is my editor is failing to highlight things correctly?
It may seem like a minor concern but as I'm a novice at rst, I find the highlighting to be very helpful.
Are special characters in an argument to a directive supposed to be escaped?
No, I think that there is no additional processing performed on arguments of rst directives. Which matches your observation: whatever you specify as an argument of the directive, you are able to get directly via self.arguments[0].
Or is it working fine and the only problem is my editor is failing to highlight things correctly?
Yes, this seems to be the case. Character * is used for emphasis/italics in rst and it gets more attention during syntax highlighting for some reason.
This means that the solution here would be to tweak or fix vim syntax file for restructuredtext.
I am trying to match part of a url http://www.mywebsite.com/get-stuff in cypress and haven't been able to figure out how to code a regex match.
I tried:
cy.contains('http.*get-stuff')
and don't find a match for
do some things
If you are trying to see if some content on your website has the text http://www.mywebsite.com/get-stuff using regex, you will need to pass in a valid Regular Expression. Your argument is attempting to match using a glob expression.
If you are trying to see if the url of your website is navigated to http://www.mywebsite.com/get-stuff, you likely want to write an assertion off of the cy.url() command like so:
cy.url().should('match', /myregexp/)
I know it's been quite a long, but for those who are still looking for a solution ( just like me ), you can make use of cy.url().should('contain', /regex/) if the accepted solution didn't work for you.
This solution should work too:
cy.get('div') // select DOM element (tag, class or id)
.invoke('text') // check the innerHTML text
.should('match', /regex/) // compare with a regular expression
More on:
https://docs.cypress.io/api/commands/invoke
Is there any built in function in Scintilla.NET to detect the cursor is over a comment or string? I'd want to avoid the autocompletion to work when the user is typing comments or strings.
I'm aware I can scan the whole text backwards, searching for //, /* */ and pairs of " " but I'm almost sure there must be a built-in function to do that.
Thanks!
If you're using a lexer, you can get the style number at the current caret postion and check to see if it corresponds with a string or comment. The Scintilla API for retrieving the style number is:
SCI_GETSTYLEAT(int pos)
The Scintilla.NET documentation states there are already some convenience APIs for detecting comments:
ScintillaNET.Scintilla.PositionIsOnComment(System.Int32)
ScintillaNET.Scintilla.PositionIsOnComment(System.Int32,ScintillaNET.Lexer)
But there does not seem to be anything equivalent for strings - so it looks like you'll have to roll your own by using the above Scintilla message with one of the ScintillaNET.Scintilla.SendMessageDirect() methods.
I'm trying to parse a webpage to get posts from a forum.
The start of each message starts with the following format
<div id="post_message_somenumber">
and I only want to get the first one
I tried xpath='//div[starts-with(#id, '"post_message_')]' in yql without success
I'm still learning this, anyone have suggestions
I think I have a solution that does not require dealing with namespaces.
Here is one that selects all matching div's:
//div[#id[starts-with(.,"post_message")]]
But you said you wanted just the "first one" (I assume you mean the first "hit" in the whole page?). Here is a slight modification that selects just the first matching result:
(//div[#id[starts-with(.,"post_message")]])[1]
These use the dot to represent the id's value within the starts-with() function. You may have to escape special characters in your language.
It works great for me in PowerShell:
# Load a sample xml document
$xml = [xml]'<root><div id="post_message_somenumber"/><div id="not_post_message"/><div id="post_message_somenumber2"/></root>'
# Run the xpath selection of all matching div's
$xml.selectnodes('//div[#id[starts-with(.,"post_message")]]')
Result:
id
--
post_message_somenumber
post_message_somenumber2
Or, for just the first match:
# Run the xpath selection of the first matching div
$xml.selectnodes('(//div[#id[starts-with(.,"post_message")]])[1]')
Result:
id
--
post_message_somenumber
I tried xpath='//div[starts-with(#id,
'"post_message_')]' in yql without
success I'm still learning this,
anyone have suggestions
If the problem isn't due to the many nested apostrophes and the unclosed double-quote, then the most likely cause (we can only guess without being shown the XML document) is that a default namespace is used.
Specifying names of elements that are in a default namespace is the most FAQ in XPath. If you search for "XPath default namespace" in SO or on the internet, you'll find many sources with the correct solution.
Generally, a special method must be called that binds a prefix (say "x:") to the default namespace. Then, in the XPath expression every element name "someName" must be replaced by "x:someName.
Here is a good answer how to do this in C#.
Read the documentation of your language/xpath-engine how something similar should be done in your specific environment.
#FindBy(xpath = "//div[starts-with(#id,'expiredUserDetails') and contains(text(), 'Details')]")
private WebElementFacade ListOfExpiredUsersDetails;
This one gives a list of all elements on the page that share an ID of expiredUserDetails and also contains the text or the element Details