Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
c5482ffc
Commit
c5482ffc
authored
May 13, 2004
by
Christian Heimes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merging from tiran-restfixing-brnach
parent
7e454840
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
114 deletions
+64
-114
lib/python/reStructuredText/__init__.py
lib/python/reStructuredText/__init__.py
+64
-55
lib/python/reStructuredText/html4zope.py
lib/python/reStructuredText/html4zope.py
+0
-59
No files found.
lib/python/reStructuredText/__init__.py
View file @
c5482ffc
...
@@ -10,20 +10,30 @@
...
@@ -10,20 +10,30 @@
# FOR A PARTICULAR PURPOSE
# FOR A PARTICULAR PURPOSE
#
#
##############################################################################
##############################################################################
"""Wrapper to integrate reStructuredText into Zope
""" Wrapper to integrate reStructuredText into Zope """
This implementation requires docutils 0.3.4+ from http://docutils.sf.net/
"""
__all__
=
(
"HTML"
,
)
import
sys
,
os
,
locale
from
App.config
import
getConfiguration
import
sys
,
os
from
docutils.core
import
publish_parts
import
docutils.core
from
docutils.io
import
StringOutput
,
StringInput
from
App.config
import
getConfiguration
# get encoding
default_enc
=
sys
.
getdefaultencoding
()
default_enc
=
sys
.
getdefaultencoding
()
default_output_encoding
=
getConfiguration
().
rest_output_encoding
or
default_enc
default_output_encoding
=
getConfiguration
().
rest_output_encoding
or
default_enc
default_input_encoding
=
getConfiguration
().
rest_input_encoding
or
default_enc
default_input_encoding
=
getConfiguration
().
rest_input_encoding
or
default_enc
# starting level for <H> elements (default behaviour inside Zope is <H3>)
default_level
=
int
(
os
.
environ
.
get
(
'STX_DEFAULT_LEVEL'
,
3
))
initial_header_level
=
getConfiguration
().
rest_header_level
or
default_level
# default language
default_lang
=
getConfiguration
().
locale
or
locale
.
getdefaultlocale
()[
0
]
if
default_lang
and
'_'
in
default_lang
:
default_lang
=
default_lang
[:
default_lang
.
index
(
'_'
)]
class
Warnings
:
class
Warnings
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -32,12 +42,15 @@ class Warnings:
...
@@ -32,12 +42,15 @@ class Warnings:
def
write
(
self
,
message
):
def
write
(
self
,
message
):
self
.
messages
.
append
(
message
)
self
.
messages
.
append
(
message
)
def
HTML
(
src
,
def
HTML
(
src
,
writer
=
'html4
zope'
,
writer
=
'html4
css1'
,
report_level
=
1
,
report_level
=
1
,
stylesheet
=
'default.css'
,
stylesheet
=
'default.css'
,
input_encoding
=
default_input_encoding
,
input_encoding
=
default_input_encoding
,
output_encoding
=
default_output_encoding
):
output_encoding
=
default_output_encoding
,
language_code
=
default_lang
,
warnings
=
None
,
settings
=
{}):
""" render HTML from a reStructuredText string
""" render HTML from a reStructuredText string
...
@@ -52,48 +65,44 @@ def HTML(src,
...
@@ -52,48 +65,44 @@ def HTML(src,
- 'input_encoding' - encoding of the reST input string
- 'input_encoding' - encoding of the reST input string
- 'output_encoding' - encoding of the rendered HTML output
- 'output_encoding' - encoding of the rendered HTML output
"""
- 'report_level' - verbosity of reST parser
pub
=
docutils
.
core
.
Publisher
()
pub
.
set_reader
(
'standalone'
,
None
,
'restructuredtext'
)
pub
.
set_writer
(
writer
)
# go with the defaults
pub
.
get_settings
()
pub
.
settings
.
stylesheet
=
stylesheet
# this is needed, but doesn't seem to do anything
pub
.
settings
.
_destination
=
''
# set the reporting level to something sane
pub
.
settings
.
report_level
=
report_level
# don't break if we get errors
pub
.
settings
.
halt_level
=
6
# remember warnings
pub
.
settings
.
warning_stream
=
Warnings
()
# input
pub
.
source
=
StringInput
(
source
=
src
,
encoding
=
input_encoding
)
# output - not that it's needed
pub
.
destination
=
StringOutput
(
encoding
=
output_encoding
)
# parse!
document
=
pub
.
reader
.
read
(
pub
.
source
,
pub
.
parser
,
pub
.
settings
)
# transform
pub
.
apply_transforms
(
document
)
warnings
=
''
.
join
(
pub
.
settings
.
warning_stream
.
messages
)
# do the format
return
pub
.
writer
.
write
(
document
,
pub
.
destination
)
from
docutils
import
writers
- 'language_code' - docutils language
import
html4zope
- 'warnings' - will be overwritten with a string containing the warnings
- 'settings' - dict of settings to pass in to Docutils, with priority
writers
.
html4zope
=
html4zope
"""
sys
.
modules
[
'docutils.writers.html4zope'
]
=
html4zope
# Docutils settings:
settings
=
settings
.
copy
()
settings
[
'input_encoding'
]
=
input_encoding
settings
[
'output_encoding'
]
=
output_encoding
settings
[
'stylesheet'
]
=
stylesheet
settings
[
'language_code'
]
=
language_code
# starting level for <H> elements:
settings
[
'initial_header_level'
]
=
initial_header_level
# set the reporting level to something sane:
settings
[
'report_level'
]
=
report_level
# don't break if we get errors:
settings
[
'halt_level'
]
=
6
# remember warnings:
settings
[
'warning_stream'
]
=
warning_stream
=
Warnings
()
parts
=
publish_parts
(
source
=
src
,
writer_name
=
writer
,
settings_overrides
=
settings
,
config_section
=
'zope application'
)
output
=
(
'<h%(level)s class="title">%(title)s</h%(level)s>
\
n
%(body)s'
%
{
'level'
:
initial_header_level
,
'title'
:
parts
[
'title'
],
'body'
:
parts
[
'body'
]}).
encode
(
output_encoding
)
# what to do with this? (not used in the original code)
warnings
=
''
.
join
(
warning_stream
.
messages
)
return
output
__all__
=
(
"HTML"
,
)
lib/python/reStructuredText/html4zope.py
deleted
100644 → 0
View file @
7e454840
# Author: Andreas Jung
# Contact: andreas@andreas-jung.com
# Revision: $Revision: 1.1 $
# Date: $Date: 2003/11/30 16:16:06 $
# Copyright: This module has been placed in the public domain.
"""
Writer module to integrate reST into Zope. This writer subclasses the standard
html4css1 writer and changes the starting level for <H> elements from 1 to 3
(default behaviour inside Zope.
"""
__docformat__
=
'reStructuredText'
from
docutils
import
nodes
from
docutils.writers.html4css1
import
Writer
as
CSS1Writer
,
HTMLTranslator
as
CSS1HTMLTranslator
import
os
default_level
=
int
(
os
.
environ
.
get
(
'STX_DEFAULT_LEVEL'
,
3
))
class
Writer
(
CSS1Writer
):
def
__init__
(
self
):
CSS1Writer
.
__init__
(
self
)
self
.
translator_class
=
HTMLTranslator
class
HTMLTranslator
(
CSS1HTMLTranslator
):
def
astext
(
self
):
return
''
.
join
(
self
.
body
)
def
visit_title
(
self
,
node
):
"""Only 6 section levels are supported by HTML."""
if
isinstance
(
node
.
parent
,
nodes
.
topic
):
self
.
body
.
append
(
self
.
starttag
(
node
,
'p'
,
''
,
CLASS
=
'topic-title'
))
if
node
.
parent
.
hasattr
(
'id'
):
self
.
body
.
append
(
self
.
starttag
({},
'a'
,
''
,
name
=
node
.
parent
[
'id'
]))
self
.
context
.
append
(
'</a></p>
\
n
'
)
else
:
self
.
context
.
append
(
'</p>
\
n
'
)
elif
self
.
section_level
==
0
:
# document title
self
.
head
.
append
(
'<title>%s</title>
\
n
'
%
self
.
encode
(
node
.
astext
()))
self
.
body
.
append
(
self
.
starttag
(
node
,
'h%d'
%
default_level
,
''
,
CLASS
=
'title'
))
self
.
context
.
append
(
'</h%d>
\
n
'
%
default_level
)
else
:
self
.
body
.
append
(
self
.
starttag
(
node
,
'h%s'
%
(
default_level
+
self
.
section_level
-
1
),
''
))
atts
=
{}
if
node
.
parent
.
hasattr
(
'id'
):
atts
[
'name'
]
=
node
.
parent
[
'id'
]
if
node
.
hasattr
(
'refid'
):
atts
[
'class'
]
=
'toc-backref'
atts
[
'href'
]
=
'#'
+
node
[
'refid'
]
self
.
body
.
append
(
self
.
starttag
({},
'a'
,
''
,
**
atts
))
self
.
context
.
append
(
'</a></h%s>
\
n
'
%
((
default_level
+
self
.
section_level
-
1
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment