Is it possible to create custom Entity Code character in HTML ? as if i want to display space on web page so i have to Write but i want to create custom Entity Code like
first i set code admin = 'This is admin'
&admin; so it should display on page as 'This is admin'.
if it is possible so please help me for that.
Hi Dear,
I do not know if it is possible or not in HTML.
but you can create in XML.
Example :
First You have to write top of XML file.
<!DOCTYPE custome_code [
<!ENTITY admin "This is admin">
]>
Now you can use &admin; in any where in XML file.
It's not possible, unfortunately, in current browsers (see Using custom entities in HTML documents) - the list of HTML entities is usually fixed. Using a server-side templating language (PHP, ASP.NET, etc.) would allow you to do something similar with variables. E.g. with PHP:
<?php
$admin = 'This is admin';
?>
Lorem ipsum <?=$admin?> fillare emptimum spatium.
Or in javascript / jQuery you could set up placeholders like <span class="admin"></span> and then fill them using:
$('.admin').html('This is admin');
Related
I am making a forum with markdown support.
I've been using meteor's markdown parser {{#markdown}} and have found something disturbing that I can't seem to figure out.
I am using {{#markdown}}{{content}}{{/markdown}} to render the content inserted into database.
The disturbing thing, for example, if someone writes up html without inserting it into the code block in the content...
example
<div class = "col-md-12">
Content Here
</div>
This will render as a column. They could also make buttons and etc through writing the HTML for it.
How to disable this behaviour so that when HTML is written it will not render into HTML but just simply show it as text?
You can write global helper, which will strip all html tags:
function stripHTML(string){
s = string.replace(/(<([^>]+)>)/ig, '');
return s;
}
Template.registerHelper('stripHTML', stripHTML)
Usage :
{{#markdown}}{{stripHTML content}}{{/markdown}}
Test it in console:
stripHTML("<div>Inside dive</div> Text outside")
i used tinymce to allow people to write content. But now i wan't them to edit their own content, i need to use tinymce again.
My problem is in my database, this content is composed of html tags, and when i try to load the text in my tinymce textarea (in edit view), i've got the raw content eg <p> Hello my name is <em>John</em> [...] </p> . But when they written this content, it was with "wysiwyg".
I want to convert this raw html to wysiwig.
here a screenshot of the raw html
and i want it to be like this when they click on "edit my content" button :
I use this:
echo <textarea name="icerik" id="editor1" rows="10" cols="80">'.htmlentities($satir->icerik).'</textarea>;
I use "htmlentities" method in php to convert html code to wysiwyg. When you write that converted text between and , you can get what you want.
Assuming you're using PHP of course. If not, try to search like for example "htmlentities in asp.net" or wait for another answers.
tinyMCE.activeEditor.setContent('<span>html data from your database</span>');
Use this:
strip_tags(stripslashes('row html content'))
I'm working on a mailer system where I'm required to replace variables in html template with actual values in our database. Earlier, I was getting a plain HTML template where I was required to overwrite the variable's actual value from database to the template itself. However, I was not comfortable with it. I made the following suggestion that instead of whole HTML template, pass XML containing the attributes which we seek to replace with actual values from database(sort of RSS). Now I am finding a way to put the actual values found from the database to the original template. Let us take an example:
<html>
<body>
<div var="toxml">
<li>
PROFILEID(This will be a number)
NAME
AGE(etc.)
</li>
</div>
</body>
</html>
The XML which will be generated out of this will be
<PROFILEID val="Number">
<NAME></NAME>
<AGE></AGE>
</PROFILEID>
Now I will stuff in the values from database in this xml only(XML parsing tools are available for php).
Now my question is, how can I put the stuffed values in the XML back to the HTML template from which it came?
First a bit of background information. I create HTML emails at my work place and the whole process is very tedious. It goes a little little like this...
Code markup for HTML using tables and some CSS
Parse HTML and CSS using Premailer so all CSS is inline
Test HTML works in all email clients
Create a copy of the inline version of HTML and start adding in proprietary variables to email tool used for sending emails, ie <%=constant.first_name%>, <%=unsubscribe_link%>
Test in email client to see if it works and client is happy. If not repeat steps 1 through 5 again.
So as you can see it gets really tedious after a while.
What I would like to do is create a command line script similar to Premailer which allows me to parse a HTML file with variables stored in it without destroying the example text already in the HTML. That way when you are previewing the HTML it all looks dandy.
For example...
Store the first name function as a variable for own use.
$first_name = "<%=constant.first_name%>
Then tell the parser what word(s) to replace with the appropriate variable.
<p>My name is <!-- $first_name -->Gavin<!-- /$first_name --></p>
So that the final output looks something like:
<p>My name is <%=constat.first_name%></p>
Would such a thing be possible? Is there a better syntax I could, a custom tag like <first_name>Gavin</first_name>, if the browser can handle it.
Any advice is helpful. :)
I've seen this done before using a syntax like:
{assign_variable:first_name="Jesse"}
Then, you could use it like:
{first_name}
The way you'd parse this (provided you're using PHP) would be something like:
<?php
// Our Template Code
$strHTML = <<<EOT
{assign_variable:first_name="Jesse"}
{assign_variable:last_name="Bunch"}
Hello, {first_name}!
EOT;
// Get all the variables
$arrMatches = array();
preg_match_all('/\{assign\_variable\:([a-zA-Z\_\-]*)\=\"([a-zA-Z0-9]+)\"\}/', $strHTML, $arrMatches);
// Remove the assign_variable tags
$strHTML = preg_replace('/\{assign\_variable\:([a-zA-Z\_\-]*)\=\"([a-zA-Z0-9]+)\"\}/', '', $strHTML);
// Combine them into key/values
$arrVariables = array_combine($arrMatches[1], $arrMatches[2]);
foreach($arrVariables as $key=>$value) {
// Replace the variable occurrences
$strHTML = str_replace('{' . $key . '}', $value, $strHTML);
}
// Send the parsed template
echo $strHTML;
Which outputs:
Hello, Jesse!
Note, this is a very basic example. Here are some improvements to make on this code before using it in production:
Edit the regex to allow the right characters.
Maybe implement a better replacement method than a loop
Check for parse errors
Benchmark performance
All in all, I think you get the idea. Hope this points you in the right direction.
I have a similar situation
I have created a "format template" like this:
<?php // section1 $var1/$var2 ?>
<head>
<title>$var1</title>
<meta name="description" content="$var2">
</head>
<?php // section2 $var1/$var2 ?>
<body>
hello: <p>$var1</p>
news for you: <p>$var2</p>
</body>
it is valid php code and valid html code, so you can edit it with dreamwaver or similar, and you can host it also.
then a php script replaces all ocurrences of vars in all sections.
I'm using WebBrowser to get source of html pages .
Our page source have some text and some html tags . like this :
FONT></P><P align=center><FONT color=#ccffcc size=3>**Hello There , This is a text in our html page** </FONT></P><P align=center> </P>
Html tags are random and we can not guess them . So is there any way to get texts only and separating them from html tags ?
you can use a TWebBrowser instance to parse and select the plaint text from html code.
see this sample
uses
MSHTML,
SHDocVw,
ActiveX;
function GetPlainText(Const Html: string): string;
var
DummyWebBrowser: TWebBrowser;
Document : IHtmlDocument2;
DummyVar : Variant;
begin
Result := '';
DummyWebBrowser := TWebBrowser.Create(nil);
try
//open an blank page to create a IHtmlDocument2 instance
DummyWebBrowser.Navigate('about:blank');
Document := DummyWebBrowser.Document as IHtmlDocument2;
if (Assigned(Document)) then //Check the Document
begin
DummyVar := VarArrayCreate([0, 0], varVariant); //Create a variant array to write the html code to the IHtmlDocument2
DummyVar[0] := Html; //assign the html code to the variant array
Document.Write(PSafeArray(TVarData(DummyVar).VArray)); //set the html in the document
Document.Close;
Result :=(Document.body as IHTMLBodyElement).createTextRange.text;//get the plain text
end;
finally
DummyWebBrowser.Free;
end;
end;
You should look at using the Delphi DOM HTML parser
If your asterisk is constant, you can simply get everychar between **.
If your asterisk is not constant you can rewrite this string and erase all tags (things who starting from < and ending with >. Or you can use some DOM parser library for it.
In essence: in general you can't.
HTML is a markup language with such a wide use and mind boggling possibilities to change the content dynamically that it is virtually impossible to do this (just look at how hard the web browser suppliers need to work to pass for instance the acid tests). So you can only do a subset.
For specific and well defined subsets of HTML, then you have a better chance:
First you need to get the HTML in a
string, then parse that HTML.
Getting the HTML can be done for instance using Indy (see answers to this question).
Parsing highly depends on your HTML and can be quite complex, you can try this question or this search.
You could use TWebBrowser as RRuz suggests, but it depends on Internet Explorer.
Modern Windows systems do not guarantee that Internet Explorer is installed any more...
--jeroen
Using Delphi HTML Component Library getting text only from HTML document is simple.
THtDocument.InnerText property returns formatted text without tags.