diff --git a/ox-hugo-pandoc-cite.el b/ox-hugo-pandoc-cite.el index f227eea..ae60e1f 100644 --- a/ox-hugo-pandoc-cite.el +++ b/ox-hugo-pandoc-cite.el @@ -14,7 +14,7 @@ ;; TODO: Change the defconst to defvar (defvar org-hugo-pandoc-cite-pandoc-args-list '("-f" "markdown" - "-t" "markdown-citations-simple_tables+pipe_tables" + "-t" "markdown-citations-simple_tables+pipe_tables-fenced_divs" "--atx-headers" "--id-prefix=fn:") "Pandoc arguments used in `org-hugo-pandoc-cite--run-pandoc'. @@ -31,6 +31,9 @@ +pipe_tables : Add the \"pipe_tables\" style insted that Blackfriday understands. + -fenced_divs : Do not replace HTML
tags with Pandoc fenced + divs \":::\". + --atx-headers : Use \"# foo\" style heading for output markdown. --id-prefix=fn: : Create footnote ID's like \"[^fn:1]\" instead of @@ -48,7 +51,8 @@ arguments.") (defvar org-hugo-pandoc-cite--run-pandoc-buffer "*Pandoc Citations*" "Buffer to contain the `pandoc' run output and errors.") -(defvar org-hugo-pandoc-cite--references-header-regexp "^::: {#refs \\.references}$" +(defvar org-hugo-pandoc-cite--references-header-regexp + "^
$" "Regexp to match the Pandoc-inserted references header string. This string is present only if Pandoc has resolved one or more @@ -138,24 +142,37 @@ The list of Pandoc specific meta-data is defined in Required fixes: -- Unescape the Hugo shortcodes: \"{{\\\\=< shortcode \\\\=>}}\" -> - \"{{< shortcode >}}\". - -- Replace \"::: {#refs .references}\" with \"## References\" - where the number of hashes depends on HUGO_LEVEL_OFFSET, - followed by an opening HTML div tag. - -- Replace \"::: {#ref-someref}\" with \"
\". +- Prepend Pandoc inserted \"references\" class div with Markdown + heading \"## References\" where the number of hashes depends on + LOFFSET. LOFFSET = 1 will insert 2 hashes. -- Replace \"^:::$\" with closing HTML div tags. +- Add the Blackfriday required \"
\" hack to Pandoc + divs with \"ref\" id's. -LOFFSET is the offset added to the base level of 1 for headings." +- Unescape the Hugo shortcodes: \"{{\\\\=< shortcode \\\\=>}}\" -> + \"{{< shortcode >}}\"." (with-temp-buffer (insert content) (let ((case-fold-search nil) (level-mark (make-string (+ loffset 1) ?#))) (goto-char (point-min)) + + ;; Prepend the Pandoc inserted "references" class div with + ;; "References" heading in Markdown. + (save-excursion + ;; There should be at max only one replacement needed for + ;; this. + (when (re-search-forward org-hugo-pandoc-cite--references-header-regexp nil :noerror) + (replace-match (concat level-mark + " References {#references}\n\n" + "\\&\n
\n")))) ;See footnote 1 + + ;; Add the Blackfriday required hack to Pandoc ref divs. + (save-excursion + (let ((regexp "^
$")) + (while (re-search-forward regexp nil :noerror) + (replace-match "\\&\n
")))) ;See footnote 1 + ;; Fix Hugo shortcodes. (save-excursion (let ((regexp (concat "{{\\\\<" @@ -165,28 +182,7 @@ LOFFSET is the offset added to the base level of 1 for headings." "\\\\>}}"))) (while (re-search-forward regexp nil :noerror) (replace-match "{{< \\1 >}}" :fixedcase)))) - ;; Convert Pandoc ref ID style to HTML div's. - (save-excursion - (let ((regexp "^::: {#ref-\\(.+?\\)}$")) - (while (re-search-forward regexp nil :noerror) - (replace-match (concat "
" - "\n
\n") ;See footnote 1 - :fixedcase) - (re-search-forward "^:::$") - (replace-match "\n
")))) - ;; Replace "::: {#refs .references}" with a base-level - ;; "References" heading in Markdown, followed by an opening HTML - ;; div tag. - (save-excursion - ;; There should be at max only one replacement needed for - ;; this. - (when (re-search-forward org-hugo-pandoc-cite--references-header-regexp nil :noerror) - (replace-match (concat level-mark - " References {#references}\n\n" - "
" - "\n
\n\n")) ;See footnote 1 - (re-search-forward "^:::$") - (replace-match "\n\n
"))) + (buffer-substring-no-properties (point-min) (point-max))))) (defun org-hugo-pandoc-cite--parse-citations (info orig-outfile) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 518976f..14bb6bb 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -4624,6 +4624,10 @@ Some text. #+begin_myshortcode Text not containing *Markdown* #+end_myshortcode +*** Testing ox-hugo inserted HTML div tags +#+begin_foo +*bold* /italics/ +#+end_foo *** Testing tables |----------+----------+----------| | Header 1 | Header 2 | Header 3 | diff --git a/test/site/content/posts/citations-example-toml.md b/test/site/content/posts/citations-example-toml.md index 2c08ebe..4d35ce7 100644 --- a/test/site/content/posts/citations-example-toml.md +++ b/test/site/content/posts/citations-example-toml.md @@ -31,6 +31,18 @@ Some text. {{< myshortcode >}} Text not containing **Markdown** {{< /myshortcode >}} +## Testing ox-hugo inserted HTML div tags + +
+ +
+ +
+ +**bold** *italics* + +
+ ## Testing tables | Header 1 | Header 2 | Header 3 | @@ -78,7 +90,6 @@ Level."
- -
+
[^fn:1]: See (Thompson et al. 2016). diff --git a/test/site/content/posts/citations-example-yaml.md b/test/site/content/posts/citations-example-yaml.md index 3750475..d051e2f 100644 --- a/test/site/content/posts/citations-example-yaml.md +++ b/test/site/content/posts/citations-example-yaml.md @@ -62,7 +62,6 @@ Level."
- - + [^fn:1]: See (Thompson et al. 2016).