Query HTML string with shortcodes - postgresql

I have a content table with body field.
This field is a string and can contain text and HTML tags.
It can also contains shortcodes such as:
[shortcode-name param='some string' param2='other string'][/shortcode-name]
How can i write a query that returns all the contents that as at least one shortcode wrapped in an <a> tag?
<a href="my-link" ...>[shortcode-name param='string' ...][/shortcode-name]</a>
Note that <a> and shortcode-name can have different attributes (even no params) and shortcode-name can be every alphabetic combination ([another-shortcode][/another-shortcode]).

Related

Pgsql query with empty HTML tags

I have a body column (data type text) in a posts table which is storing HTML string.
How can i write a query to get all the posts with body containing at least one empty link (e.g. <a href=".." whatever></a>)?
SELECT * FROM posts WHERE body ~* '^[^\>]*(>){1}</a>$';
It means that empty links must have only one single '>' character before the ending tag.

What does CQ5's Placeholder.getDefaultPlaceholder exactly do?

The API docs are not much descriptive:
Get default placeholder for any component incl. title as text information
Here's the method signature:
public static String getDefaultPlaceholder(ServletRequest slingRequest,
Component component,
String defaultPlaceholder)
What's a Placeholder? What is/should be returned by getDefaultPlaceholder?
What's the purpose of defaultPlaceholder? What should I pass as defaultPlaceholder? What would happen if I pass null?
When a component does not have any content defined you need to put a placeholder to occupy its place (for the editor to know there's a component there).
The getDefaultComponent returns a HTML snippet that works as the placeholder. It consists of an empty div with attributes class and data-emptytext with the title of the component as its value.
<div class="" data-emptyText="component.getTitle()"></div>
You can also pass an additional parameter with a list of strings and they will be added in the class attribute of the div.
getDefaultPlaceholder(ServletRequest slingRequest,
Component component,
String defaultPlaceholder,
String... addClasses)

winJS data win bind innerText of span Renders the html tags

I have an app that needs to render the HTML tags like <bold>abc<bold>
but when I do <span data-win-bind='innerText: newText'></span>
then the output comes some thing like
<bold>abc</bold> instead of abc . what to do in order to achieve this ??
Rendering here is being done wrong
Try binding innerHTML rather than innerText
InnerText retrieves and sets the content of the tag as plain text, whereas InnerHtml retrieves and sets the same content but in HTML format.
Here's a microsoft site with same discussion
inner text and html
go through it :)

How do I get the nth element with a certain name in the entire XML document?

so will something like this work using Hpple Xpath
//a[4]
The fourth tag in a html tree?
Or do i need to do it programmatically by counting in a for() loop?
The XPath for the fourth <a> in an HTML document is:
(//a)[4]
Your example //a[4] will produce a set of all <a>s that are the fourth <a> in their respective parent, and that is not what you want here.
See also: https://stackoverflow.com/a/14209492/1945651

GWT: RichTextArea getHTML loses "outer" tags

Please bear with me as I am a newbie in gwt and front end stuff.
I have a html string:
String s=
"<html><head><title>Hello World</title></head><body><b>Hello World</b></body></html>";
(I am using spaces in the tags to prevent the text from displaying "htmlized".)
//and gwt RichTextArea control->richTextArea
richTextArea.setHTML(s);
//So far so good as the document String displays as desired.
//Now comes the problem...
String transformed = richTextArea.getHTML();
The rich text area strips the outer and returns the inner html only. i.e. The body, html and the head tags are stripped.
Q How do I get the html string returned with only the modifications which occur in the rich text area showing.. i.e. The original "outer" tags do not get lost.
Hope I am adequately clear.
You don't have to set them in setHTML <b>hello world<b/> is enough.
Also if you set the outer tags you can't get them, as they don't add anything in the formatting of the text.