Move CKeditor configuration to a separate JS file
Remove unneeded try-except block
This commit is contained in:
parent
1d1f5fa218
commit
56844d93f2
@ -169,37 +169,34 @@ def convert_html_to_reportlab(pdf, text):
|
||||
soup = BeautifulSoup(text)
|
||||
# read all list elements...
|
||||
for element in soup.find_all('li'):
|
||||
try:
|
||||
# ... and replace ul list elements with <para><bullet>•</bullet>...<para>
|
||||
if element.parent.name == "ul":
|
||||
if element.ul:
|
||||
# for nested ul lists use simple spaces (pragmatic solution)
|
||||
element.li.insert(0,' ')
|
||||
element.insert_before(element.find_all('li'))
|
||||
element.clear()
|
||||
else:
|
||||
element.name = "para"
|
||||
bullet_tag = soup.new_tag("bullet")
|
||||
bullet_tag.string = "•"
|
||||
element.insert(0, bullet_tag)
|
||||
# ... and replace ol list elements with <para><bullet><seq id="%id"></seq>.</bullet>...</para>
|
||||
if element.parent.name == "ol":
|
||||
# set list id if element is the first of numbered list
|
||||
if not element.find_previous_sibling():
|
||||
id = random.randrange(0, 101)
|
||||
if element.ol:
|
||||
# nested ol list
|
||||
element.li.insert(0,' ')
|
||||
element.insert_before(element.find_all('li'))
|
||||
element.clear()
|
||||
else:
|
||||
element.name = "para"
|
||||
element.insert(0, soup.new_tag("bullet"))
|
||||
element.bullet.insert(0, soup.new_tag("seq"))
|
||||
element.bullet.seq['id'] = id
|
||||
element.bullet.insert(1, ".")
|
||||
except AttributeError:
|
||||
pass
|
||||
# ... and replace ul list elements with <para><bullet>•</bullet>...<para>
|
||||
if element.parent.name == "ul":
|
||||
if element.ul:
|
||||
# for nested ul lists use simple spaces (pragmatic solution)
|
||||
element.li.insert(0, ' ')
|
||||
element.insert_before(element.find_all('li'))
|
||||
element.clear()
|
||||
else:
|
||||
element.name = "para"
|
||||
bullet_tag = soup.new_tag("bullet")
|
||||
bullet_tag.string = "•"
|
||||
element.insert(0, bullet_tag)
|
||||
# ... and replace ol list elements with <para><bullet><seq id="%id"></seq>.</bullet>...</para>
|
||||
if element.parent.name == "ol":
|
||||
# set list id if element is the first of numbered list
|
||||
if not element.find_previous_sibling():
|
||||
id = random.randrange(0, 101)
|
||||
if element.ol:
|
||||
# nested ol list
|
||||
element.li.insert(0, ' ')
|
||||
element.insert_before(element.find_all('li'))
|
||||
element.clear()
|
||||
else:
|
||||
element.name = "para"
|
||||
element.insert(0, soup.new_tag("bullet"))
|
||||
element.bullet.insert(0, soup.new_tag("seq"))
|
||||
element.bullet.seq['id'] = id
|
||||
element.bullet.insert(1, ".")
|
||||
# remove tags which are not supported by reportlab (replace tags with their children tags)
|
||||
for tag in soup.find_all('ul'):
|
||||
tag.unwrap()
|
||||
|
@ -10,60 +10,8 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
<script type="text/javascript" src="{% static 'javascript/ckeditor/ckeditor.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
var ck_options = {
|
||||
|
||||
// Using a custom CSS file allows us to specifically style elements entered
|
||||
// using the editor. Using the CSS prefix class .ckeditor_html prevents these
|
||||
// styles from meddling with the main layout
|
||||
|
||||
contentsCss: "{% static 'styles/ckeditor.css' %}",
|
||||
bodyClass: "ckeditor_html",
|
||||
|
||||
allowedContent:
|
||||
'h1 h2 h3 pre blockquote b i u strike;' +
|
||||
|
||||
// A workaround for the problem described in http://dev.ckeditor.com/ticket/10192
|
||||
// Hopefully, the problem will be solved in the final version of CKEditor 4.1
|
||||
// If so, then {margin-left} can be removed
|
||||
'p{margin-left};' +
|
||||
|
||||
'a[!href];' +
|
||||
'table tr th td caption;' +
|
||||
'ol ul li;' +
|
||||
'span{!font-family};' +
|
||||
'span{!color};',
|
||||
removePlugins: "save, print, preview, pagebreak, templates, showblocks, magicline",
|
||||
|
||||
// Not part of the standard package of CKEditor
|
||||
// http://ckeditor.com/addon/insertpre
|
||||
extraPlugins: "insertpre",
|
||||
|
||||
toolbar_Full: [
|
||||
{ name: 'document', items : [ 'Source','-','Save','DocProps','Preview','Print','-','Templates' ] },
|
||||
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
|
||||
{ name: 'editing', items : [ 'Find','Replace','-','SpellChecker', 'Scayt' ] },
|
||||
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
|
||||
{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
|
||||
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Pre','InsertPre','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
|
||||
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
|
||||
{ name: 'styles', items : [ 'Format','FontSize' ] },
|
||||
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] }
|
||||
],
|
||||
toolbar: 'Full'
|
||||
};
|
||||
|
||||
// Override the tags 'strong' and 'em' so that reportlab can read it
|
||||
CKEDITOR.config.coreStyles_bold = { element : 'b', overrides : 'strong' };
|
||||
CKEDITOR.config.coreStyles_italic = { element : 'i', overrides : 'em' };
|
||||
|
||||
CKEDITOR.replace('id_text', ck_options);
|
||||
CKEDITOR.replace('id_reason', ck_options);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="{% static 'javascript/ckeditor/ckeditor.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'javascript/ckeditor-config.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}
|
||||
|
53
openslides/static/javascript/ckeditor-config.js
Normal file
53
openslides/static/javascript/ckeditor-config.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Configuration file for the CKeditor
|
||||
*/
|
||||
$(function() {
|
||||
var ck_options = {
|
||||
|
||||
// Using a custom CSS file allows us to specifically style elements entered
|
||||
// using the editor. Using the CSS prefix class .ckeditor_html prevents these
|
||||
// styles from meddling with the main layout
|
||||
|
||||
contentsCss: "/static/styles/ckeditor.css",
|
||||
bodyClass: "ckeditor_html",
|
||||
|
||||
allowedContent:
|
||||
'h1 h2 h3 pre blockquote b i u strike;' +
|
||||
|
||||
// A workaround for the problem described in http://dev.ckeditor.com/ticket/10192
|
||||
// Hopefully, the problem will be solved in the final version of CKEditor 4.1
|
||||
// If so, then {margin-left} can be removed
|
||||
'p{margin-left};' +
|
||||
|
||||
'a[!href];' +
|
||||
'table tr th td caption;' +
|
||||
'ol ul li;' +
|
||||
'span{!font-family};' +
|
||||
'span{!color};',
|
||||
removePlugins: "save, print, preview, pagebreak, templates, showblocks, magicline",
|
||||
|
||||
// Not part of the standard package of CKEditor
|
||||
// http://ckeditor.com/addon/insertpre
|
||||
extraPlugins: "insertpre",
|
||||
|
||||
toolbar_Full: [
|
||||
{ name: 'document', items : [ 'Source','-','Save','DocProps','Preview','Print','-','Templates' ] },
|
||||
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
|
||||
{ name: 'editing', items : [ 'Find','Replace','-','SpellChecker', 'Scayt' ] },
|
||||
{ name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
|
||||
{ name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
|
||||
{ name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Pre','InsertPre','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
|
||||
{ name: 'links', items : [ 'Link','Unlink','Anchor' ] },
|
||||
{ name: 'styles', items : [ 'Format','FontSize' ] },
|
||||
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] }
|
||||
],
|
||||
toolbar: 'Full'
|
||||
};
|
||||
|
||||
// Override the tags 'strong' and 'em' so that reportlab can read it
|
||||
CKEDITOR.config.coreStyles_bold = { element : 'b', overrides : 'strong' };
|
||||
CKEDITOR.config.coreStyles_italic = { element : 'i', overrides : 'em' };
|
||||
|
||||
CKEDITOR.replace('id_text', ck_options);
|
||||
CKEDITOR.replace('id_reason', ck_options);
|
||||
});
|
@ -71,7 +71,7 @@ stylesheet.add(ParagraphStyle(
|
||||
bulletIndent=10,
|
||||
bulletFontSize=10,
|
||||
bulletColor=colors.black,
|
||||
leftIndent = 30
|
||||
leftIndent=30
|
||||
))
|
||||
stylesheet.add(ParagraphStyle(
|
||||
name='InnerMonotypeParagraph',
|
||||
|
Loading…
Reference in New Issue
Block a user