@@ -69,7 +69,7 @@ def convert(source, to, format=None, extra_args=(), encoding='utf-8',
6969
7070
7171def convert_text (source , to , format , extra_args = (), encoding = 'utf-8' ,
72- outputfile = None , filters = None ):
72+ outputfile = None , filters = None , verify_format = True ):
7373 """Converts given `source` from `format` to `to`.
7474
7575 :param str source: Unicode string or bytes (see encoding)
@@ -98,11 +98,12 @@ def convert_text(source, to, format, extra_args=(), encoding='utf-8',
9898 """
9999 source = _as_unicode (source , encoding )
100100 return _convert_input (source , format , 'string' , to , extra_args = extra_args ,
101- outputfile = outputfile , filters = filters )
101+ outputfile = outputfile , filters = filters ,
102+ verify_format = verify_format )
102103
103104
104105def convert_file (source_file , to , format = None , extra_args = (), encoding = 'utf-8' ,
105- outputfile = None , filters = None ):
106+ outputfile = None , filters = None , verify_format = True ):
106107 """Converts given `source` from `format` to `to`.
107108
108109 :param str source_file: file path (see encoding)
@@ -135,7 +136,8 @@ def convert_file(source_file, to, format=None, extra_args=(), encoding='utf-8',
135136 raise RuntimeError ("source_file is not a valid path" )
136137 format = _identify_format_from_path (source_file , format )
137138 return _convert_input (source_file , format , 'path' , to , extra_args = extra_args ,
138- outputfile = outputfile , filters = filters )
139+ outputfile = outputfile , filters = filters ,
140+ verify_format = verify_format )
139141
140142
141143def _identify_path (source ):
@@ -192,18 +194,20 @@ def _identify_input_type(source, format, encoding='utf-8'):
192194 return source , format , input_type
193195
194196
197+ def normalize_format (fmt ):
198+ formats = {
199+ 'dbk' : 'docbook' ,
200+ 'md' : 'markdown' ,
201+ 'tex' : 'latex' ,
202+ }
203+ fmt = formats .get (fmt , fmt )
204+ # rst format can have extensions
205+ if fmt [:4 ] == "rest" :
206+ fmt = "rst" + fmt [4 :]
207+ return fmt
208+
209+
195210def _validate_formats (format , to , outputfile ):
196- def normalize_format (fmt ):
197- formats = {
198- 'dbk' : 'docbook' ,
199- 'md' : 'markdown' ,
200- 'tex' : 'latex' ,
201- }
202- fmt = formats .get (fmt , fmt )
203- # rst format can have extensions
204- if fmt [:4 ] == "rest" :
205- fmt = "rst" + fmt [4 :]
206- return fmt
207211
208212 format = normalize_format (format )
209213 to = normalize_format (to )
@@ -252,10 +256,14 @@ def normalize_format(fmt):
252256
253257
254258def _convert_input (source , format , input_type , to , extra_args = (), outputfile = None ,
255- filters = None ):
259+ filters = None , verify_format = True ):
256260 _ensure_pandoc_path ()
257261
258- format , to = _validate_formats (format , to , outputfile )
262+ if verify_format :
263+ format , to = _validate_formats (format , to , outputfile )
264+ else :
265+ format = normalize_format (format )
266+ to = normalize_format (to )
259267
260268 string_input = input_type == 'string'
261269 input_file = [source ] if not string_input else []
0 commit comments