Skip to content

Commit

Permalink
Add $NB_BROWSE_MARKDOWN_READER variable.
Browse files Browse the repository at this point in the history
refs gh-275
refs gh-284
  • Loading branch information
xwmx committed Feb 10, 2024
1 parent 96376bb commit 32b6843
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9043,6 +9043,7 @@ Shortcut Alias:
<a href="#nb_audio_tool"><code>$NB_AUDIO_TOOL</code></a>&nbsp;·
<a href="#nb_auto_sync"><code>$NB_AUTO_SYNC</code></a>&nbsp;·
<a href="#nb_browser"><code>$NB_BROWSER</code></a>&nbsp;·
<a href="#nb_browse_markdown_reader"><code>$NB_BROWSE_MARKDOWN_READER</code></a>&nbsp;·
<a href="#nb_browse_server_tool"><code>$NB_BROWSE_SERVER_TOOL</code></a>&nbsp;·
<a href="#nb_color_primary"><code>$NB_COLOR_PRIMARY</code></a>&nbsp;·
<a href="#nb_color_secondary"><code>$NB_COLOR_SECONDARY</code></a>&nbsp;·
Expand Down Expand Up @@ -9225,6 +9226,27 @@ When set to '1', each `_git checkpoint()` call will automativally run
</sup>
</p>

##### `$NB_BROWSE_MARKDOWN_READER`

```text
$NB_BROWSE_MARKDOWN_READER

Default: 'markdown+emoji+raw_html+east_asian_line_breaks'

The Pandoc reader, including extensions, to use for converting Markdown to
HTML in `nb browse`.

More information:
https://pandoc.org/MANUAL.html#extensions
https://pandoc.org/MANUAL.html#general-options-1
```

<p>
<sup>
<a href="#-variables">↑</a>
</sup>
</p>

##### `$NB_BROWSE_SERVER_TOOL`

```text
Expand Down
22 changes: 22 additions & 0 deletions docs/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9049,6 +9049,7 @@ Shortcut Alias:
<a href="#nb_audio_tool"><code>$NB_AUDIO_TOOL</code></a>&nbsp;·
<a href="#nb_auto_sync"><code>$NB_AUTO_SYNC</code></a>&nbsp;·
<a href="#nb_browser"><code>$NB_BROWSER</code></a>&nbsp;·
<a href="#nb_browse_markdown_reader"><code>$NB_BROWSE_MARKDOWN_READER</code></a>&nbsp;·
<a href="#nb_browse_server_tool"><code>$NB_BROWSE_SERVER_TOOL</code></a>&nbsp;·
<a href="#nb_color_primary"><code>$NB_COLOR_PRIMARY</code></a>&nbsp;·
<a href="#nb_color_secondary"><code>$NB_COLOR_SECONDARY</code></a>&nbsp;·
Expand Down Expand Up @@ -9231,6 +9232,27 @@ When set to '1', each `_git checkpoint()` call will automativally run
</sup>
</p>

##### `$NB_BROWSE_MARKDOWN_READER`

```text
$NB_BROWSE_MARKDOWN_READER

Default: 'markdown+emoji+raw_html+east_asian_line_breaks'

The Pandoc reader, including extensions, to use for converting Markdown to
HTML in `nb browse`.

More information:
https://pandoc.org/MANUAL.html#extensions
https://pandoc.org/MANUAL.html#general-options-1
```

<p>
<sup>
<a href="#-variables">↑</a>
</sup>
</p>

##### `$NB_BROWSE_SERVER_TOOL`

```text
Expand Down
17 changes: 15 additions & 2 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -9865,6 +9865,18 @@ _main "${_ARGUMENTS[@]:-}"
###############################################################################
# --------------------------------------------------------------------------- #

# $NB_BROWSE_MARKDOWN_READER
#
# Default: 'markdown+emoji+raw_html+east_asian_line_breaks'
#
# The Pandoc reader, including extensions, to use for converting Markdown to
# HTML in `nb browse`.
#
# More information:
# https://pandoc.org/MANUAL.html#extensions
# https://pandoc.org/MANUAL.html#general-options-1
export NB_BROWSE_MARKDOWN_READER="${NB_BROWSE_MARKDOWN_READER:-"markdown+emoji+raw_html+east_asian_line_breaks"}"

# $NB_BROWSE_SERVER_TOOL
#
# Default: '' (automatically assigned)
Expand Down Expand Up @@ -11587,9 +11599,10 @@ HEREDOC
if [[ -n "${_from:-}" ]]
then
_pandoc_arguments+=("--from=${_from:-}")
elif [[ -z "${_prepared_file_path:-}" ]]
elif [[ -z "${_prepared_file_path:-}" ]] ||
_contains "${_prepared_file_path##*.}" "md" "markdown"
then
_pandoc_arguments+=("--from=markdown+raw_html+east_asian_line_breaks")
_pandoc_arguments+=("--from=${NB_BROWSE_MARKDOWN_READER:-}")
fi

if ((${NB_MATHJAX_ENABLED:-0}))
Expand Down
66 changes: 66 additions & 0 deletions test/browse-items.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,72 @@

load test_helper

@test "'browse <selector>' processes markdown with \$NB_BROWSE_MARKDOWN_READER value." {
{
"${_NB}" init

"${_NB}" add "File One.md" \
--title "Root Title One" \
--content "$(<<HEREDOC cat
Example line one
Example line two
Example line four
:smile:
HEREDOC
)"

sleep 1
}

run "${_NB}" browse 1 --print

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

[[ "${status}" -eq 0 ]]

diff \
<(printf "%s\\n" "${output}" | sed -ne '/<div class="main">/,$ p') \
<(cat <<HEREDOC
<div class="main">
<h1 id="root-title-one">Root Title One</h1>
<p>Example line one
Example line two</p>
<p>Example line four
<span class="emoji" data-emoji="smile">😄</span></p>
</div>
</body>
</html>
HEREDOC
)

NB_BROWSE_MARKDOWN_READER="markdown+hard_line_breaks-emoji" run "${_NB}" browse 1 --print

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

[[ "${status}" -eq 0 ]]

diff \
<(printf "%s\\n" "${output}" | sed -ne '/<div class="main">/,$ p') \
<(cat <<HEREDOC
<div class="main">
<h1 id="root-title-one">Root Title One</h1>
<p>Example line one<br />
Example line two</p>
<p>Example line four<br />
:smile:</p>
</div>
</body>
</html>
HEREDOC
)

}

# response handling ###########################################################

@test "'browse' responds to request with no parameters and successfully serves item." {
Expand Down

0 comments on commit 32b6843

Please sign in to comment.