Skip to content

Commit

Permalink
Set useMaxWidth to False via mermaid config file (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
bimbashrestha authored Jul 28, 2022
1 parent e7c0cdd commit a3b8f3d
Showing 1 changed file with 11 additions and 0 deletions.
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")
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

0 comments on commit a3b8f3d

Please sign in to comment.