Why Can't the ≪P≫ Tag Contain a ≪Div≫ Tag Inside It

What do and stand for?

  • < stands for the less-than sign: <
  • > stands for the greater-than sign: >
  • stands for the less-than or equals sign:
  • stands for the greater-than or equals sign:

Javascript onclick even on a div not working

Onclick will call the function, you don't need the javascript:

<div onclick="test('zaswde');">sdfasdasdadasdasds</div>​

How To Replace with and with using jquery

The simplest thing to do would be

$('#test').each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('<','<').replace('>', '>'));
});

working edit/jsfiddle by Jared Farrish

Issue with finding what a user has inputted with what is aleady stored in my array

Now with a smaller validation array, less looping/filtering, no strpos, no array_push. (your $AllowedTags elements had inconsistencies: some with > and some with >) This is leaner and cleaner:

View PHP Demo

View Regex Demo

Here is the code:

// don't duplicate tag names as /-prefixed and non-/-prefixed
$AllowedTags = array("html","head","body","div","p","b","base","link","meta","style",
"title","address","article","aside","footer","h1","h2","h3","h4","h5","h6","header",
"hgroup","nav","selection","dd","d1","dt","figcaption","figure","hr","li","main","ol",
"pre","ul","a","abbr","b","bdi","bdo","br","cite","code","data","dfn","em","i","kbd",
"mark","q","rp","rt","rtc","ruby","s","samp","small","span","strong","sub","sup","time",
"u","var","wbr","area","audio","img","map","track","video","embed","object","param",
"source","canvas","noscript","script","del","ins","caption","col","colgroup","table",
"tbody","td","tfoot","th","thead","tr","button","datalist","fieldset","form","input",
"label","legend","meter","optgroup","option","output","progress","select","textarea",
"details","dialog","menu","menuitem","summary","shadow","slot","template","acronym",
"applet","basefont","big","blink","center","command","content","dir","element","font",
"frame","frameset","isindex","keygen","listing","marquee","multicol","nextid","noembed",
"plaintext","shadow","spacer","strike","tt","xmp");

$UserInput="<a href="https:www.this.that.com">Word</a><aaa style='color:orange;'>Somethingelse</aaa><b>Another bit of something</b you=can't put attributes on an end tag>";
// <a href="https:www.this.that.com">Word</a><aaa style='color:orange;'>Somethingelse</aaa><b>Another bit of something</b you=can't put attributes on an end tag>

if(preg_match_all('/<([^\/][a-z1-6]*)\s?(.*?)>|<\/([^&]*?)>/',$UserInput,$tags)){
// match opening, opening attributes, and closing tags in three separate groups,
// but store only the tagname in tag groups and keep the attribute string whole
$AllTags=array(
"Opening"=>array_diff($tags[1],array('')), // remove empties
"Closing"=>array_diff($tags[3],array('')) // remove empties
);
foreach($AllTags as $label=>$group){ // loop through opening & closing tags
foreach(array_intersect($group,$AllowedTags) as $tag){ // loop Valids
echo "<div style='color:green;'>Valid $label Tag: $tag</div>";
}
foreach(array_diff($group,$AllowedTags) as $tag){ // loop Invalids
echo "<div style='color:red;'>Invalid $label Tag: $tag </div>";
}
}
$Attributes=array_diff($tags[2],array('')); // remove empties
// As it is a separate can of worms, I will leave $Attributes handling to you.
foreach($Attributes as $attr){ // loop Attributes
echo "<div style='color:green;'>Attribute: $attr</div>";
}
}else{
echo "<div style='color:blue;'>No tags found in input</div>";
}

This will help you to identify all of the valid and invalid opening and closing tags in $UserInput. Modify my solution to your precise needs. I'm happy to explain further if necessary.

*Note if your program permits tags containing attributes, the regex pattern will need to be expanded to allow (and not capture) attributes.

driver.getPageSource() converts signs to

It is generally best practice to not use the getPageSource() method of WebDriver, but to rather use JavaScriptExecutor to get the page source through javascript.

String pageSource = ((JavaScriptExecutor)driver).executeScript("return document.documentElement.outerHTML;").toString();

Escaping HTML strings with jQuery

Since you're using jQuery, you can just set the element's text property:

// before:
// <div class="someClass">text</div>
var someHtmlString = "<script>alert('hi!');</script>";

// set a DIV's text:
$("div.someClass").text(someHtmlString);
// after:
// <div class="someClass"><script>alert('hi!');</script></div>

// get the text in a string:
var escaped = $("<div>").text(someHtmlString).html();
// value:
// <script>alert('hi!');</script>

React Native html render: issues with images

You can use react-native-render-html and specify a style using tagsStyles and classesStyles props for each html tags or classes. The following code is an example of using this props:

<HTML
html={item.message}
tagsStyles={{
p: {
fontSize: 22,
lineHeight: 30,
marginBottom: 0
},
img: {
...
}
}}
classesStyles={{
'custom-image': {
...
}
}}
ignoredStyles={['line-height']} />

also you can use renderers props to render custom contents for specific tags. for more information about react-native-render-html follow this link:
https://github.com/archriss/react-native-render-html

Beautiful Soup replaces with

The found object is not a Python string, it's a Tag that just happens to have a nice string representation. You can verify this by doing

type(found)

A Tag is part of the hierarchy of objects that Beautiful Soup creates for you to be able to interact with the HTML. Another such object is NavigableString. NavigableString is a lot like a string, but it can only contain things that would go into the content portion of the HTML.

When you do

found.replace_with('<div id="content">stuff here</div>')

you are asking the Tag to be replaced with a NavigableString containing that literal text. The only way for HTML to be able to display that string is to escape all the angle brackets, as it's doing.

Instead of that mess, you probably want to keep your Tag, and replace only it's content:

found.string.replace_with('stuff here')

Notice that the correct replacement does not attempt to overwrite the tags.

When you do found.replace_with(...), the object referred to by the name found gets replaced in the parent hierarchy. However, the name found keeps pointing to the same outdated object as before. That is why printing soup shows the update, but printing found does not.

drupal rss xml transformed has tags

Drupal is using HTML entities to preserve the tags. If you don't want that, you need to strip them on Drupal's side of things. The exact method depends on the way you generate the feed.

If you do want them, you need to decode the entities before rendering it, otherwise the escaped entities will show up as characters. You can use http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#unescapeHtml%28java.lang.String%29 for this.

How to render encoded tags as proper HTML, rather than text?

Try this:

    String Input = "investment professionals.<BR /><BR /> blah blah blah";

String Output = Server.HtmlDecode(Input);


Related Topics



Leave a reply



Submit