@@ -144,7 +144,14 @@ class CommandImportWordpress(Command, ImportMixin):
144
144
'default' : False ,
145
145
'type' : bool ,
146
146
'help' : "Uses WordPress page compiler to transform WordPress posts directly to HTML during import" ,
147
- }
147
+ },
148
+ {
149
+ 'name' : 'use_wordpress_compiler' ,
150
+ 'long' : 'use-wordpress-compiler' ,
151
+ 'default' : False ,
152
+ 'type' : bool ,
153
+ 'help' : "Instead of converting posts to markdown, leave them as is and use the WordPress page compiler" ,
154
+ },
148
155
]
149
156
all_tags = set ([])
150
157
@@ -177,6 +184,7 @@ def _read_options(self, options, args):
177
184
self .export_comments = options .get ('export_comments' , False )
178
185
179
186
self .transform_to_html = options .get ('transform_to_html' , False )
187
+ self .use_wordpress_compiler = options .get ('use_wordpress_compiler' , False )
180
188
181
189
self .auth = None
182
190
if options .get ('download_auth' ) is not None :
@@ -189,6 +197,14 @@ def _read_options(self, options, args):
189
197
self .separate_qtranslate_content = options .get ('separate_qtranslate_content' )
190
198
self .translations_pattern = options .get ('translations_pattern' )
191
199
200
+ if self .transform_to_html and self .use_wordpress_compiler :
201
+ LOGGER .warn ("It does not make sense to combine --transform-to-html with --use-wordpress-compiler, as the first converts all posts to HTML and the latter option affects zero posts." )
202
+
203
+ if self .use_wordpress_compiler :
204
+ LOGGER .warn ("Make sure to install the WordPress page compiler via" )
205
+ LOGGER .warn (" nikola plugin -i wordpress_compiler" )
206
+ LOGGER .warn ("in your imported blog's folder ({0}), if you haven't installed it system-wide or user-wide. Otherwise, your newly imported blog won't compile." .format (options ['output_folder' ]))
207
+
192
208
if self .transform_to_html :
193
209
self .wordpress_page_compiler = None
194
210
for plugin_info in self .site .plugin_manager .getPluginsOfCategory ('PageCompiler' ):
@@ -349,12 +365,14 @@ def populate_context(self, channel):
349
365
PAGES += ')\n '
350
366
context ['POSTS' ] = POSTS
351
367
context ['PAGES' ] = PAGES
352
- context ['COMPILERS' ] = '''{
353
- "rest": ('.txt', '.rst'),
354
- "markdown": ('.md', '.mdown', '.markdown'),
355
- "html": ('.html', '.htm')
356
- }
357
- '''
368
+ COMPILERS = '{\n '
369
+ COMPILERS += ''' "rest": ('.txt', '.rst'),''' + '\n '
370
+ COMPILERS += ''' "markdown": ('.md', '.mdown', '.markdown')''' + '\n '
371
+ COMPILERS += ''' "html": ('.html', '.htm'),''' + '\n '
372
+ if self .use_wordpress_compiler :
373
+ COMPILERS += ''' "wordpress": ('.wp'),''' + '\n '
374
+ COMPILERS += '}'
375
+ context ['COMPILERS' ] = COMPILERS
358
376
359
377
return context
360
378
@@ -490,16 +508,18 @@ def transform_content(self, content, post_format):
490
508
if post_format == 'wp' :
491
509
if self .transform_to_html :
492
510
content = self .wordpress_page_compiler .compile_to_string (content )
493
- return content , 'html'
511
+ return content , 'html' , True
512
+ elif self .use_wordpress_compiler :
513
+ return content , 'wp' , False
494
514
else :
495
515
content = self .transform_code (content )
496
516
content = self .transform_caption (content )
497
517
content = self .transform_multiple_newlines (content )
498
- return content , 'md'
518
+ return content , 'md' , True
499
519
elif post_format == 'markdown' :
500
- return content , 'md'
520
+ return content , 'md' , True
501
521
elif post_format == 'none' :
502
- return content , 'html'
522
+ return content , 'html' , True
503
523
else :
504
524
return None
505
525
@@ -698,7 +718,7 @@ def import_item(self, item, wordpress_namespace, out_folder=None):
698
718
default_language = self .context ["DEFAULT_LANG" ]
699
719
for lang , content in content_translations .items ():
700
720
try :
701
- content , extension = self .transform_content (content , post_format )
721
+ content , extension , rewrite_html = self .transform_content (content , post_format )
702
722
except :
703
723
LOGGER .error (('Cannot interpret post "{0}" (language {1}) with post ' +
704
724
'format {2}!' ).format (os .path .join (out_folder , slug ), lang , post_format ))
@@ -725,7 +745,8 @@ def import_item(self, item, wordpress_namespace, out_folder=None):
725
745
self .write_content (
726
746
os .path .join (self .output_folder ,
727
747
out_folder , out_content_filename ),
728
- content )
748
+ content ,
749
+ rewrite_html )
729
750
730
751
if self .export_comments :
731
752
comments = []
0 commit comments