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

Improve inline src blocks #578

Merged
merged 4 commits into from May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions ox-hugo.el
Expand Up @@ -2444,8 +2444,16 @@ holding export options."

;;;; Inline Src Block
(defun org-hugo-inline-src-block (inline-src-block _contents _info)
"Transcode INLINE-SRC-BLOCK object into Hugo-compatible Markdown format."
(org-md-verbatim inline-src-block nil nil))
"Transcode INLINE-SRC-BLOCK object into HTML.

Escape Hugo shortcodes if present in this element's value."
(let* ((lang (org-element-property :language inline-src-block))
(code (org-hugo--escape-hugo-shortcode
(org-element-property :value inline-src-block)
lang)))
(org-element-put-property inline-src-block :value code)
(format "<code class=\"inline-src language-%s\" data-lang=\"%s\">%s</code>"
lang lang code)))

;;;; Keyword
(defun org-hugo-keyword (keyword contents info)
Expand Down
42 changes: 42 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -2160,6 +2160,48 @@ src_emacs-lisp[:exports both]{(message "Hello 3")} {{{results(=Hello 3=)}}}
src_emacs-lisp[:exports none]{(message "Hello 4")}
#+end_src
src_emacs-lisp[:exports none]{(message "Hello 4")} {{{results(=Hello 4=)}}}
** Escape Hugo shortcodes
- md :: src_md[:exports code]{{{< some_shortcode "foo" >}}}
- org :: src_org[:exports code]{{{% some_shortcode "foo" %}}}
- go-html-template :: src_go-html-template[:exports code]{{{< some_shortcode "foo" >}}}
** Using custom CSS for inline src blocks
{{{oxhugoissue(638)}}}

CSS used here:
#+begin_src html :noweb-ref inline_src_css
<style>
code.inline-src.language-nim::before {
color: initial;
content: "「";
}
code.inline-src.language-nim::after {
color: initial;
content: "」";
}
</style>
#+end_src

#+begin_export html
<style>
code.inline-src.language-nim::before {
color: initial;
content: "「";
}
code.inline-src.language-nim::after {
color: initial;
content: "」";
}
</style>
#+end_export

In Nim, src_nim[:exports code]{echo "hello"} will print
{{{results(/hello/)}}}.
** COMMENT Wrapping inline source block in a list item
As of <2022-03-01 Tue>, below snippet exports incorrectly due to a bug
in Org element parsing in Org mode. The issue was [[https://lists.gnu.org/r/emacs-orgmode/2022-03/msg00008.html][reported on the
mailing list today]].
- abcdefg abcdefg abcdefg abcdefg src_org[:exports code]{[[abc
def][bar]]}.
* Formatting :formatting:
** General
:PROPERTIES:
Expand Down
50 changes: 48 additions & 2 deletions test/site/content/posts/inline-code-blocks.md
Expand Up @@ -31,7 +31,7 @@ src_emacs-lisp[:exports results]{(message "Hello 1")}
src_emacs-lisp[:exports code]{(message "Hello 2")}
```

`(message "Hello 2")`
<code class="inline-src language-emacs-lisp" data-lang="emacs-lisp">(message "Hello 2")</code>


## Both code and results {#both-code-and-results}
Expand All @@ -40,11 +40,57 @@ src_emacs-lisp[:exports code]{(message "Hello 2")}
src_emacs-lisp[:exports both]{(message "Hello 3")}
```

`(message "Hello 3")` `Hello 3`
<code class="inline-src language-emacs-lisp" data-lang="emacs-lisp">(message "Hello 3")</code> `Hello 3`


## None! {#none}

```org
src_emacs-lisp[:exports none]{(message "Hello 4")}
```


## Escape Hugo shortcodes {#escape-hugo-shortcodes}

md
: <code class="inline-src language-md" data-lang="md">{{</* some_shortcode "foo" */>}}</code>

org
: <code class="inline-src language-org" data-lang="org">{{%/* some_shortcode "foo" */%}}</code>

go-html-template
: <code class="inline-src language-go-html-template" data-lang="go-html-template">{{</* some_shortcode "foo" */>}}</code>


## Using custom CSS for inline src blocks {#using-custom-css-for-inline-src-blocks}

`ox-hugo` Issue #[638](https://github.com/kaushalmodi/ox-hugo/issues/638)

CSS used here:

```html
<style>
code.inline-src.language-nim::before {
color: initial;
content: "「";
}
code.inline-src.language-nim::after {
color: initial;
content: "」";
}
</style>
```

<style>
code.inline-src.language-nim::before {
color: initial;
content: "「";
}
code.inline-src.language-nim::after {
color: initial;
content: "」";
}
</style>

In Nim, <code class="inline-src language-nim" data-lang="nim">echo "hello"</code> will print
_hello_.