Mobileread
[Conversion Output] Markdown Output. Test and seek for help.
#1  The_book 04-17-2020, 04:38 AM
I create a Markdown Output plugin. This is nothing new, just the function of TXT Output plugin with txt_output_formatting=markdown, and keep_links=True, keep_image_references=True in default. keep_color have been removed for it is a function in textile. I create this, so that I don't need to set them and rename .txt to .md everytime.

I think this can work, but I still have some questions.
  1. How to set opts in function convert? I use setattr, am I right?
  2. How to create output gui that can be uesd in Calibre?
[zip] Markdown Output.zip (1.1 KB, 43 views)
Reply 

#2  The_book 04-17-2020, 05:07 AM
And, by the way. I think let build-in plugins the same as outer plugin is a better idea. Now they cannot be removed and hard to change.
Reply 

#3  kovidgoyal 04-17-2020, 06:00 AM
1. yes
2. You implement gui_configuration_widget() in your plugin
Reply 

#4  The_book 04-17-2020, 09:44 AM
Quote kovidgoyal
1. yes
2. You implement gui_configuration_widget() in your plugin
Thanks.
I update this plugin. Now it has gui in convert.
And now it has more questions.

1. It can convert to Markdown when I use ebook-convert.exe try.epub .md but when I use gui, it prints

calibre, version 4.12.0 (win32, embedded-python: True)
Conversion error: Failed: Convert book 1 of 1 (***)

Convert book 1 of 1 (***)
Failed to initialize plugin: u'C:\\Users\\LJT\\AppData\\Roaming\\calibre\\plugi ns\\Markdown Output.zip'
Python function terminated unexpectedly
No plugin to handle output format: md (Error Code: 1)
Traceback (most recent call last):
File "site.py", line 114, in main
File "site.py", line 88, in run_entry_point
File "site-packages\calibre\utils\ipc\worker.py", line 209, in main
File "site-packages\calibre\gui2\convert\gui_conversion.py", line 43, in gui_convert_override
File "site-packages\calibre\gui2\convert\gui_conversion.py", line 25, in gui_convert
File "site-packages\calibre\ebooks\conversion\plumber.py", line 758, in __init__
ValueError: No plugin to handle output format: md

2. I can see gui in convert widget like image_8.png. How to remove formatting and keep text color?

3. Preference->Output options do not have markdown output. What can I do?
image_8.png 
[zip] Markdown Output.zip (4.9 KB, 39 views)
Reply 

#5  kovidgoyal 04-17-2020, 10:11 AM
Thats because your plugin is failing initialization

Failed to initialize plugin: u'C:\\Users\\LJT\\AppData\\Roaming\\calibre\\plugi ns\\Markdown Output.zip'
Reply 

#6  The_book 04-17-2020, 10:15 AM
Quote kovidgoyal
Thats because your plugin is failing initialization

Failed to initialize plugin: u'C:\\Users\\LJT\\AppData\\Roaming\\calibre\\plugi ns\\Markdown Output.zip'
But ebook-convert cli works well. I can not understand why.
Reply 

#7  kovidgoyal 04-17-2020, 10:18 AM
Run calibre in debug mode (right click preferences button) and you will get more information
Reply 

#8  The_book 04-17-2020, 10:42 AM
Quote kovidgoyal
Run calibre in debug mode (right click preferences button) and you will get more information
After checking, it happens in src\calibre\customize\ui.py line 713
Code
 for zfp in list(external_plugins) + builtin_plugins: try: if not isinstance(zfp, type): # We have a plugin name pname = zfp zfp = os.path.join(plugin_dir, zfp+'.zip') if not os.path.exists(zfp): zfp = external_plugins[pname] try: plugin = load_plugin(zfp) if not isinstance(zfp, type) else zfp except PluginNotFound: continue if perf: st = time.time() plugin = initialize_plugin(plugin, None if isinstance(zfp, type) else zfp) if perf: times[plugin.name] = time.time() - st _initialized_plugins.append(plugin) except: print('Failed to initialize plugin:', repr(zfp)) traceback.print_exc() if DEBUG: traceback.print_exc()
with
Quote
Traceback (most recent call last):
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\ui.py", line 703, in initialize_plugins
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\ui.py", line 61, in load_plugin
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\zipplugin.py", line 203, in load
File "importlib\__init__.py", line 37, in import_module
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\zipplugin.py", line 185, in load_module
File "calibre_plugins.markdown_output.__init__", line 3, in <module>
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\zipplugin.py", line 185, in load_module
File "calibre_plugins.markdown_output.markdown_outp ut", line 3, in <module>
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\customize\zipplugin.py", line 185, in load_module
File "calibre_plugins.markdown_output.ui", line 1, in <module>
File "D:\workplace\program\open-sourse\calibre-src\src\calibre\gui2\convert\txt_output.py", line 10, in <module>
ImportError: cannot import name Widget
Reply 

#9  kovidgoyal 04-17-2020, 10:52 AM
Move your import
at calibre_plugins.markdown_output.ui", line 1, in <module>

to inside the function where it is actually used.
Reply 

#10  The_book 04-17-2020, 11:03 AM
Quote kovidgoyal
Move your import
at calibre_plugins.markdown_output.ui", line 1, in <module>

to inside the function where it is actually used.
Thanks. Now it works well. I update it.
[zip] Markdown Output.zip (4.9 KB, 40 views)
Reply 

  Next »  Last »  (1/2)
Today's Posts | Search this Thread | Login | Register