Skip to content

Commit

Permalink
Improve _pandoc() argument handling.
Browse files Browse the repository at this point in the history
- Call `_pandoc()` with file path as first argument in `_export()`.
- Pass initial argument through to `pandoc` when it's an option argument.

refs gh-293
  • Loading branch information
xwmx committed Dec 27, 2023
1 parent 51e1044 commit 1747215
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 9 additions & 6 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -2761,14 +2761,17 @@ _pandoc() {
--standard-input)
_read_from_standard_input=1
;;
-*)
_pandoc_arguments+=("${1:-}")
;;
*)
_path="${1:-}"
;;
esac

shift

[[ -n "${1:-}" ]] && _pandoc_arguments=("${@}")
[[ -n "${1:-}" ]] && _pandoc_arguments+=("${@}")

if _command_exists "iconv" && {
((_read_from_standard_input)) || _file_is_text "${_path:-}"
Expand Down Expand Up @@ -15137,15 +15140,15 @@ _export() {
if [[ -n "${_args[*]:-}" ]]
then
_pandoc \
"${_notebook_path}/${_relative_path}" \
-o "${_target_path}" \
--standalone \
"${_notebook_path}/${_relative_path}" \
"${_args[@]:-}"
else
_pandoc \
-o "${_target_path}" \
--standalone \
"${_notebook_path}/${_relative_path}"
_pandoc \
"${_notebook_path}/${_relative_path}" \
-o "${_target_path}" \
--standalone
fi
else
cp "${_notebook_path}/${_relative_path}" "${_target_path}"
Expand Down
24 changes: 23 additions & 1 deletion test/export.bats
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ load test_helper
[[ "${output}" =~ sample.md ]]
}

@test "'export' with valid <id> and <path> with different file type converts." {
@test "'export' with valid <id> and <path> to HTML file type converts." {
{
"${_NB}" init
"${_NB}" add "# Export Example"
Expand All @@ -176,6 +176,28 @@ load test_helper
[[ "${output}" =~ example.html ]]
}

@test "'export' with valid <id> and <path> to PDF file type converts." {
{
"${_NB}" init
"${_NB}" add --title "Export Example"
}

run "${_NB}" export 1 "${_TMP_DIR}/example.pdf"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ -e "${_TMP_DIR}/example.pdf" ]]
[[ "$(file "${_TMP_DIR}/example.pdf")" =~ PDF\ document ]]

# Prints output

[[ "${lines[0]}" =~ \
^Exported:\ .*\[.*1.*\].*\ .*export_example\.md.*\ \"Export\ Example\"$ ]]
[[ "${lines[1]}" =~ \
^To:\ \ \ \ \ \ \ \ .*${_TMP_DIR}/example.pdf.*$ ]]
}

# `notebook` ##################################################################

@test "'export notebook' with valid <name> and <path> exports." {
Expand Down

0 comments on commit 1747215

Please sign in to comment.