Skip to content

Commit

Permalink
Merge pull request #522 from kaushalmodi/more-div-hack-removals
Browse files Browse the repository at this point in the history
More div hack removals + test for #521
  • Loading branch information
kaushalmodi committed Jan 12, 2022
2 parents 22677d7 + 877d87a commit 3a7cb20
Show file tree
Hide file tree
Showing 27 changed files with 45 additions and 69 deletions.
25 changes: 16 additions & 9 deletions ox-hugo-pandoc-cite.el
Expand Up @@ -11,6 +11,8 @@

;;; Code:

(declare-function org-hugo--plist-get-true-p "ox-hugo")

(defcustom org-hugo-pandoc-cite-references-heading "References {#references}"
"Markdown title for Pandoc inserted references section."
:group 'org-export-hugo
Expand Down Expand Up @@ -164,19 +166,21 @@ The list of Pandoc specific meta-data is defined in
(delete-matching-lines regexp))
(buffer-substring-no-properties (point-min) (point-max))))

(defun org-hugo-pandoc-cite--fix-pandoc-output (content loffset)
(defun org-hugo-pandoc-cite--fix-pandoc-output (content loffset info)
"Fix the Pandoc output CONTENT and return it.
Required fixes:
- Prepend Pandoc inserted \"references\" class div with
`org-hugo-pandoc-cite-references-heading'.
- Add the Blackfriday required \"<div></div>\" hack to Pandoc
divs with \"ref\" id's.
- When not using Goldmark (Hugo v0.60.0+), add the Blackfriday
required \"<div></div>\" hack to Pandoc divs with \"ref\" id's.
- Unescape the Hugo shortcodes: \"{{\\\\=< shortcode \\\\=>}}\" ->
\"{{< shortcode >}}\"."
\"{{< shortcode >}}\"
INFO is a plist used as a communication channel."
(with-temp-buffer
(insert content)
(let ((case-fold-search nil))
Expand All @@ -192,12 +196,15 @@ Required fixes:
(when (org-string-nw-p org-hugo-pandoc-cite-references-heading)
(let ((level-mark (make-string (+ loffset 1) ?#)))
(setq references-heading (concat level-mark " " org-hugo-pandoc-cite-references-heading))))
(replace-match (concat references-heading "\n\n\\&\n <div></div>\n"))))) ;See footnote 1
(replace-match (concat references-heading "\n\n\\&"
(when (null (org-hugo--plist-get-true-p info :hugo-goldmark))
"\n <div></div>\n")))))) ;See footnote 1

;; Add the Blackfriday required hack to Pandoc ref divs.
(save-excursion
(while (re-search-forward org-hugo-pandoc-cite--reference-entry-regexp nil :noerror)
(replace-match "\\&\n <div></div>"))) ;See footnote 1
(when (null (org-hugo--plist-get-true-p info :hugo-goldmark))
(save-excursion
(while (re-search-forward org-hugo-pandoc-cite--reference-entry-regexp nil :noerror)
(replace-match "\\&\n <div></div>")))) ;See footnote 1

;; Fix Hugo shortcodes.
(save-excursion
Expand Down Expand Up @@ -289,7 +296,7 @@ ORIG-OUTFILE is the Org exported file name."
;; references.
(if content-has-references
(let* ((contents-fixed (org-hugo-pandoc-cite--fix-pandoc-output
pandoc-outfile-contents loffset))
pandoc-outfile-contents loffset info))
(fm (org-hugo-pandoc-cite--remove-pandoc-meta-data fm))
(fm-plus-content (concat fm "\n" contents-fixed)))
(write-region fm-plus-content nil orig-outfile))
Expand Down
3 changes: 2 additions & 1 deletion ox-hugo.el
Expand Up @@ -1147,7 +1147,8 @@ contents according to the current heading."
(if local
" local"
""))
"<div></div>\n" ;This is a nasty workaround till Hugo/Blackfriday support
(when (not org-hugo-goldmark)
"<div></div>\n") ;This is a nasty workaround till Hugo/Blackfriday support
toc-heading ;wrapping Markdown in HTML div's.
"\n"
toc-items ;https://github.com/kaushalmodi/ox-hugo/issues/93
Expand Down
3 changes: 3 additions & 0 deletions test/site/content-org/all-posts.org
Expand Up @@ -7263,6 +7263,9 @@ you will be able to see when you view this page's source).
[[https://github.com/Vonng][*Vonng*]] in [[https://github.com/gohugoio/hugo/issues/234#issuecomment-347725391][this comment]]. All credit for this post
goes to the original author.
-----

#+toc: headlines 2

神经网络相关基本知识笔记
*** 神经网络表示
**** 神经元模型
Expand Down
1 change: 0 additions & 1 deletion test/site/content/dir-locals-test/dir-locals-test.md
Expand Up @@ -13,7 +13,6 @@ creator: "Dummy creator string"
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
3 changes: 0 additions & 3 deletions test/site/content/issues/336_test.md
Expand Up @@ -16,11 +16,8 @@ This issue only appears when there is a citation Giovanelli (2016)
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-giovanelli2016" class="csl-entry">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" The Reichenbach--Einstein Debate on the Geometrization
Expand Down
6 changes: 0 additions & 6 deletions test/site/content/posts/citation-forms-apa-csl.md
Expand Up @@ -67,11 +67,8 @@ citations" ([n.d.](#ref-rmdCitations)) for more.

<div id="refs" class="references csl-bib-body hanging-indent"
line-spacing="2">
<div></div>


<div id="ref-rmdCitations" class="csl-entry">
<div></div>

Bibliographies and citations / citations. (n.d.). In *RMarkdown*.
RStudio. Retrieved from
Expand All @@ -80,23 +77,20 @@ RStudio. Retrieved from
</div>

<div id="ref-doe99" class="csl-entry">
<div></div>

Doe, J. (1999). *An awesome revelation* (3rd ed., Vol. 4). The address:
Publisher Foo.

</div>

<div id="ref-smith04" class="csl-entry">
<div></div>

Smith, A. (2004). *The book on life* (1st ed., Vol. 7). The address:
Publisher Bar.

</div>

<div id="ref-addCite17" class="csl-entry">
<div></div>

Xie, Y. (2017). Adding citations to posts. Retrieved from
<https://blogdown-demo.rbind.io/2017/08/28/adding-citations-to-posts/>
Expand Down
6 changes: 0 additions & 6 deletions test/site/content/posts/citation-forms.md
Expand Up @@ -63,11 +63,8 @@ Citations" ([n.d.](#ref-rmdCitations)) for more.
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-rmdCitations" class="csl-entry">
<div></div>

"Bibliographies and Citations / Citations." n.d. In *RMarkdown*.
RStudio.
Expand All @@ -76,23 +73,20 @@ RStudio.
</div>

<div id="ref-doe99" class="csl-entry">
<div></div>

Doe, John. 1999. *An Awesome Revelation*. 3rd ed. Vol. 4. 10th Series.
The address: Publisher Foo.

</div>

<div id="ref-smith04" class="csl-entry">
<div></div>

Smith, Adam. 2004. *The Book on Life*. 1st ed. Vol. 7. 99th Series. The
address: Publisher Bar.

</div>

<div id="ref-addCite17" class="csl-entry">
<div></div>

Xie, Yihui. 2017. "Adding Citations to Posts."
<https://blogdown-demo.rbind.io/2017/08/28/adding-citations-to-posts/>.
Expand Down
6 changes: 0 additions & 6 deletions test/site/content/posts/citation-linking.md
Expand Up @@ -16,18 +16,14 @@ footnote citation.[^fn:1]
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-eilan2016" class="csl-entry">
<div></div>

Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

</div>

<div id="ref-giovanelli2016" class="csl-entry">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" The Reichenbach--Einstein Debate on the Geometrization
Expand All @@ -37,15 +33,13 @@ Science* 54: 35--51.
</div>

<div id="ref-loncar2016" class="csl-entry">
<div></div>

Loncar, Samuel. 2016. "Why Listen to Philosophers? A Constructive
Critique of Disciplinary Philosophy." *Metaphilosophy* 47 (1): 3--25.

</div>

<div id="ref-thompson2016" class="csl-entry">
<div></div>

Thompson, Morgan, Toni Adleberg, Sam Sims, and Eddy Nahmias. 2016. "Why
Do Women Leave Philosophy? Surveying Students at the Introductory
Expand Down
7 changes: 0 additions & 7 deletions test/site/content/posts/citations-example-toml.md
Expand Up @@ -88,18 +88,14 @@ Ox-hugo manual (Modi, Kaushal (2018))
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-eilan2016" class="csl-entry">
<div></div>

Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

</div>

<div id="ref-giovanelli2016" class="csl-entry">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" The Reichenbach--Einstein Debate on the Geometrization
Expand All @@ -109,23 +105,20 @@ Science* 54: 35--51.
</div>

<div id="ref-loncar2016" class="csl-entry">
<div></div>

Loncar, Samuel. 2016. "Why Listen to Philosophers? A Constructive
Critique of Disciplinary Philosophy." *Metaphilosophy* 47 (1): 3--25.

</div>

<div id="ref-ox_hugo_man" class="csl-entry">
<div></div>

Modi, Kaushal. 2018. *Ox-Hugo: A Carefully Crafted Org Exporter Back-End
for Hugo*. North Carolina, USA. <https://ox-hugo.scripter.co/>.

</div>

<div id="ref-thompson2016" class="csl-entry">
<div></div>

Thompson, Morgan, Toni Adleberg, Sam Sims, and Eddy Nahmias. 2016. "Why
Do Women Leave Philosophy? Surveying Students at the Introductory
Expand Down
6 changes: 0 additions & 6 deletions test/site/content/posts/citations-example-yaml.md
Expand Up @@ -25,18 +25,14 @@ Content in section 2.
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-eilan2016" class="csl-entry">
<div></div>

Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

</div>

<div id="ref-giovanelli2016" class="csl-entry">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" The Reichenbach--Einstein Debate on the Geometrization
Expand All @@ -46,15 +42,13 @@ Science* 54: 35--51.
</div>

<div id="ref-loncar2016" class="csl-entry">
<div></div>

Loncar, Samuel. 2016. "Why Listen to Philosophers? A Constructive
Critique of Disciplinary Philosophy." *Metaphilosophy* 47 (1): 3--25.

</div>

<div id="ref-thompson2016" class="csl-entry">
<div></div>

Thompson, Morgan, Toni Adleberg, Sam Sims, and Eddy Nahmias. 2016. "Why
Do Women Leave Philosophy? Surveying Students at the Introductory
Expand Down
4 changes: 0 additions & 4 deletions test/site/content/posts/citations-with-captions/index.md
Expand Up @@ -42,18 +42,14 @@ Snippet 1</a></span>: Nested Boxes using PlantUML
## References {#references}

<div id="refs" class="references csl-bib-body hanging-indent">
<div></div>


<div id="ref-eilan2016" class="csl-entry">
<div></div>

Eilan, Naomi. 2016. "You Me and the World." *Analysis* 76 (3): 311--24.

</div>

<div id="ref-giovanelli2016" class="csl-entry">
<div></div>

Giovanelli, Marco. 2016. "\"\...But I Still Can't Get Rid of a Sense of
Artificiality\" The Reichenbach--Einstein Debate on the Geometrization
Expand Down
1 change: 0 additions & 1 deletion test/site/content/posts/link-to-headings-by-name.md
Expand Up @@ -10,7 +10,6 @@ draft = false
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
1 change: 0 additions & 1 deletion test/site/content/posts/no-toc-in-summary--with-more.md
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
1 change: 0 additions & 1 deletion test/site/content/posts/no-toc-in-summary--without-more.md
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -10,7 +10,6 @@ draft = false
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -10,7 +10,6 @@ draft = false
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -10,7 +10,6 @@ draft = false
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
Expand Up @@ -10,7 +10,6 @@ draft = false
}
</style>
<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
1 change: 0 additions & 1 deletion test/site/content/posts/post-with-toc-keyword-2.md
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down
1 change: 0 additions & 1 deletion test/site/content/posts/post-with-toc-keyword-6.md
Expand Up @@ -5,7 +5,6 @@ draft = false
+++

<div class="ox-hugo-toc toc">
<div></div>

<div class="heading">Table of Contents</div>

Expand Down

0 comments on commit 3a7cb20

Please sign in to comment.