Skip to content

Commit

Permalink
preliminary asciidoc support
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Apr 1, 2024
1 parent 21c84a3 commit 7de26bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
asciidoc3
joppy
pyinstaller
pypandoc_binary
19 changes: 15 additions & 4 deletions src/joplin_custom_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pathlib import Path
import pkgutil
import shutil
import tempfile

from asciidoc3 import asciidoc3api
from joppy.api import Api
import pypandoc

Expand All @@ -31,10 +33,19 @@ def convert_folder(folder: Path, root):

def convert_file(file_: Path, root):
"""Default conversion function for files. Uses pandoc directly."""
# markdown output formats: https://pandoc.org/chunkedhtml-demo/8.22-markdown-variants.html
# Joplin follows CommonMark: https://joplinapp.org/help/apps/markdown
note_body = pypandoc.convert_file(file_, "commonmark_x")
root.child_notes.append(Note({"title": file_.stem, "body": note_body}))
if file_.suffix == ".adoc":
# Convert asciidoc separately, since reading is not supported by pandc (yet).
with tempfile.NamedTemporaryFile(suffix=".docbook") as docbook_file:
# https://gitlab.com/asciidoc3/asciidoc3/-/issues/5#note_752781763
asciidoc3_api = asciidoc3api.AsciiDoc3API(Path(asciidoc3api.__file__))
asciidoc3_api.execute(str(file_), docbook_file.name, backend="docbook")
note_body = pypandoc.convert_file(docbook_file.name, "commonmark_x")
root.child_notes.append(Note({"title": file_.stem, "body": note_body}))
else:
# markdown output formats: https://pandoc.org/chunkedhtml-demo/8.22-markdown-variants.html
# Joplin follows CommonMark: https://joplinapp.org/help/apps/markdown
note_body = pypandoc.convert_file(file_, "commonmark_x")
root.child_notes.append(Note({"title": file_.stem, "body": note_body}))
return root, []


Expand Down
2 changes: 1 addition & 1 deletion test_inputs/nested_folder/asciidoc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Use it to try https://asciidoc.org[AsciiDoc].
* A list item
* Another list item

[,ruby]
[source,ruby]
----
puts 'Hello, World!'
----

0 comments on commit 7de26bf

Please sign in to comment.