Skip to content

Commit

Permalink
fix: Change inline src block output to work around CommonMark issue
Browse files Browse the repository at this point in the history
- Before: Inline src block classes were in the HTML code element
- Now: The inline src block classes are in HTLM span tags wrapping
  Markdown `verbatim` block.

Fixes #640.
  • Loading branch information
kaushalmodi committed May 22, 2022
1 parent 0a672e2 commit 91f17c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
5 changes: 3 additions & 2 deletions ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -2452,8 +2452,9 @@ Escape Hugo shortcodes if present in this element's value."
(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)))
(format "<span class=\"inline-src language-%s\" data-lang=\"%s\">%s</span>"
lang lang
(org-md-verbatim inline-src-block nil nil))))

;;;; Keyword
(defun org-hugo-keyword (keyword contents info)
Expand Down
12 changes: 8 additions & 4 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -2170,11 +2170,11 @@ src_emacs-lisp[:exports none]{(message "Hello 4")} {{{results(=Hello 4=)}}}
CSS used here:
#+begin_src html :noweb-ref inline_src_css
<style>
code.inline-src.language-nim::before {
.inline-src.language-nim code::before {
color: initial;
content: "「";
}
code.inline-src.language-nim::after {
.inline-src.language-nim code::after {
color: initial;
content: "」";
}
Expand All @@ -2183,17 +2183,21 @@ CSS used here:

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

{{{oxhugoissue(640)}}} -- Test that straight quotes in inline src
blocks don't get rendered as curved quotes by Hugo/Goldmark's
Typographer.

In Nim, src_nim[:exports code]{echo "hello"} will print
{{{results(/hello/)}}}.
** COMMENT Wrapping inline source block in a list item
Expand Down
24 changes: 14 additions & 10 deletions test/site/content/posts/inline-code-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ src_emacs-lisp[:exports results]{(message "Hello 1")}
src_emacs-lisp[:exports code]{(message "Hello 2")}
```

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


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

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


## None! {#none}
Expand All @@ -53,13 +53,13 @@ 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>
: <span class="inline-src language-md" data-lang="md">`{{</* some_shortcode "foo" */>}}`</span>

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

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


## Using custom CSS for inline src blocks {#using-custom-css-for-inline-src-blocks}
Expand All @@ -70,27 +70,31 @@ CSS used here:

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

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

In Nim, <code class="inline-src language-nim" data-lang="nim">echo "hello"</code> will print
`ox-hugo` Issue #[640](https://github.com/kaushalmodi/ox-hugo/issues/640) -- Test that straight quotes in inline src
blocks don't get rendered as curved quotes by Hugo/Goldmark's
Typographer.

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

0 comments on commit 91f17c6

Please sign in to comment.