Skip to content

Commit

Permalink
pygmentsCodeFences -> markup.highlight.codeFences
Browse files Browse the repository at this point in the history
Similarly `pygmentsUseClasses` -> not `markup.highlight.noClasses`
  • Loading branch information
kaushalmodi committed Dec 31, 2021
1 parent dfc0d6c commit 6d1fb3e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 113 deletions.
31 changes: 7 additions & 24 deletions doc/config.toml
Expand Up @@ -16,25 +16,6 @@ cleandestinationdir = true
# files to be the date when I deleted them from this repo.. sigh.
# enableGitInfo = true

# https://gohugo.io/extras/highlighting/

# Syntax highlighting using Pygments
# $ python
# >>> from pygments.styles import STYLE_MAP
# >>> STYLE_MAP.keys()
# ['manni', 'igor', 'lovelace', 'xcode', 'vim', 'autumn', 'vs', 'rrt', 'native',
# 'perldoc', 'borland', 'tango', 'emacs', 'friendly', 'monokai', 'paraiso-dark',
# 'colorful', 'murphy', 'bw', 'pastie', 'algol_nu', 'paraiso-light', 'trac',
# 'default', 'algol', 'fruity']
# pygmentsStyle = "native"
# pygmentsStyle = "trac" # This is not needed as the theme is set using external CSS -- Tue Sep 26 13:26:59 EDT 2017 - kmodi
pygmentsCodeFences = true # This applies to Chroma too.
# Use pygmentize generated CSS file instead of inlining the code codes in the HTML.
# See https://gohugo.io/tools/syntax-highlighting/#pygments and
# https://github.com/richleland/pygments-css
pygmentsUseClasses = true # This applies to Chroma too.
pygmentsUseClassic = false # Needs Hugo 0.28+, default=false => Use Chroma for syntax highlighting

enableEmoji = true

LanguageCode = "en-us" # Used in RSS generation
Expand All @@ -44,6 +25,10 @@ disableFastRender = true # Hugo 0.30
disableKinds = ["taxonomy", "taxonomyTerm"]

[markup]
[markup.highlight]
codeFences = true # default = true
noClasses = false # default = true

[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true # This is *necessary* for ox-hugo to work well with Hugo 0.60.0+
Expand Down Expand Up @@ -78,12 +63,10 @@ disableKinds = ["taxonomy", "taxonomyTerm"]

images = ["/favicon-196x196.png"] # Used in twitter_cards.html partial

custom_css = [ # Pygments Trac theme
# "css/trac_pygments.css" # Needs pygmentsUseClasses to be true
# Chroma Trac theme
# "css/trac_chroma.css" # Needs pygmentsUseClasses to be true
custom_css = [ # Chroma Trac theme
# "css/trac_chroma.css" # Needs markup.highlight.noClasses to be false
# Chroma GitHub theme
"css/github_chroma.css" # Needs pygmentsUseClasses to be true
"css/github_chroma.css" # Needs markup.highlight.noClasses to be false
, "css/style.css"
]
custom_css_absolute = [ # Iosevka fonts
Expand Down
5 changes: 3 additions & 2 deletions doc/ox-hugo-manual.org
Expand Up @@ -1331,8 +1331,9 @@ Example:
#+end_src

- Note :: It is necessary to set the Hugo site config variable
=pygmentsCodeFences= to =true= for syntax highlighting to
work for fenced code blocks.
=markup.highlight.codeFences= to =true= (which is the default at
least as of [[https://github.com/gohugoio/hugo/commit/bfb9613a14ab2d93a4474e5486d22e52a9d5e2b3][Hugo v0.60.0]]) for syntax highlighting to work for fenced
code blocks.

The Hugo =highlight= shortcode is automatically used instead of code
fences (even with this property at a non-nil value) if:
Expand Down
13 changes: 9 additions & 4 deletions ox-hugo.el
Expand Up @@ -2646,10 +2646,15 @@ The code block is wrapped in Hugo \"highlight\" shortcode (See
https://gohugo.io/content-management/syntax-highlighting) if one
of the above conditions is false.
Note that even with the default non-nil value of HUGO_CODE_FENCE,
the user *needs* to set the `pygmentsCodeFences' variable to
`true' in their Hugo site's config, otherwise syntax highlighting
will not work in the generated fenced code blocks!
If using a Hugo version older than v0.60.0, note that even with
the default non-nil value of HUGO_CODE_FENCE, the user *needs* to
set the `pygmentsCodeFences' variable to `true' in their Hugo
site's config. Otherwise syntax highlighting will not work in
the generated fenced code blocks!
Hugo v0.60.0 onwards, the `markup.highlight.codeFences' (new name
for the old `pygmentsCodeFences') config variable defaults to
true.
Hugo \"highlight\" shortcode features:
- Code blocks with line numbers (if the -n or +n switch is used)
Expand Down
7 changes: 4 additions & 3 deletions test/site/config.toml
Expand Up @@ -17,10 +17,11 @@ enableGitInfo = true

disableFastRender = true # Hugo 0.30

pygmentsCodeFences = true # This applies to Chroma too.
pygmentsUseClasses = true # This applies to Chroma too.

[markup]
[markup.highlight]
codeFences = true # default = true
noClasses = false # default = true

[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true # This is *necessary* for ox-hugo to work well with Hugo 0.60.0+
Expand Down
43 changes: 6 additions & 37 deletions test/site/content-org/all-posts.org
Expand Up @@ -1247,8 +1247,8 @@ The source blocks are code-fenced by default.
#+include: "./all-posts.org::#example-text-with-code-blocks" :only-contents t
-----
*It is necessary to set the Hugo site config variable
=pygmentsCodeFences= to =true= for syntax highlighting to work for
fenced code blocks.*
=markup.highlight.codeFences= to =true= (default) for syntax
highlighting to work for fenced code blocks.*
*** Code-fenced source blocks
:PROPERTIES:
:EXPORT_HUGO_CODE_FENCE: t
Expand All @@ -1261,8 +1261,8 @@ the =EXPORT_HUGO_CODE_FENCE= property to =t=.
#+include: "./all-posts.org::#example-text-with-code-blocks" :only-contents t
-----
*It is necessary to set the Hugo site config variable
=pygmentsCodeFences= to =true= for syntax highlighting to work for
fenced code blocks.*
=markup.highlight.codeFences= to =true= (default) for syntax
highlighting to work for fenced code blocks.*
*** Code-fenced source blocks with backticks :backticks:
:PROPERTIES:
:EXPORT_HUGO_CODE_FENCE: t
Expand Down Expand Up @@ -1772,8 +1772,8 @@ Below, the same ~figure~ shortcode is called with the ~%~ syntax.

-----
*It is necessary to set the Hugo site config variable
=pygmentsCodeFences= to =true= for syntax highlighting to work for
fenced code blocks.*
=markup.highlight.codeFences= to =true= (default) for syntax
highlighting to work for fenced code blocks.*
** Source blocks with ATTR_HTML :attr___html:attr___css:
:PROPERTIES:
:EXPORT_FILE_NAME: source-blocks-with-attr-html
Expand All @@ -1789,37 +1789,6 @@ Some text.
#+end_src

Some more text.
** Org Source Block via Pygments :pygments:noexport:
:PROPERTIES:
:EXPORT_FILE_NAME: org-source-block-pygments
:END:
/This test case is not important after Hugo 0.28 as this was a
workaround for a limitation in the Pygments syntax highlighter. Hugo
0.28 onwards, the default syntax highlighter is Chroma, which does not
have that limitation, and thus no need for this workaround./
-----
Test case for the case where user has set
=org-hugo-langs-no-descr-in-code-fences= to a list containing the
element =org=.

/As this variable is dependent on user's config, this post is not set
to be exported by default./

The [[https://discourse.gohugo.io/t/fenced-code-block-with-language-unsupported-by-pygments/7710][issue]] with Hugo will be seen if _all_ of the below are true:
- =pygmentsCodeFences = true= *and* =pygmentsUseClassic = true= (Hugo
≥ 0.28 -- default value is =false=) are set in the Hugo site
=config.toml=.
- A source block's language is set to one that's not supported by
Pygments (like [[https://bitbucket.org/birkenfeld/pygments-main/issues/719/wishlist-support-org][org]], and thus the below example with source code
language set to =org=).
- =org-hugo-langs-no-descr-in-code-fences= is set to a value not
containing that language descriptor (=org= in this case).
#+begin_src org
# Org comment
Export this post after setting
=org-hugo-langs-no-descr-in-code-fences= to =(org)= and temporarily
removing the =noexport= tag.
#+end_src
* Formatting :formatting:
** General
:PROPERTIES:
Expand Down
4 changes: 2 additions & 2 deletions test/site/content/posts/code-fenced-src-blocks-default.md
Expand Up @@ -80,5 +80,5 @@ def permanent(m):
---

**It is necessary to set the Hugo site config variable
`pygmentsCodeFences` to `true` for syntax highlighting to work for
fenced code blocks.**
`markup.highlight.codeFences` to `true` (default) for syntax
highlighting to work for fenced code blocks.**
4 changes: 2 additions & 2 deletions test/site/content/posts/code-fenced-src-blocks.md
Expand Up @@ -81,5 +81,5 @@ def permanent(m):
---

**It is necessary to set the Hugo site config variable
`pygmentsCodeFences` to `true` for syntax highlighting to work for
fenced code blocks.**
`markup.highlight.codeFences` to `true` (default) for syntax
highlighting to work for fenced code blocks.**
37 changes: 0 additions & 37 deletions test/site/content/posts/org-source-block-pygments.md

This file was deleted.

Expand Up @@ -62,8 +62,8 @@ Note
---

**It is necessary to set the Hugo site config variable
`pygmentsCodeFences` to `true` for syntax highlighting to work for
fenced code blocks.**
`markup.highlight.codeFences` to `true` (default) for syntax
highlighting to work for fenced code blocks.**

[^fn:1]: Even if the user has set the `HUGO_CODE_FENCE` value to `t`
(via variable, keyword or subtree property), the Hugo `highlight`
Expand Down

0 comments on commit 6d1fb3e

Please sign in to comment.