diff --git a/ox-blackfriday.el b/ox-blackfriday.el index b72ae50..104be01 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -384,6 +384,15 @@ style tag." ""))))) ret)) +;;;; Sanitize URL +(defun org-blackfriday-url-sanitize (url) + "Sanitize the URL by replace certain characters with their hex encoding. + +Replaces \"_\" with \"%5F\". + +Workaround for Blackfriday bug https://github.com/russross/blackfriday/issues/278." + (replace-regexp-in-string "_" "%5F" url)) + ;;; Transcode Functions diff --git a/ox-hugo.el b/ox-hugo.el index 7ba0901..c25e687 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1692,9 +1692,13 @@ INFO is a plist used as a communication channel. Unlike `org-md-link', this function will also copy local images and rewrite link paths to make blogging more seamless." - (let ((raw-link (org-element-property :raw-link link)) - (raw-path (org-element-property :path link)) - (type (org-element-property :type link))) + (let* ((raw-link (org-element-property :raw-link link)) + (raw-path (org-element-property :path link)) + (type (org-element-property :type link)) + (link-is-url (member type '("http" "https" "ftp" "mailto")))) + (when (and (stringp raw-path) + link-is-url) + (setq raw-path (org-blackfriday-url-sanitize raw-path))) ;; (message "[ox-hugo-link DBG] link: %S" link) ;; (message "[ox-hugo-link DBG] link path: %s" (org-element-property :path link)) ;; (message "[ox-hugo-link DBG] link filename: %s" (expand-file-name (plist-get (car (cdr link)) :path))) @@ -1767,7 +1771,7 @@ and rewrite link paths to make blogging more seamless." grand-parent parent)) (inline-image (not (org-html-standalone-image-p useful-parent info))) - (source (if (member type '("http" "https" "ftp")) + (source (if link-is-url (concat type ":" path) path)) (attr (org-export-read-attribute :attr_html useful-parent)) @@ -1861,7 +1865,7 @@ and rewrite link paths to make blogging more seamless." (t (let* ((link-param-str "") (path (cond - ((member type '("http" "https" "ftp" "mailto")) + (link-is-url ;; Taken from ox-html.el -- Extract attributes ;; from parent's paragraph. HACK: Only do this ;; for the first link in parent (inner image link diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index e8d52c9..1e0e91e 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -1994,6 +1994,22 @@ And these ones should be eventually removed and _underline_ the text - /This is italics, and *this is bold too*, and back to plain italics./ - *This is bold, and /this is italics too/, and back to plain bold.* +** Italicize links with underscores :italic:links:underscore: +:PROPERTIES: +:EXPORT_FILE_NAME: italicize-links-with-underscores +:END: +#+begin_description +Test that links with underscores can be italicized/emboldened/both. +#+end_description +{{{oxhugoissue(170)}}} +*** External links +- Italic :: /What is a [[https://en.wikipedia.org/wiki/Two%27s_complement][two's complement]]?/ +- Bold :: *What is a [[https://en.wikipedia.org/wiki/Two%27s_complement][two's complement]]?* +- Bold + Italic :: /*What is a [[https://en.wikipedia.org/wiki/Two%27s_complement][two's complement]]?*/ +*** Internal links +- Italic :: /Link to [[file:single-posts/post_with_underscore_in_name.org][another post on this site]]?/ +- Bold :: *Link to [[file:single-posts/post_with_underscore_in_name.org][another post on this site]]?* +- Bold + Italic :: /*Link to [[file:single-posts/post_with_underscore_in_name.org][another post on this site]]?*/ ** Single and Double quotes :PROPERTIES: :EXPORT_FILE_NAME: single-double-quotes diff --git a/test/site/content-org/single-posts/post_with_underscore_in_name.org b/test/site/content-org/single-posts/post_with_underscore_in_name.org new file mode 100644 index 0000000..e2f1171 --- /dev/null +++ b/test/site/content-org/single-posts/post_with_underscore_in_name.org @@ -0,0 +1,12 @@ +#+title: Post with underscore in name +#+author: +#+date: 2017-07-20 + +#+hugo_base_dir: ../../ +#+hugo_section: singles +#+hugo_tags: "cross-link" +#+description: Test post to test another ox-hugo test. + +This test post is created to test [{{< relref +"italicize-links-with-underscores" >}}]({{< relref +"italicize-links-with-underscores" >}}). diff --git a/test/site/content/posts/figure-shortcode-and-attr-html.md b/test/site/content/posts/figure-shortcode-and-attr-html.md index 819abb7..dabfee3 100644 --- a/test/site/content/posts/figure-shortcode-and-attr-html.md +++ b/test/site/content/posts/figure-shortcode-and-attr-html.md @@ -16,7 +16,7 @@ draft = false ## Setting `alt` parameter {#setting-alt-parameter} -[Reference](https://www.reddit.com/r/emacs/comments/71wy6n/orgmode_as_a_markup_language_does_make_sense_even/dnhqudn/) +[Reference](https://www.reddit.com/r/emacs/comments/71wy6n/orgmode%5Fas%5Fa%5Fmarkup%5Flanguage%5Fdoes%5Fmake%5Fsense%5Feven/dnhqudn/) {{< figure src="/images/org-mode-unicorn-logo.png" alt="Org-mode Unicorn Logo" >}} @@ -59,7 +59,7 @@ to the text that follows that image too._ ### Setting `:width` parameter {#setting-width-parameter} -The image [width](https://www.w3schools.com/tags/att_img_width.asp) can be specified in **pixels** using the `:width` +The image [width](https://www.w3schools.com/tags/att%5Fimg%5Fwidth.asp) can be specified in **pixels** using the `:width` parameter. **The height of the image will be resized proportionally.** Below image is shown 50 pixels wide. @@ -85,7 +85,7 @@ image is 200px × 200px. But the image will still show up in 1000px × --- -The image [height](https://www.w3schools.com/tags/att_img_height.asp) can be specified in **pixels** using the `:height` +The image [height](https://www.w3schools.com/tags/att%5Fimg%5Fheight.asp) can be specified in **pixels** using the `:height` parameter. **The weight of the image will be resized proportionally.** Below image is shown 50 pixels tall. @@ -137,7 +137,7 @@ Rendered this: **NOTE**: We cannot use `:style` in `#+attr_html` because Hugo does not _yet_ support a `style` argument in the `figure` shortcode - [[Source](https://github.com/gohugoio/hugo/blob/488631fe0abc3667355345c7eb98ba7a2204deb5/tpl/tplimpl/template_embedded.go#L22-L37)]. + [[Source](https://github.com/gohugoio/hugo/blob/488631fe0abc3667355345c7eb98ba7a2204deb5/tpl/tplimpl/template%5Fembedded.go#L22-L37)]. So using `#+html: ` and `#+attr_html: :class foo` as shown in the workaround above. diff --git a/test/site/content/posts/italicize-links-with-underscores.md b/test/site/content/posts/italicize-links-with-underscores.md new file mode 100644 index 0000000..8bba700 --- /dev/null +++ b/test/site/content/posts/italicize-links-with-underscores.md @@ -0,0 +1,32 @@ ++++ +title = "Italicize links with underscores" +description = "Test that links with underscores can be italicized/emboldened/both." +tags = ["body", "italic", "links", "underscore"] +draft = false ++++ + +`ox-hugo` Issue #[170](https://github.com/kaushalmodi/ox-hugo/issues/170) + + +## External links {#external-links} + +Italic +: _What is a [two's complement](https://en.wikipedia.org/wiki/Two%27s%5Fcomplement)?_ + +Bold +: **What is a [two's complement](https://en.wikipedia.org/wiki/Two%27s%5Fcomplement)?** + +Bold + Italic +: _**What is a [two's complement](https://en.wikipedia.org/wiki/Two%27s%5Fcomplement)?**_ + + +## Internal links {#internal-links} + +Italic +: _Link to [another post on this site]({{< relref "post_with_underscore_in_name" >}})?_ + +Bold +: **Link to [another post on this site]({{< relref "post_with_underscore_in_name" >}})?** + +Bold + Italic +: _**Link to [another post on this site]({{< relref "post_with_underscore_in_name" >}})?**_ diff --git a/test/site/content/posts/no-toc-in-summary--with-more.md b/test/site/content/posts/no-toc-in-summary--with-more.md index bcc688e..1557fd9 100644 --- a/test/site/content/posts/no-toc-in-summary--with-more.md +++ b/test/site/content/posts/no-toc-in-summary--with-more.md @@ -33,7 +33,7 @@ HTML comment **``** after the TOC. ## Snippet {#snippet} -As the `more` comment is present, the [`summary_minus_toc.html`](https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/summary_minus_toc.html) partial +As the `more` comment is present, the [`summary_minus_toc.html`](https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/summary%5Fminus%5Ftoc.html) partial used for this test site ensures that only the content between `` and `` is considered as summary. diff --git a/test/site/content/posts/no-toc-in-summary--without-more.md b/test/site/content/posts/no-toc-in-summary--without-more.md index 6a31623..88bc8ab 100644 --- a/test/site/content/posts/no-toc-in-summary--without-more.md +++ b/test/site/content/posts/no-toc-in-summary--without-more.md @@ -31,7 +31,7 @@ HTML comment **``** after the TOC. ## Snippet {#snippet} -As the `more` comment is not present, the [`summary_minus_toc.html`](https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/summary_minus_toc.html) +As the `more` comment is not present, the [`summary_minus_toc.html`](https://github.com/kaushalmodi/hugo-bare-min-theme/blob/master/layouts/partials/summary%5Fminus%5Ftoc.html) partial used for this test site ensures that only the first 300 (or so) characters after `` is considered as summary. diff --git a/test/site/content/real-examples/nn-intro.md b/test/site/content/real-examples/nn-intro.md index e32db75..462e5df 100644 --- a/test/site/content/real-examples/nn-intro.md +++ b/test/site/content/real-examples/nn-intro.md @@ -579,7 +579,7 @@ if __name__ == '__main__': net.gradient_descent(train_data, test_data, epoches=100, m=10, eta=2.0) ``` -数据加载脚本: [`mnist_loader.py`](https://github.com/mnielsen/neural-networks-and-deep-learning/blob/master/src/mnist_loader.py) +数据加载脚本: [`mnist_loader.py`](https://github.com/mnielsen/neural-networks-and-deep-learning/blob/master/src/mnist%5Floader.py) 。输入数据为二元组列表: `(input(784,1), output(10,1))` ```sh @@ -852,7 +852,7 @@ Round {30}: {9802}/{10000} 对于MNIST数字分类任务,目前最好的准确率为99.79%,那些识别错误的case,恐怕人类想 要正确识别也很困难。神经网络的分类效果最新进展可以参看这里: -[classification\\\_datasets\\\_results](http://rodrigob.github.io/are_we_there_yet/build/classification_datasets_results.html)。 +[classification\\\_datasets\\\_results](http://rodrigob.github.io/are%5Fwe%5Fthere%5Fyet/build/classification%5Fdatasets%5Fresults.html)。 本文是tensorflow官方推荐教程:[Neural Networks and Deep Learning](http://neuralnetworksanddeeplearning.com/)的笔记整理,原文 [Github Page](https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md)。 diff --git a/test/site/content/singles/post_with_underscore_in_name.md b/test/site/content/singles/post_with_underscore_in_name.md new file mode 100644 index 0000000..b3a9c11 --- /dev/null +++ b/test/site/content/singles/post_with_underscore_in_name.md @@ -0,0 +1,11 @@ ++++ +title = "Post with underscore in name" +description = "Test post to test another ox-hugo test." +date = 2017-07-20 +tags = ["cross-link"] +draft = false ++++ + +This test post is created to test [{{< relref +"italicize-links-with-underscores" >}}]({{< relref +"italicize-links-with-underscores" >}}).