Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set useMaxWidth to False via mermaid config file #44

Merged
merged 1 commit into from
Jul 28, 2022
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
11 changes: 11 additions & 0 deletions n2y/plugins/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import tempfile
import json

from pandoc.types import Para, Image

Expand All @@ -11,6 +12,12 @@

logger = logging.getLogger(__name__)

mermaid_config = {
"flowchart": {
"useMaxWidth": False
}
}


class MermaidFencedCodeBlock(FencedCodeBlock):
"""
Expand All @@ -32,10 +39,14 @@ def __init__(self, client, page, notion_data, get_children=True):
def to_pandoc(self):
temp_fd, temp_filepath = tempfile.mkstemp(suffix=".png")
os.close(temp_fd)
temp_config_fd, temp_config_filepath = tempfile.mkstemp(suffix=".json")
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
os.write(temp_config_fd, json.dumps(mermaid_config).encode("utf-8"))
os.close(temp_config_fd)
try:
diagram_as_bytes = self.rich_text.to_plain_text().encode()
subprocess.run([
'mmdc',
'--configFile', temp_config_filepath,
'-o', temp_filepath,
], capture_output=True, input=diagram_as_bytes, check=True)
with open(temp_filepath, 'rb') as temp_file:
Expand Down