author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Dec 2015 14:12:59 +0100 | |
changeset 10981 | 45bc791275b4 |
parent 10960 | 9e64fddebc89 |
permissions | -rw-r--r-- |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4771
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""rest publishing functions |
19 |
||
996 | 20 |
contains some functions and setup of docutils for cubicweb. Provides the |
21 |
following ReST directives: |
|
22 |
||
23 |
* `eid`, create link to entity in the repository by their eid |
|
24 |
||
25 |
* `card`, create link to card entity in the repository by their wikiid |
|
26 |
(proposing to create it when the refered card doesn't exist yet) |
|
27 |
||
28 |
* `winclude`, reference to a web documentation file (in wdoc/ directories) |
|
29 |
||
30 |
* `sourcecode` (if pygments is installed), source code colorization |
|
0 | 31 |
|
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
32 |
* `rql-table`, create a table from a RQL query |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
33 |
|
0 | 34 |
""" |
35 |
__docformat__ = "restructuredtext en" |
|
36 |
||
10952
4f28cb25b6c1
[rest] avoid field on two lines if name is above some size limit. Closes #8961835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10023
diff
changeset
|
37 |
import sys |
0 | 38 |
from itertools import chain |
39 |
from logging import getLogger |
|
40 |
from os.path import join |
|
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10588
diff
changeset
|
41 |
|
10708
d5e3fffa9c07
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
42 |
from six import text_type |
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10588
diff
changeset
|
43 |
from six.moves.urllib.parse import urlsplit |
0 | 44 |
|
45 |
from docutils import statemachine, nodes, utils, io |
|
4771
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
46 |
from docutils.core import Publisher |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
47 |
from docutils.parsers.rst import Parser, states, directives, Directive |
0 | 48 |
from docutils.parsers.rst.roles import register_canonical_role, set_classes |
49 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2311
diff
changeset
|
50 |
from logilab.mtconverter import ESC_UCAR_TABLE, ESC_CAR_TABLE, xml_escape |
0 | 51 |
|
2467
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
52 |
from cubicweb import UnknownEid |
704
0c2c8f0a6ded
new ext package for modules depending on an option third party package
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
53 |
from cubicweb.ext.html4zope import Writer |
0 | 54 |
|
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
55 |
from cubicweb.web.views import vid_from_rset # XXX better not to import c.w.views here... |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
56 |
|
0 | 57 |
# We provide our own parser as an attempt to get rid of |
58 |
# state machine reinstanciation |
|
59 |
||
60 |
import re |
|
61 |
# compile states.Body patterns |
|
62 |
for k, v in states.Body.patterns.items(): |
|
63 |
if isinstance(v, str): |
|
64 |
states.Body.patterns[k] = re.compile(v) |
|
65 |
||
66 |
# register ReStructured Text mimetype / extensions |
|
67 |
import mimetypes |
|
68 |
mimetypes.add_type('text/rest', '.rest') |
|
69 |
mimetypes.add_type('text/rest', '.rst') |
|
70 |
||
71 |
||
72 |
LOGGER = getLogger('cubicweb.rest') |
|
73 |
||
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
74 |
|
0 | 75 |
def eid_reference_role(role, rawtext, text, lineno, inliner, |
76 |
options={}, content=[]): |
|
77 |
try: |
|
78 |
try: |
|
79 |
eid_num, rest = text.split(u':', 1) |
|
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
80 |
except ValueError: |
0 | 81 |
eid_num, rest = text, '#'+text |
82 |
eid_num = int(eid_num) |
|
83 |
if eid_num < 0: |
|
84 |
raise ValueError |
|
85 |
except ValueError: |
|
86 |
msg = inliner.reporter.error( |
|
87 |
'EID number must be a positive number; "%s" is invalid.' |
|
88 |
% text, line=lineno) |
|
89 |
prb = inliner.problematic(rawtext, rawtext, msg) |
|
90 |
return [prb], [msg] |
|
91 |
# Base URL mainly used by inliner.pep_reference; so this is correct: |
|
92 |
context = inliner.document.settings.context |
|
2467
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
93 |
try: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2680
diff
changeset
|
94 |
refedentity = context._cw.entity_from_eid(eid_num) |
2467
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
95 |
except UnknownEid: |
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
96 |
ref = '#' |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2680
diff
changeset
|
97 |
rest += u' ' + context._cw._('(UNEXISTANT EID)') |
2467
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
98 |
else: |
6983631f5d0d
don't fail on unknown eid, simply issue a warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2312
diff
changeset
|
99 |
ref = refedentity.absolute_url() |
0 | 100 |
set_classes(options) |
101 |
return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref, |
|
102 |
**options)], [] |
|
103 |
||
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
104 |
|
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
105 |
def rql_role(role, rawtext, text, lineno, inliner, options={}, content=[]): |
10023
c3ab46842b2d
[book] fix docstrings to please sphinx
David Douard <david.douard@logilab.fr>
parents:
9592
diff
changeset
|
106 |
"""``:rql:`<rql-expr>``` or ``:rql:`<rql-expr>:<vid>``` |
8710
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
107 |
|
10023
c3ab46842b2d
[book] fix docstrings to please sphinx
David Douard <david.douard@logilab.fr>
parents:
9592
diff
changeset
|
108 |
Example: ``:rql:`Any X,Y WHERE X is CWUser, X login Y:table``` |
8710
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
109 |
|
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
110 |
Replace the directive with the output of applying the view to the resultset |
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
111 |
returned by the query. |
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
112 |
|
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
113 |
"X eid %(userid)s" can be used in the RQL query for this query will be |
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
114 |
executed with the argument {'userid': _cw.user.eid}. |
becbbbc840b8
[ext/rest] fix docstring of rql_role()
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
115 |
""" |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
116 |
_cw = inliner.document.settings.context._cw |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
117 |
text = text.strip() |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
118 |
if ':' in text: |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
119 |
rql, vid = text.rsplit(u':', 1) |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
120 |
rql = rql.strip() |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
121 |
else: |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
122 |
rql, vid = text, None |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
123 |
_cw.ensure_ro_rql(rql) |
7732
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
124 |
try: |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
125 |
rset = _cw.execute(rql, {'userid': _cw.user.eid}) |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
126 |
if rset: |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
127 |
if vid is None: |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
128 |
vid = vid_from_rset(_cw, rset, _cw.vreg.schema) |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
129 |
else: |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
130 |
vid = 'noresult' |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
131 |
view = _cw.vreg['views'].select(vid, _cw, rset=rset) |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
132 |
content = view.render() |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
133 |
except Exception as exc: |
9517
3338b2205ea3
Typo in comments and error messages
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents:
9322
diff
changeset
|
134 |
content = 'an error occurred while interpreting this rql directive: %r' % exc |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
135 |
set_classes(options) |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
136 |
return [nodes.raw('', content, format='html')], [] |
0 | 137 |
|
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
138 |
|
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
139 |
def bookmark_role(role, rawtext, text, lineno, inliner, options={}, content=[]): |
10023
c3ab46842b2d
[book] fix docstrings to please sphinx
David Douard <david.douard@logilab.fr>
parents:
9592
diff
changeset
|
140 |
"""``:bookmark:`<bookmark-eid>``` or ``:bookmark:`<eid>:<vid>``` |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
141 |
|
10023
c3ab46842b2d
[book] fix docstrings to please sphinx
David Douard <david.douard@logilab.fr>
parents:
9592
diff
changeset
|
142 |
Example: ``:bookmark:`1234:table``` |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
143 |
|
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
144 |
Replace the directive with the output of applying the view to the resultset |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
145 |
returned by the query stored in the bookmark. By default, the view is the one |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
146 |
stored in the bookmark, but it can be overridden by the directive as in the |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
147 |
example above. |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
148 |
|
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
149 |
"X eid %(userid)s" can be used in the RQL query stored in the Bookmark, for |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
150 |
this query will be executed with the argument {'userid': _cw.user.eid}. |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
151 |
""" |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
152 |
_cw = inliner.document.settings.context._cw |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
153 |
text = text.strip() |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
154 |
try: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
155 |
if ':' in text: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
156 |
eid, vid = text.rsplit(u':', 1) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
157 |
eid = int(eid) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
158 |
else: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
159 |
eid, vid = int(text), None |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
160 |
except ValueError: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
161 |
msg = inliner.reporter.error( |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
162 |
'EID number must be a positive number; "%s" is invalid.' |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
163 |
% text, line=lineno) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
164 |
prb = inliner.problematic(rawtext, rawtext, msg) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
165 |
return [prb], [msg] |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
166 |
try: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
167 |
bookmark = _cw.entity_from_eid(eid) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
168 |
except UnknownEid: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
169 |
msg = inliner.reporter.error('Unknown EID %s.' % text, line=lineno) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
170 |
prb = inliner.problematic(rawtext, rawtext, msg) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
171 |
return [prb], [msg] |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
172 |
try: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
173 |
params = dict(_cw.url_parse_qsl(urlsplit(bookmark.path).query)) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
174 |
rql = params['rql'] |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
175 |
if vid is None: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
176 |
vid = params.get('vid') |
10588
fdaa0e4b7eaf
[py3k] except as
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10212
diff
changeset
|
177 |
except (ValueError, KeyError) as exc: |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
178 |
msg = inliner.reporter.error('Could not parse bookmark path %s [%s].' |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
179 |
% (bookmark.path, exc), line=lineno) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
180 |
prb = inliner.problematic(rawtext, rawtext, msg) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
181 |
return [prb], [msg] |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
182 |
try: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
183 |
rset = _cw.execute(rql, {'userid': _cw.user.eid}) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
184 |
if rset: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
185 |
if vid is None: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
186 |
vid = vid_from_rset(_cw, rset, _cw.vreg.schema) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
187 |
else: |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
188 |
vid = 'noresult' |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
189 |
view = _cw.vreg['views'].select(vid, _cw, rset=rset) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
190 |
content = view.render() |
10588
fdaa0e4b7eaf
[py3k] except as
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10212
diff
changeset
|
191 |
except Exception as exc: |
9517
3338b2205ea3
Typo in comments and error messages
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents:
9322
diff
changeset
|
192 |
content = 'An error occurred while interpreting directive bookmark: %r' % exc |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
193 |
set_classes(options) |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
194 |
return [nodes.raw('', content, format='html')], [] |
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
195 |
|
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
196 |
|
0 | 197 |
def winclude_directive(name, arguments, options, content, lineno, |
198 |
content_offset, block_text, state, state_machine): |
|
199 |
"""Include a reST file as part of the content of this reST file. |
|
200 |
||
201 |
same as standard include directive but using config.locate_doc_resource to |
|
202 |
get actual file to include. |
|
203 |
||
204 |
Most part of this implementation is copied from `include` directive defined |
|
205 |
in `docutils.parsers.rst.directives.misc` |
|
206 |
""" |
|
207 |
context = state.document.settings.context |
|
4769
5b878b02b67b
[rest] cleanup, avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
208 |
cw = context._cw |
0 | 209 |
source = state_machine.input_lines.source( |
210 |
lineno - state_machine.input_offset - 1) |
|
211 |
#source_dir = os.path.dirname(os.path.abspath(source)) |
|
212 |
fid = arguments[0] |
|
4769
5b878b02b67b
[rest] cleanup, avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
213 |
for lang in chain((cw.lang, cw.vreg.property_value('ui.language')), |
5b878b02b67b
[rest] cleanup, avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
214 |
cw.vreg.config.available_languages()): |
0 | 215 |
rid = '%s_%s.rst' % (fid, lang) |
4769
5b878b02b67b
[rest] cleanup, avoid deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
216 |
resourcedir = cw.vreg.config.locate_doc_file(rid) |
0 | 217 |
if resourcedir: |
218 |
break |
|
219 |
else: |
|
220 |
severe = state_machine.reporter.severe( |
|
221 |
'Problems with "%s" directive path:\nno resource matching %s.' |
|
222 |
% (name, fid), |
|
223 |
nodes.literal_block(block_text, block_text), line=lineno) |
|
224 |
return [severe] |
|
225 |
path = join(resourcedir, rid) |
|
226 |
encoding = options.get('encoding', state.document.settings.input_encoding) |
|
227 |
try: |
|
228 |
state.document.settings.record_dependencies.add(path) |
|
229 |
include_file = io.FileInput( |
|
230 |
source_path=path, encoding=encoding, |
|
231 |
error_handler=state.document.settings.input_encoding_error_handler, |
|
232 |
handle_io_errors=None) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
233 |
except IOError as error: |
0 | 234 |
severe = state_machine.reporter.severe( |
235 |
'Problems with "%s" directive path:\n%s: %s.' |
|
236 |
% (name, error.__class__.__name__, error), |
|
237 |
nodes.literal_block(block_text, block_text), line=lineno) |
|
238 |
return [severe] |
|
239 |
try: |
|
240 |
include_text = include_file.read() |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7879
diff
changeset
|
241 |
except UnicodeError as error: |
0 | 242 |
severe = state_machine.reporter.severe( |
243 |
'Problem with "%s" directive:\n%s: %s' |
|
244 |
% (name, error.__class__.__name__, error), |
|
245 |
nodes.literal_block(block_text, block_text), line=lineno) |
|
246 |
return [severe] |
|
8697
574bb05e40a4
[toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
247 |
if 'literal' in options: |
0 | 248 |
literal_block = nodes.literal_block(include_text, include_text, |
249 |
source=path) |
|
250 |
literal_block.line = 1 |
|
251 |
return literal_block |
|
252 |
else: |
|
253 |
include_lines = statemachine.string2lines(include_text, |
|
254 |
convert_whitespace=1) |
|
255 |
state_machine.insert_input(include_lines, path) |
|
256 |
return [] |
|
257 |
||
258 |
winclude_directive.arguments = (1, 0, 1) |
|
259 |
winclude_directive.options = {'literal': directives.flag, |
|
260 |
'encoding': directives.encoding} |
|
261 |
||
10953
8b8193046600
[rest] a bit of pep8
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10952
diff
changeset
|
262 |
|
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
263 |
class RQLTableDirective(Directive): |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
264 |
"""rql-table directive |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
265 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
266 |
Example: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
267 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
268 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
269 |
:vid: mytable |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
270 |
:headers: , , progress |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
271 |
:colvids: 2=progress |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
272 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
273 |
Any X,U,X WHERE X is Project, X url U |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
274 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
275 |
All fields but the RQL string are optionnal. The ``:headers:`` option can |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
276 |
contain empty column names. |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
277 |
""" |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
278 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
279 |
required_arguments = 0 |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
280 |
optional_arguments = 0 |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
281 |
has_content= True |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
282 |
final_argument_whitespace = True |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
283 |
option_spec = {'vid': directives.unchanged, |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
284 |
'headers': directives.unchanged, |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
285 |
'colvids': directives.unchanged} |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
286 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
287 |
def run(self): |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
288 |
errid = "rql-table directive" |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
289 |
self.assert_has_content() |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
290 |
if self.arguments: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
291 |
raise self.warning('%s does not accept arguments' % errid) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
292 |
rql = ' '.join([l.strip() for l in self.content]) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
293 |
_cw = self.state.document.settings.context._cw |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
294 |
_cw.ensure_ro_rql(rql) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
295 |
try: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
296 |
rset = _cw.execute(rql) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
297 |
except Exception as exc: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
298 |
raise self.error("fail to execute RQL query in %s: %r" % |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
299 |
(errid, exc)) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
300 |
if not rset: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
301 |
raise self.warning("empty result set") |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
302 |
vid = self.options.get('vid', 'table') |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
303 |
try: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
304 |
view = _cw.vreg['views'].select(vid, _cw, rset=rset) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
305 |
except Exception as exc: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
306 |
raise self.error("fail to select '%s' view in %s: %r" % |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
307 |
(vid, errid, exc)) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
308 |
headers = None |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
309 |
if 'headers' in self.options: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
310 |
headers = [h.strip() for h in self.options['headers'].split(',')] |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
311 |
while headers.count(''): |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
312 |
headers[headers.index('')] = None |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
313 |
if len(headers) != len(rset[0]): |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
314 |
raise self.error("the number of 'headers' does not match the " |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
315 |
"number of columns in %s" % errid) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
316 |
cellvids = None |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
317 |
if 'colvids' in self.options: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
318 |
cellvids = {} |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
319 |
for f in self.options['colvids'].split(','): |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
320 |
try: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
321 |
idx, vid = f.strip().split('=') |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
322 |
except ValueError: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
323 |
raise self.error("malformatted 'colvids' option in %s" % |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
324 |
errid) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
325 |
cellvids[int(idx.strip())] = vid.strip() |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
326 |
try: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
327 |
content = view.render(headers=headers, cellvids=cellvids) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
328 |
except Exception as exc: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
329 |
raise self.error("Error rendering %s (%s)" % (errid, exc)) |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
330 |
return [nodes.raw('', content, format='html')] |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
331 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
332 |
|
996 | 333 |
try: |
334 |
from pygments import highlight |
|
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4483
diff
changeset
|
335 |
from pygments.lexers import get_lexer_by_name |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
336 |
from pygments.formatters.html import HtmlFormatter |
996 | 337 |
except ImportError: |
4118
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
338 |
pygments_directive = None |
996 | 339 |
else: |
340 |
_PYGMENTS_FORMATTER = HtmlFormatter() |
|
341 |
||
342 |
def pygments_directive(name, arguments, options, content, lineno, |
|
343 |
content_offset, block_text, state, state_machine): |
|
344 |
try: |
|
345 |
lexer = get_lexer_by_name(arguments[0]) |
|
346 |
except ValueError: |
|
347 |
# no lexer found |
|
348 |
lexer = get_lexer_by_name('text') |
|
349 |
parsed = highlight(u'\n'.join(content), lexer, _PYGMENTS_FORMATTER) |
|
4483
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
350 |
# don't fail if no context set on the sourcecode directive |
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
351 |
try: |
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
352 |
context = state.document.settings.context |
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
353 |
context._cw.add_css('pygments.css') |
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
354 |
except AttributeError: |
7577
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
355 |
# used outside cubicweb XXX use hasattr instead |
4483
918fd9931cb7
cleanup, don't fail if no context set on the sourcecode directive
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4334
diff
changeset
|
356 |
pass |
996 | 357 |
return [nodes.raw('', parsed, format='html')] |
1447
a1ca676294f0
don't use a singleton rest parser which may leads to concurrency bugs
sylvain.thenault@logilab.fr
parents:
1323
diff
changeset
|
358 |
|
996 | 359 |
pygments_directive.arguments = (1, 0, 1) |
360 |
pygments_directive.content = 1 |
|
361 |
||
362 |
||
0 | 363 |
class CubicWebReSTParser(Parser): |
364 |
"""The (customized) reStructuredText parser.""" |
|
365 |
||
366 |
def __init__(self): |
|
367 |
self.initial_state = 'Body' |
|
368 |
self.state_classes = states.state_classes |
|
369 |
self.inliner = states.Inliner() |
|
370 |
self.statemachine = states.RSTStateMachine( |
|
371 |
state_classes=self.state_classes, |
|
372 |
initial_state=self.initial_state, |
|
373 |
debug=0) |
|
374 |
||
375 |
def parse(self, inputstring, document): |
|
376 |
"""Parse `inputstring` and populate `document`, a document tree.""" |
|
377 |
self.setup_parse(inputstring, document) |
|
378 |
inputlines = statemachine.string2lines(inputstring, |
|
379 |
convert_whitespace=1) |
|
380 |
self.statemachine.run(inputlines, document, inliner=self.inliner) |
|
381 |
self.finish_parse() |
|
382 |
||
383 |
||
4771
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
384 |
# XXX docutils keep a ref on context, can't find a correct way to remove it |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
385 |
class CWReSTPublisher(Publisher): |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
386 |
def __init__(self, context, settings, **kwargs): |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
387 |
Publisher.__init__(self, **kwargs) |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
388 |
self.set_components('standalone', 'restructuredtext', 'pseudoxml') |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
389 |
self.process_programmatic_settings(None, settings, None) |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
390 |
self.settings.context = context |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
391 |
|
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
392 |
|
0 | 393 |
def rest_publish(context, data): |
394 |
"""publish a string formatted as ReStructured Text to HTML |
|
1447
a1ca676294f0
don't use a singleton rest parser which may leads to concurrency bugs
sylvain.thenault@logilab.fr
parents:
1323
diff
changeset
|
395 |
|
0 | 396 |
:type context: a cubicweb application object |
397 |
||
398 |
:type data: str |
|
399 |
:param data: some ReST text |
|
400 |
||
401 |
:rtype: unicode |
|
402 |
:return: |
|
6109
47d9c0e0f7b7
integrate Celso's work on translation file: proper/complete spanish translation, fixed some typos in french translation, occured -> occurred fix in various places
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
403 |
the data formatted as HTML or the original data if an error occurred |
0 | 404 |
""" |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2680
diff
changeset
|
405 |
req = context._cw |
10708
d5e3fffa9c07
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
406 |
if isinstance(data, text_type): |
0 | 407 |
encoding = 'unicode' |
2311
f178182b1305
actually close #344401 by removing unprintable characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
408 |
# remove unprintable characters unauthorized in xml |
f178182b1305
actually close #344401 by removing unprintable characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
409 |
data = data.translate(ESC_UCAR_TABLE) |
0 | 410 |
else: |
411 |
encoding = req.encoding |
|
2311
f178182b1305
actually close #344401 by removing unprintable characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
412 |
# remove unprintable characters unauthorized in xml |
f178182b1305
actually close #344401 by removing unprintable characters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
413 |
data = data.translate(ESC_CAR_TABLE) |
0 | 414 |
settings = {'input_encoding': encoding, 'output_encoding': 'unicode', |
10212
dccce2be3101
[ext] Remove use of cStringIO
Rémi Cardona <remi.cardona@free.fr>
parents:
10023
diff
changeset
|
415 |
'warning_stream': False, |
6275
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
416 |
'traceback': True, # don't sys.exit |
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
417 |
'stylesheet': None, # don't try to embed stylesheet (may cause |
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
418 |
# obscure bug due to docutils computing |
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
419 |
# relative path according to the directory |
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
420 |
# used *at import time* |
0 | 421 |
# dunno what's the max, severe is 4, and we never want a crash |
6275
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
422 |
# (though try/except may be a better option...). May be the |
20f30e01ae59
[ReST] settings update: add traceback=True to avoid sys.exit, and set stylesheet to None since we don't care about it and that may makes docutils stupidly fail according to the cwd at import time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6109
diff
changeset
|
423 |
# above traceback option will avoid this? |
1447
a1ca676294f0
don't use a singleton rest parser which may leads to concurrency bugs
sylvain.thenault@logilab.fr
parents:
1323
diff
changeset
|
424 |
'halt_level': 10, |
10952
4f28cb25b6c1
[rest] avoid field on two lines if name is above some size limit. Closes #8961835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10023
diff
changeset
|
425 |
# disable stupid switch to colspan=2 if field name is above a size limit |
4f28cb25b6c1
[rest] avoid field on two lines if name is above some size limit. Closes #8961835
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10023
diff
changeset
|
426 |
'field_name_limit': sys.maxsize, |
0 | 427 |
} |
428 |
if context: |
|
429 |
if hasattr(req, 'url'): |
|
430 |
base_url = req.url() |
|
431 |
elif hasattr(context, 'absolute_url'): |
|
432 |
base_url = context.absolute_url() |
|
433 |
else: |
|
434 |
base_url = req.base_url() |
|
435 |
else: |
|
436 |
base_url = None |
|
437 |
try: |
|
4771
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
438 |
pub = CWReSTPublisher(context, settings, |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
439 |
parser=CubicWebReSTParser(), |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
440 |
writer=Writer(base_url=base_url), |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
441 |
source_class=io.StringInput, |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
442 |
destination_class=io.StringOutput) |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
443 |
pub.set_source(data) |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
444 |
pub.set_destination() |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
445 |
res = pub.publish(enable_exit_status=None) |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
446 |
# necessary for proper garbage collection, else a ref is kept somewhere in docutils... |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
447 |
del pub.settings.context |
e27d23f875c6
custom rest publisher instead of using rest_publish. Avoid to keep a ref on the latest context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4769
diff
changeset
|
448 |
return res |
9592
6fd2651719bc
[ext/rest] Catch SystemExit raised by docutils
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9517
diff
changeset
|
449 |
except BaseException: |
0 | 450 |
LOGGER.exception('error while publishing ReST text') |
10708
d5e3fffa9c07
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
451 |
if not isinstance(data, text_type): |
d5e3fffa9c07
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
452 |
data = text_type(data, encoding, 'replace') |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2311
diff
changeset
|
453 |
return xml_escape(req._('error while publishing ReST text') |
0 | 454 |
+ '\n\n' + data) |
4118
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
455 |
|
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
456 |
|
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
457 |
_INITIALIZED = False |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
458 |
def cw_rest_init(): |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
459 |
global _INITIALIZED |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
460 |
if _INITIALIZED: |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
461 |
return |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
462 |
_INITIALIZED = True |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
463 |
register_canonical_role('eid', eid_reference_role) |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6275
diff
changeset
|
464 |
register_canonical_role('rql', rql_role) |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8711
diff
changeset
|
465 |
register_canonical_role('bookmark', bookmark_role) |
4118
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
466 |
directives.register_directive('winclude', winclude_directive) |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
467 |
if pygments_directive is not None: |
8a9a00a9405c
quick and dirty fix trying to avoid rest directive conflicts when using sphinx (which seems to import the code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2680
diff
changeset
|
468 |
directives.register_directive('sourcecode', pygments_directive) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
469 |
directives.register_directive('rql-table', RQLTableDirective) |