Skip to content

Commit

Permalink
add settings: :crop :nopdf
Browse files Browse the repository at this point in the history
  • Loading branch information
kimim committed Feb 11, 2024
1 parent 9368184 commit 97eed30
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 28 deletions.
24 changes: 15 additions & 9 deletions chatu-drawio.el
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@ KEYWORD-PLIST contains parameters from the chatu line."
(output-path (plist-get keyword-plist :output-path))
(output-path-pdf (file-name-with-extension output-path "pdf"))
(page (plist-get keyword-plist :page)))
(format "%s -x %s -p %s -o %s >/dev/null 2>&1 && \
(if (plist-get keyword-plist :nopdf)
(format "draw.io %s -x %s -p %s -o %s >/dev/null 2>&1"
(if (plist-get keyword-plist :crop) "--crop" "")
(shell-quote-argument input-path)
(or page "0")
(shell-quote-argument output-path))
(format "draw.io %s -x %s -p %s -o %s >/dev/null 2>&1 && \
%s %s %s >/dev/null 2>&1 && rm %s"
"draw.io"
(shell-quote-argument input-path)
(or page "0")
(shell-quote-argument output-path-pdf)
"pdf2svg"
(shell-quote-argument output-path-pdf)
(shell-quote-argument output-path)
(shell-quote-argument output-path-pdf))))
(if (plist-get keyword-plist :crop) "--crop" "")
(shell-quote-argument input-path)
(or page "0")
(shell-quote-argument output-path-pdf)
"pdf2svg"
(shell-quote-argument output-path-pdf)
(shell-quote-argument output-path)
(shell-quote-argument output-path-pdf)))))

(defun chatu-drawio-open (keyword-plist)
"Open .drawio file.
Expand Down
43 changes: 27 additions & 16 deletions chatu.el
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@

(defun chatu-get-keyword (line)
"Get chatu keyword from string LINE."
(when (string-match
"#\\+\\(\\w+\\): +" line)
(list :keyword
(substring-no-properties
(match-string 1 line)))))

(defun chatu-get-type (line)
"Get chatu type from string LINE."
(when (string-match
":\\(\\w+\\) +" line)
(list :type
(substring-no-properties
(match-string 1 line)))))
(when (and
(string-match
"#\\+\\(\\w+\\): +" line)
(string= "chatu"
(substring-no-properties
(match-string 1 line))))
(list :chatu t)))

(defun chatu-get-settings (line)
"Get all chatu settings from string LINE."
(save-match-data
(let ((pos 0)
settings)
(while (string-match "\\(:\\w+\\)\\( +:\\|$\\)" line pos)
(setq settings
(append settings
(list
(intern
(substring-no-properties
(match-string 1 line)))
t)))
(setq pos (match-end 1)))
settings)))

(defun chatu-get-input (line)
"Get chatu input file from string LINE."
Expand Down Expand Up @@ -147,6 +157,7 @@

(defvar chatu-keyword-value-functions
'(chatu-get-keyword
chatu-get-settings
chatu-get-type
chatu-get-input
chatu-get-output
Expand All @@ -156,7 +167,7 @@

(defun chatu-normalize-keyword-plist (keyword-plist)
"Normalize KEYWORD-PLIST."
(when (plist-get keyword-plist :keyword)
(when (plist-get keyword-plist :chatu)
(let* ((input-dir (or (plist-get keyword-plist :input-dir)
chatu-input-dir))
(input (plist-get keyword-plist :input))
Expand Down Expand Up @@ -275,7 +286,7 @@
(defun chatu-ctrl-c-ctrl-c ()
"Hook function for `org-ctrl-c-ctrl-c-hook'."
(let ((plist (chatu-keyword-plist)))
(if (string= "chatu" (plist-get plist :keyword))
(if (plist-get plist :chatu)
(progn
(chatu-add)
t)
Expand All @@ -286,7 +297,7 @@
ARGS is ignored, required by `markdown-follow-thing-at-point'."
(ignore args) ;; args are not used.
(let ((plist (chatu-keyword-plist)))
(if (string= "chatu" (plist-get plist :keyword))
(if (plist-get plist :chatu)
(progn
(chatu-open)
t)
Expand Down
25 changes: 22 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ Or git submodule and use-package
```

# Usage
Add `chatu` line with `chatu-new` command:

```org
#+chatu: :drawio "diagram.drawio" :page 0 :input-dir "./draws" :output-dir "./images" :output "diagram.svg" :crop :nopdf
```
```markdown
<!-- #+chatu: :drawio "diagram.drawio" :page 0 :input-dir "./draws" :output-dir "./images" :output "diagram.svg" :crop :nopdf -->
```

Options/Settings:
- `:drawio` specifies the backend, they can be `:planuml`, `:babashka`, `:curl` or others added in the future by you.
- file name after backend keyword is the input file name.
- `:page` species which page you want to import to buffer.
- `:input-dir` and `:output-dir` are the folders for input or output file.
- `:output` is the output file name.
- `:crop` if you want to crop the empty white in page.
- `:nopdf` if you do not want intermediate pdf file for drawio backend.

Move cursor to `chatu` line,
- `C-c C-c` will invoke `chatu-add` to add image in orgmode.
Expand Down Expand Up @@ -65,17 +82,19 @@ Both method use a `keyword-plist` parameter, which contains the
`chatu` settings from `chatu` line.

```org
#+chatu: :drawio "diagram.drawio" :page 0 :input-dir "./draws" :output-dir "./images" :output "diagram.svg"
#+chatu: :drawio "diagram.drawio" :page 0 :input-dir "./draws" :output-dir "./images" :output "diagram.svg" :crop :nopdf
```

For example, we can get following `keyword-plist` from above `chatu` line:

```emacs-lisp
(:keyword "chatu" :type "drawio"
(:chatu t :type "drawio"
:input "diagram.drawio" :output "diagram.svg" :page "0"
:input-dir "./draws" :output-dir "./images"
:input-path "./draws/diagram.drawio"
:output-path "./images/diagram.svg")
:output-path "./images/diagram.svg"
:crop t
:nopdf t)
```
# Usage

Expand Down

0 comments on commit 97eed30

Please sign in to comment.