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

Support ox-hugo export backend #21

Closed
authsec opened this issue Dec 15, 2021 · 7 comments
Closed

Support ox-hugo export backend #21

authsec opened this issue Dec 15, 2021 · 7 comments
Labels
duplicate This issue or pull request already exists

Comments

@authsec
Copy link

authsec commented Dec 15, 2021

I try to use ox-hugo as an export backend the exporter however does not recognize the parameter values of the special blocks. After a discussion on reddit the ox-hugo creator/maintainer mentioned to raise an issue here, as this seems to be something that he cannot fix on his end.

Problem

When doing a LaTeX export, the stutter example works and repeats 5 times, however on ox-hugo export the repeat only happens 2 times, as seems to be the function default. The presumption is that the parameters of the #begin_noteblock block are ignored by org-special-block-extras when exporting using ox-hugo.

Configuration

The package configuration looks like:

 (use-package org-special-block-extras
       :ensure t
       :after org
       :hook (org-mode . org-special-block-extras-mode)
       ;; All relevant Lisp functions are prefixed ‘o-’; e.g., `o-docs-insert'.

       :config
       (o-defblock noteblock (title "Note") (title-color "primary")
		   "Define noteblock export for docsy ox hugo"
		   (apply #'concat
			  (pcase backend
			    (`latex `("\\begin{noteblock}", contents, "\\end{noteblock}"))
			    (`hugo `("{{% alert title=\"", title, "\" color=\"", title-color, "\" %}}\n", contents, "\n{{% /alert %}}"))
			    )
			  )
		   )
       (o-defblock cautionblock (title "Caution") (title-color "warning")
		   "Awesomebox caution"
		   (apply #'concat
			  (pcase backend
			    (`latex `("\\begin{cautionblock}", contents, "\\end{cautionblock}"))
			    (`hugo `("{{% alert title=\"", title, "\" color=\"", title-color, "\" %}}\n", contents, "\n{{% /alert %}}"))
			    )
			  )
		   )
       )

The org parts in using them look like:

  #+begin_noteblock
  This is a noteblock info environment from the awesomebox LaTeX package.
  #+end_noteblock

  #+begin_stutter 5
  gaga
  #+end_stutter
 
  Some blabla blabli and a little bit of a plantuml file, make sure to put the code to render the image and also add some attributes on top of the =#RESULTS:= line under which the generated image is displayed. You can control the image layout with these attributes when rendered to LaTeX.

  #+begin_cautionblock 
  Danger, Will Robinson!

  It is possible to use the blocks
  #+end_cautionblock

A screenshot of how this currently renders:

From left to right (org source, ox-hugo output using the docsy theme, LaTeX output)

Screenshot 2021-12-15 at 22 35 59

@alhassy
Copy link
Owner

alhassy commented Dec 31, 2021

Hey @authsec, nice screenshots!

Unfortunately, I'm not very familiar with ox-hugo, but from a cursoury glance it seems that ox-hugo has it's own support for special blocks: It looks like that there are CSS style definitions for the resulting HTML tags.

It may be best to ask @kaushalmodi of ox-hugo to take a look. In particular, to whether ox-hugo performs any translation phase wrt special blocks; e.g., whether org-export-before-processing-hook is used? [This hook is the main way my package can do its thing.]

For now, @authsec, an alternative to shortcodes, one thing to try is to mimic ox-hugo's nesting for block arguments via nested blocks; but this is far from ideal.

@alhassy
Copy link
Owner

alhassy commented Jan 1, 2022

Hey @authsec, and @kaushalmodi, there is now a solution to this issue over at #12 (comment). Let me know if that works for your needs 😁

@alhassy alhassy added duplicate This issue or pull request already exists and removed help wanted Extra attention is needed labels Jan 1, 2022
@alhassy alhassy closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2022
@kaushalmodi
Copy link

@alhassy Apologies for not replying sooner. I don't have much to comment because I am not using this package.

I hope that the original poster @authsec can provide some feedback to your reply.

I understand how disheartening it can be when you spend time and effort to reply to an issue and then you hear nothing from the original poster.

@authsec
Copy link
Author

authsec commented Jun 7, 2022

Hi @alhassy/@kaushalmodi,

I managed to make it work again with the following (doom) config snippet:

(use-package! org-special-block-extras
  :ensure t
  :after org
  :hook (org-mode . org-special-block-extras-mode)
  :config
  (defun ospe-add-support-for-derived-backend (new-backend parent-backend)
    "See subsequent snippet for a working example use."
    (add-to-list 'org-export-filter-parse-tree-functions
                 `(lambda (tree backend info)
                    (when (eq backend (quote ,new-backend))
                      (org-element-map tree 'export-block
                        (lambda (el)
                          (when (string= (org-element-property :type el) (s-upcase (symbol-name (quote ,new-backend))))
                            (org-element-put-property el :type (s-upcase (symbol-name (quote ,parent-backend))))))))
                    tree)))
(progn
;; Register new backend
(ospe-add-support-for-derived-backend 'hugo 'html)
;; Register new special block
(org-defblock noteblock (title "Note") (titleColor "primary")
            "Define noteblock export for docsy ox hugo"
            (if ;; ≈ (or (equal backend 'latex) (equal backend new-backend) ⋯)
                (org-export-derived-backend-p backend 'hugo)
                (format "{{%% alert title=\"%s\" color=\"%s\"%%}}\n%s{{%% /alert %%}}" title titleColor raw-contents) title titleColor
                raw-contents))
)
)

The interesting thing to me is, that it seems to export to latex as intended. The built-in stutter command e.g. takes the arguments just fine and repeats the words to stutter, for 5 times (in my example). The export to Hugo however does not do that. If I look at the generated markdown file, the words to stutter are repeated for 2 times only, which is the built-in default.

@kaushalmodi Is it possible, that the Hugo exporter "eats" the arguments and doesn't pass them on to the derived? markdown exporter backend? If I do use the markdown exporter directly, the words are repeated 5 times, as expected.

@kaushalmodi
Copy link

Is it possible, that the Hugo exporter "eats" the arguments and doesn't pass them on to the derived? markdown exporter backend?

ox-hugo defines org-hugo-special-block and handles some special blocks there, and then delegates the parsing of other special blocks to org-blackfriday-special-block. Nothing ever gets passed on to org-md-special-block.

As I haven't looked into the internals of this package, I don't know how you are getting the "stutter" special block to work even with its default repeat count of 2.

@authsec
Copy link
Author

authsec commented Jun 7, 2022

Thanks for the explanation, I was just wild guessing, as I found it was strange that the other exporters seem to do it. My elisp Kung-Fu is quite bad.

You can get the stutter block to work, if you load OSBE and then put this in a org file and export the org file:

#+begin_stutter 5
gaga
#+end_stutter

The example would simply repeat the word gaga 5 times if it works correctly and only 2 times if it's using the defaults.

@authsec
Copy link
Author

authsec commented Jun 12, 2022

@kaushalmodi I just found out that if I'm exporting using [h] File to Md file, the stutter block and therefore the repetitions work, whereas if I'm using [A] All subtrees (or File) to Md file(s) it doesn't.

image

Does that help you in anyway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants