Moved html_escape from NarrativeWeb to libhtml ... use: from libhtml import html_escape as html_escape
svn: r16638
This commit is contained in:
parent
4a67b6fdaa
commit
4dd853135e
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
@ -28,6 +30,11 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# Python modules
|
||||
#------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
"""
|
||||
HTML operations.
|
||||
|
||||
@ -97,6 +104,46 @@ _START_CLOSE = set([
|
||||
'param'
|
||||
])
|
||||
|
||||
_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE)
|
||||
_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE)
|
||||
_html_replacement = {
|
||||
"&" : "&",
|
||||
">" : ">",
|
||||
"<" : "<",
|
||||
"°" : "",
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
# html_ecape function
|
||||
#-----------------------------------------------------------------------
|
||||
# This command then defines the 'html_escape' option for escaping
|
||||
# special characters for presentation in HTML based on the above list.
|
||||
def html_escape(text):
|
||||
"""Convert the text and replace some characters with a &# variant."""
|
||||
|
||||
# First single characters, no quotes
|
||||
text = ''.join([_html_replacement.get(c, c) for c in text])
|
||||
|
||||
# Deal with double quotes.
|
||||
while 1:
|
||||
m = _html_dbl_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '“' + m.group(2) + '”' + m.group(3)
|
||||
# Replace remaining double quotes.
|
||||
text = text.replace('"', '"')
|
||||
|
||||
# Deal with single quotes.
|
||||
text = text.replace("'s ", '’s ')
|
||||
while 1:
|
||||
m = _html_sng_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '‘' + m.group(2) + '’' + m.group(3)
|
||||
# Replace remaining single quotes.
|
||||
text = text.replace("'", ''')
|
||||
|
||||
return text
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Html class.
|
||||
|
@ -103,6 +103,9 @@ from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
||||
# src/plugins/lib/libhtml.py
|
||||
from libhtml import Html
|
||||
|
||||
#import the html_escape function
|
||||
from libhtml import html_escape as html_escape
|
||||
|
||||
# import styled notes from
|
||||
# src/plugins/lib/libhtmlbackend.py
|
||||
from libhtmlbackend import HtmlBackend, process_spaces
|
||||
@ -197,46 +200,9 @@ wrapper = TextWrapper()
|
||||
wrapper.break_log_words = True
|
||||
wrapper.width = 20
|
||||
|
||||
_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE)
|
||||
_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE)
|
||||
_html_replacement = {
|
||||
"&" : "&",
|
||||
">" : ">",
|
||||
"<" : "<",
|
||||
}
|
||||
|
||||
PLUGMAN = GuiPluginManager.get_instance()
|
||||
CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
|
||||
|
||||
# This command then defines the 'html_escape' option for escaping
|
||||
# special characters for presentation in HTML based on the above list.
|
||||
def html_escape(text):
|
||||
"""Convert the text and replace some characters with a &# variant."""
|
||||
|
||||
# First single characters, no quotes
|
||||
text = ''.join([_html_replacement.get(c, c) for c in text])
|
||||
|
||||
# Deal with double quotes.
|
||||
while 1:
|
||||
m = _html_dbl_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '“' + m.group(2) + '”' + m.group(3)
|
||||
# Replace remaining double quotes.
|
||||
text = text.replace('"', '"')
|
||||
|
||||
# Deal with single quotes.
|
||||
text = text.replace("'s ", '’s ')
|
||||
while 1:
|
||||
m = _html_sng_quotes.match(text)
|
||||
if not m:
|
||||
break
|
||||
text = m.group(1) + '‘' + m.group(2) + '’' + m.group(3)
|
||||
# Replace remaining single quotes.
|
||||
text = text.replace("'", ''')
|
||||
|
||||
return text
|
||||
|
||||
def name_to_md5(text):
|
||||
"""This creates an MD5 hex string to be used as filename."""
|
||||
return md5(text).hexdigest()
|
||||
|
Loading…
Reference in New Issue
Block a user