Workaround for Blackfriday bug in italicizing links with underscores

Replaces underscores with "%5F" (hex code for underscores) in
links (only of http, https, ftp and mailto type).

- Fixes https://github.com/kaushalmodi/ox-hugo/issues/170.

Revert his commit once
https://github.com/russross/blackfriday/issues/278 gets fixed.
master
Kaushal Modi 8 years ago
parent b350b8772c
commit ad98ebf498
  1. 9
      ox-blackfriday.el
  2. 14
      ox-hugo.el
  3. 16
      test/site/content-org/all-posts.org
  4. 12
      test/site/content-org/single-posts/post_with_underscore_in_name.org
  5. 8
      test/site/content/posts/figure-shortcode-and-attr-html.md
  6. 32
      test/site/content/posts/italicize-links-with-underscores.md
  7. 2
      test/site/content/posts/no-toc-in-summary--with-more.md
  8. 2
      test/site/content/posts/no-toc-in-summary--without-more.md
  9. 4
      test/site/content/real-examples/nn-intro.md
  10. 11
      test/site/content/singles/post_with_underscore_in_name.md

@ -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

@ -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

@ -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

@ -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" >}}).

@ -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: <style>.foo img ... </style>` and `#+attr_html: :class
foo` as shown in the workaround above.

@ -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" >}})?**_

@ -33,7 +33,7 @@ HTML comment **`<!--endtoc-->`** 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
`<!--endtoc-->` and `<!--more-->` is considered as summary.

@ -31,7 +31,7 @@ HTML comment **`<!--endtoc-->`** 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 `<!--endtoc-->` is considered as summary.

@ -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)。

@ -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" >}}).
Loading…
Cancel
Save