Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions md_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
run_script = True

import scribus
from tempfile import NamedTemporaryFile

try:
import markdown
except:
scribus.messageBox('python-markdown not installed',
'You need to install python-markdown for this script to work', scribus.ICON_WARNING)
run_script = False

run_script &= bool(scribus.getSelectedObject(0)) # We must have at least one selected object

if run_script and scribus.getSelectedObject(1):
result = scribus.messageBox('', 'More than one item selected, load all?',
button1=scribus.BUTTON_CANCEL, button2=scribus.BUTTON_YES)

if result == scribus.BUTTON_CANCEL:
run_script = False

def main():
md_name = scribus.fileDialog("Select a file", 'Markdown (*.md)')
if not md_name:
return

f = NamedTemporaryFile(suffix='.html')
markdown.markdownFromFile(md_name, f)
f.flush()

html_name = f.name

i = 0
while True:
ob_name = scribus.getSelectedObject(i)

if not ob_name:
break

if scribus.getObjectType(ob_name) == 'TextFrame':
scribus.insertHtmlText(html_name, ob_name)

i += 1

if run_script:
main()