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

Don't replace _ in links with %5f if using Goldmark #494

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ox-blackfriday.el
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,17 @@ style tag."
ret))

;;;; Sanitize URL
(defun org-blackfriday--url-sanitize (url)
(defun org-blackfriday--url-sanitize-maybe (info url)
"Sanitize the URL by replace certain characters with their hex encoding.

Replaces \"_\" with \"%5F\".
INFO is a plist used as a communication channel.

Replaces \"_\" with \"%5F\" only if :hugo-goldmark is nil.

Workaround for Blackfriday bug https://github.com/russross/blackfriday/issues/278."
(replace-regexp-in-string "_" "%5F" url))
(if (not (org-blackfriday--plist-get-true-p info :hugo-goldmark))
(replace-regexp-in-string "_" "%5F" url)
url))

;;;; Blackfriday Issue 239 Workaround
(defun org-blackfriday--issue-239-workaround (code parent-type)
Expand Down
2 changes: 1 addition & 1 deletion ox-hugo.el
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ and rewrite link paths to make blogging more seamless."

(when (and (stringp raw-path)
link-is-url)
(setq raw-path (org-blackfriday--url-sanitize
(setq raw-path (org-blackfriday--url-sanitize-maybe info
(url-encode-url raw-path))))
;; (message "[ox-hugo-link DBG] link: %S" link)
;; (message "[ox-hugo-link DBG] link path: %s" (org-element-property :path link))
Expand Down
33 changes: 25 additions & 8 deletions test/site/content-org/all-posts.org
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@ stop
:PROPERTIES:
:EXPORT_FILE_NAME: embedded-video
:END:
{{{oxhugoissue(274)}}}

[[https://www.w3schools.com/html/html5_video.asp][Using ~video~ HTML5 tag]]

#+begin_export html
<video width="320" height="240" controls>
<video width="320" height="240" controls>
<source src="/videos/sample.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Expand Down Expand Up @@ -2372,22 +2374,37 @@ 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:
** Italicize links with underscores (Goldmark) :italic:links:underscore:goldmark:
:PROPERTIES:
:EXPORT_FILE_NAME: italicize-links-with-underscores
:EXPORT_FILE_NAME: italicize-links-with-underscores-goldmark
:EXPORT_HUGO_ALIASES: italicize-links-with-underscores
:EXPORT_HUGO_GOLDMARK: t
:END:
#+begin_description
Test that links with underscores can be italicized/emboldened/both.
Test that links with underscores can be italicized/emboldened/both
without replacing underscores with ~%5f~.
#+end_description
{{{oxhugoissue(170)}}}
{{{oxhugoissue(308)}}}, {{{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]]?*/
- Italic :: /What is a [[https://en.wikipedia.org/wiki/Two's_complement][two's complement]]?/
- Bold :: *What is a [[https://en.wikipedia.org/wiki/Two's_complement][two's complement]]?*
- Bold + Italic :: /*What is a [[https://en.wikipedia.org/wiki/Two's_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]]?*/
** Italicize links with underscores (Blackfriday) :italic:links:underscore:blackfriday:
:PROPERTIES:
:EXPORT_FILE_NAME: italicize-links-with-underscores-blackfriday
:EXPORT_HUGO_GOLDMARK:
:END:
#+begin_description
Test that links with underscores can be italicized/emboldened/both.
#+end_description
{{{oxhugoissue(170)}}}
- Italic :: /What is a [[https://en.wikipedia.org/wiki/Two's_complement][two's complement]]?/
- Bold :: *What is a [[https://en.wikipedia.org/wiki/Two's_complement][two's complement]]?*
- Bold + Italic :: /*What is a [[https://en.wikipedia.org/wiki/Two's_complement][two's complement]]?*/
** Single and Double quotes
:PROPERTIES:
:EXPORT_FILE_NAME: single-double-quotes
Expand Down
6 changes: 4 additions & 2 deletions test/site/content/posts/embedded-video.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ tags = ["videos", "embedded"]
draft = false
+++

[Using `video` HTML5 tag](https://www.w3schools.com/html/html5%5Fvideo.asp)
`ox-hugo` Issue #[274](https://github.com/kaushalmodi/ox-hugo/issues/274)

<video width="320" height="240" controls>
[Using `video` HTML5 tag](https://www.w3schools.com/html/html5_video.asp)

<video width="320" height="240" controls>
<source src="/videos/sample.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Expand Down
8 changes: 4 additions & 4 deletions test/site/content/posts/figure-shortcode-and-attr-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ draft = false

## Setting `alt` parameter {#setting-alt-parameter}

[Reference](https://www.reddit.com/r/emacs/comments/71wy6n/orgmode%5Fas%5Fa%5Fmarkup%5Flanguage%5Fdoes%5Fmake%5Fsense%5Feven/dnhqudn/)
[Reference](https://www.reddit.com/r/emacs/comments/71wy6n/orgmode_as_a_markup_language_does_make_sense_even/dnhqudn/)

{{< figure src="/images/org-mode-unicorn-logo.png" alt="Org-mode Unicorn Logo" >}}

Expand Down Expand Up @@ -62,7 +62,7 @@ to the text that follows that image too._

### Setting `:width` parameter {#setting-width-parameter}

The image [width](https://www.w3schools.com/tags/att%5Fimg%5Fwidth.asp) can be specified in **pixels** using the `:width`
The image [width](https://www.w3schools.com/tags/att_img_width.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.
Expand All @@ -88,7 +88,7 @@ image is 200px × 200px. But the image will still show up in 1000px ×

---

The image [height](https://www.w3schools.com/tags/att%5Fimg%5Fheight.asp) can be specified in **pixels** using the `:height`
The image [height](https://www.w3schools.com/tags/att_img_height.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.
Expand Down Expand Up @@ -139,7 +139,7 @@ Rendered this:
{{< figure src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png" alt="Org mode logo" class="foo" width="300" >}}

**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%5Fembedded.go#L22-L37)
_yet_ support a `style` argument in the `figure` shortcode [ [Source](https://github.com/gohugoio/hugo/blob/488631fe0abc3667355345c7eb98ba7a2204deb5/tpl/tplimpl/template_embedded.go#L22-L37)
].

So using `#+html: <style>.foo img ... </style>` and `#+attr_html: :class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
+++
title = "Italicize links with underscores (Blackfriday)"
description = "Test that links with underscores can be italicized/emboldened/both."
tags = ["body", "italic", "links", "underscore", "blackfriday"]
draft = false
+++

`ox-hugo` Issue #[170](https://github.com/kaushalmodi/ox-hugo/issues/170)

Italic
: _What is a [two's complement](https://en.wikipedia.org/wiki/Two's%5Fcomplement)?_

Bold
: **What is a [two's complement](https://en.wikipedia.org/wiki/Two's%5Fcomplement)?**

Bold + Italic
: _**What is a [two's complement](https://en.wikipedia.org/wiki/Two's%5Fcomplement)?**_
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
+++
title = "Italicize links with underscores"
description = "Test that links with underscores can be italicized/emboldened/both."
tags = ["body", "italic", "links", "underscore"]
title = "Italicize links with underscores (Goldmark)"
description = """
Test that links with underscores can be italicized/emboldened/both
without replacing underscores with `%5f`.
"""
aliases = ["/posts/italicize-links-with-underscores"]
tags = ["body", "italic", "links", "underscore", "goldmark"]
draft = false
+++

`ox-hugo` Issue #[170](https://github.com/kaushalmodi/ox-hugo/issues/170)
`ox-hugo` Issue #[308](https://github.com/kaushalmodi/ox-hugo/issues/308), `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)?_
: _What is a [two's complement](https://en.wikipedia.org/wiki/Two's_complement)?_

Bold
: **What is a [two's complement](https://en.wikipedia.org/wiki/Two%27s%5Fcomplement)?**
: **What is a [two's complement](https://en.wikipedia.org/wiki/Two's_complement)?**

Bold + Italic
: _**What is a [two's complement](https://en.wikipedia.org/wiki/Two%27s%5Fcomplement)?**_
: _**What is a [two's complement](https://en.wikipedia.org/wiki/Two's_complement)?**_


## Internal links {#internal-links}
Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/no-toc-in-summary--with-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -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%5Fminus%5Ftoc.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_minus_toc.html) partial
used for this test site ensures that only the content between
`<!--endtoc-->` and `<!--more-->` is considered as summary.

Expand Down
2 changes: 1 addition & 1 deletion test/site/content/posts/no-toc-in-summary--without-more.md
Original file line number Diff line number Diff line change
Expand Up @@ -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%5Fminus%5Ftoc.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_minus_toc.html)
partial used for this test site ensures that only the first 300 (or
so) characters after `<!--endtoc-->` is considered as summary.

Expand Down
4 changes: 2 additions & 2 deletions test/site/content/real-examples/nn-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,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%5Floader.py)
数据加载脚本: [`mnist_loader.py`](https://github.com/mnielsen/neural-networks-and-deep-learning/blob/master/src/mnist_loader.py)
。输入数据为二元组列表: `(input(784,1), output(10,1))`

```sh
Expand Down Expand Up @@ -773,7 +773,7 @@ Round {30}: {9802}/{10000}
修改Size为 `[784,128,64,10]` 添加一层隐藏层,可以进一步提升测试集准确率至98.33%,验证集至98.24%。

对于MNIST数字分类任务,目前最好的准确率为99.79%,那些识别错误的case,恐怕人类想要正确识别也很困难。神经网络的分类效果最新进展可以参看这里:
[classification_datasets_results](http://rodrigob.github.io/are%5Fwe%5Fthere%5Fyet/build/classification%5Fdatasets%5Fresults.html)。
[classification_datasets_results](http://rodrigob.github.io/are_we_there_yet/build/classification_datasets_results.html)。

本文是tensorflow官方推荐教程:[Neural Networks and Deep Learning](http://neuralnetworksanddeeplearning.com/)的笔记整理,原文
[Github Page](https://github.com/Vonng/Math/blob/master/nndl/nn-intro.md)。