I was looking for a function to transform a unicode string into
htmlentities. Not only the usual html escaping thing but all
characters.
As I didn't find I wrote my own:
# -*- coding: utf-8 -*-
from htmlentitydefs import codepoint2name
def unicode2htmlent ities(u):
htmlentities = list()
for c in u:
if ord(c) < 128:
htmlentities.ap pend(c)
else:
htmlentities.ap pend('&%s;' % codepoint2name[ord(c)])
return ''.join(htmlent ities)
print unicode2htmlent ities(u'São Paulo')
Is there a function like that in one of python builtin modules? If not
is there a better way to do it?
Regards, Clodoaldo Pinto Neto 6 4707
"Clodoaldo" <cl************ *@gmail.comwrot e in message
news:11******** *************@n 15g2000prd.goog legroups.com...
>I was looking for a function to transform a unicode string into htmlentities .
>>u'São Paulo'.encode(' ascii', 'xmlcharrefrepl ace')
'São Paulo'
On May 29, 12:57 pm, "Richard Brodie" <R.Bro...@rl.ac .ukwrote:
"Clodoaldo" <clodoaldo.pi.. .@gmail.comwrot e in message
news:11******** *************@n 15g2000prd.goog legroups.com...
I was looking for a function to transform a unicode string into
htmlentities.
>u'São Paulo'.encode(' ascii', 'xmlcharrefrepl ace')
'São Paulo'
That was a fast answer. I would never find that myself.
Thanks, Clodoaldo
Clodoaldo <cl************ *@gmail.comwrot e:
On May 29, 12:57 pm, "Richard Brodie" <R.Bro...@rl.ac .ukwrote:
>"Clodoaldo" <clodoaldo.pi.. .@gmail.comwrot e in message
news:11******* **************@ n15g2000prd.goo glegroups.com.. .
>I was looking for a function to transform a unicode string into htmlentities . u'São Paulo'.encode(' ascii', 'xmlcharrefrepl ace')
'São Paulo'
That was a fast answer. I would never find that myself.
You might actually want:
>>cgi.escape(u' São Paulo & Espírito Santo').encode( 'ascii', 'xmlcharrefrepl ace')
'São Paulo & Espírito Santo'
as you have to be sure to escape any ampersands in your unicode
string before doing the encode.
On 29 maj 2007, at 17.52, Clodoaldo wrote:
I was looking for a function to transform a unicode string into
htmlentities. Not only the usual html escaping thing but all
characters.
As I didn't find I wrote my own:
# -*- coding: utf-8 -*-
from htmlentitydefs import codepoint2name
def unicode2htmlent ities(u):
htmlentities = list()
for c in u:
if ord(c) < 128:
htmlentities.ap pend(c)
else:
htmlentities.ap pend('&%s;' % codepoint2name[ord(c)])
return ''.join(htmlent ities)
print unicode2htmlent ities(u'São Paulo')
Is there a function like that in one of python builtin modules? If not
is there a better way to do it?
Regards, Clodoaldo Pinto Neto
In many cases, the need to use html/xhtml entities can be avoided by
generating
utf8- coded pages.
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone" to************@ comhem.se
On May 30, 8:53 am, Tommy Nordgren <tommy.nordg... @comhem.sewrote :
On 29 maj 2007, at 17.52, Clodoaldo wrote:
I was looking for a function to transform a unicode string into
htmlentities. Not only the usual html escaping thing but all
characters.
As I didn't find I wrote my own:
# -*- coding: utf-8 -*-
from htmlentitydefs import codepoint2name
def unicode2htmlent ities(u):
htmlentities = list()
for c in u:
if ord(c) < 128:
htmlentities.ap pend(c)
else:
htmlentities.ap pend('&%s;' % codepoint2name[ord(c)])
return ''.join(htmlent ities)
print unicode2htmlent ities(u'São Paulo')
Is there a function like that in one of python builtin modules? If not
is there a better way to do it?
Regards, Clodoaldo Pinto Neto
In many cases, the need to use html/xhtml entities can be avoidedby
generating
utf8- coded pages.
Sure. All my pages are utf-8 encoded. The case I'm dealing with is an
email link which subject has non ascii characters like in:
<a href=mailto:ex* ****@sample.com ?subject=Dúvida s>Mail to</a>
Somehow when the user clicks on the link the subject goes to his email
client with the non ascii chars as garbage.
And before someone points that I should not expose email addresses,
the email is only linked with the consent of the owner and the source
is obfuscated to make it harder for a robot to harvest it.
Regards, Clodoaldo
On May 30, 4:25 am, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
Clodoaldo <clodoaldo.pi.. .@gmail.comwrot e:
On May 29, 12:57 pm, "Richard Brodie" <R.Bro...@rl.ac .ukwrote:
"Clodoaldo" <clodoaldo.pi.. .@gmail.comwrot e in message
>news:11******* **************@ n15g2000prd.goo glegroups.com.. .
I was looking for a function to transform a unicode string into
htmlentities. u'São Paulo'.encode(' ascii', 'xmlcharrefrepl ace')
'São Paulo'
That was a fast answer. I would never find that myself.
You might actually want:
>cgi.escape(u'S ão Paulo & Espírito Santo').encode( 'ascii', 'xmlcharrefrepl ace')
'São Paulo & Espírito Santo'
as you have to be sure to escape any ampersands in your unicode
string before doing the encode.
I will do it. Thanks.
Regards, Clodoaldo. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nancy |
last post by:
I recently completed a web page, "Browser Tests of Entities in 2004".
http://www.santagata.us/characters/CharacterEntities.html
It shows those characters that work in all of the version 5.2+
browsers that were tested and those that only work in some of them.
Take a look, maybe you'll consider it useful.
This is not my field (I'm an architect - you know the house
construction kind), so if you notice any inaccuracies I'd appreciate a...
|
by: dalei |
last post by:
My question is presented more clearly in following web page:
http://www.pinyinology.com/signs2.html
<html>
HTML entities display outside script tags:
a¹, a², a³, a⁴
But unicode doesn't display outside script tags:
a\xb2, a\xb3, a\u2074
|
by: Beat Richli |
last post by:
Hello
i have following problem with ASP (using Interdev, Win2003 Server): if a
special character is entered in a textbox, ASP or the Client Browser (IE 6)
seems to convert this character in HTML entities.
eg characters on this site:
http://unicode.e-workers.de/kyrillisch.php
come back as eg Л . i'm not shure, where exactly this happens. it
doesn't happen on ASP.NET sites though. the top of those documents looks
|
by: Mark Johnson |
last post by:
I wonder if anyone has a solution? I wanted to use the web browser
control as a 'zoom' box for a smaller textbox. I can format in the
control, and save whatever formatting as HTML code back to the textbox
when the web browser is closed. The only problem comes in the use of
numeric entities to specify Unicode. The web browser control is fine
when it comes to named entities, like . And there are a lot of
named entities, just...
|
by: zunbeltz |
last post by:
Hi,
I'm parsing html. I have a page with a lot of html enitties for hebrew
characters. When i print what i get are blanks, dots and commas. How
can i decode this entities to unicode charachters?
TIA
Zunbeltz
| |
by: lorenzo.viscanti |
last post by:
X-No-Archive: yes
Hi, I've found lots of material on the net about unicode html
conversions, but still i'm having many problems converting unicode
characters to html entities. Is there any available function to solve
this issue?
As an example I would like to do this kind of conversion:
\uc3B4 =ô
for all available html entities.
thanks,
|
by: Frantic |
last post by:
I'm working on a list of japaneese entities that contain the entity,
the unicode hexadecimal code and the xml/sgml entity used for that
entity. A unicode document is read into the program, then the program
sorts out every doublet and the hexadecimal unicode code is extracted,
but I dont know a way to find the xml or sgml-entity equivalent to the
unicode code. Anyone who could give me a pointer?
Best regards
|
by: Laangen_LU |
last post by:
Dear Group,
my first post to this group, so if I'm on the wrong group, my
apologies.
I'm trying to send out an email in Chinese lanuage using the mail()
function in PHP.
Subject and mailbody are stored as Unicode entities (eg. 註)
|
by: Steven D'Aprano |
last post by:
I have a string containing Latin-1 characters:
s = u"© and many more..."
I want to convert it to HTML entities:
result =>
"© and many more..."
Decimal/hex escapes would be acceptable:
|
by: neovantage |
last post by:
hey geeks,
I am using a function which convert unicode to entities. So that i can save values into mysql database into entities. This function really helps me when i display the store entity data into web page n it shows special charactor easily. Here is the function code
function charset_decode_utf_8($string) {
/* Only do the slow convert if there are 8-bit characters */
/* avoid using 0xA0 (\240) in ereg ranges. RH73 does not...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |