Skip to content

Commit

Permalink
Add md2html-enhance-footnote-filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopudark committed May 24, 2024
1 parent 5776faf commit 924682d
Show file tree
Hide file tree
Showing 28 changed files with 526 additions and 96 deletions.
57 changes: 45 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,58 @@ For an example, `md2md_enhance_equation_filter` in [enhance_equation.py](https:/

**Runtime status** can be recorded. In **python mode**, any filter function will return a proposed panflute `Doc`. Some filter functions will add an instance attribute dict `runtime_dict` to the returned `Doc`, as a record for **runtime status**, which may be very useful for advanced users. For an example, `md2md_enhance_equation_filter`, will add an instance attribute dict `runtime_dict` to the returned `Doc`, which may contain a mapping `{'math':True}` if there is any math element in the `Doc`.

All filters with corresponding registered command-line scripts, the specific features, and the recorded **runtime status** are recorded in the following table:
All filters with corresponding registered command-line scripts, the specific features, and the recorded **runtime status** are recorded as the following:

> [!NOTE]
>
> Since some filters need additional arguments, not all filter functions support **command-line-mode**, even though they all support **python-mode** indeed.
>
> All filters support cascaded invoking.
| Filter Functions | Command Line | Additional Arguments | Features | Runtime status (`doc.runtime_dict`) |
| ----------------------------------------------------------- | ----------------------------------------------------------- | -------------------- | :----------------------------------------------------------- | ------------------------------------------------------------ |
| md2md_convert_github_style_alert_to_hexo_style_alert_filter | md2md-convert-github-style-alert-to-hexo-style-alert-filter | - | Convert the [github-style alert](https://github.com/orgs/community/discussions/16925) to hexo-style alert. | - |
| md2md_enhance_equation_filter | md2md-enhance-equation-filter | - | Enhance math equations. Specifically, this filter will: Adapt AMS rule for math formula. Auto numbering markdown formulations within \begin{equation} \end{equation}, as in Typora. Allow multiple tags, but only take the first one. Allow multiple labels, but only take the first one. | {'math':< bool >,'equations_count':<some_number>} |
| md2md_norm_footnote_filter | md2md-norm-footnote-filter | - | Normalize the footnotes.| - |
| md2md_norm_internal_link_filter | md2md-norm-internal-link-filter | - | Normalize internal links' URLs. Decode the URL if it is URL-encoded. | - |
| md2md_upload_figure_to_aliyun_filter | - | doc_path | Auto upload local pictures to Aliyun OSS. Replace the original `src` with the new one. The following environment variables should be given in advance: `$Env:OSS_ENDPOINT_NAME`, `$Env:OSS_BUCKET_NAME`, `$Env:OSS_ACCESS_KEY_ID` , and `$Env:OSS_ACCESS_KEY_SECRET`. The doc_path should be given in advance. | {'doc_path':<doc_path>,'oss_helper':<Oss_Helper>} |
| md2html_centralize_figure_filter | md2html-centralize-figure-filter | - | ==Deprecated== | - |
| md2html_enhance_link_like_filter | md2html-enhance-link-like-filter | - | Enhance the link-like string to a `link` element. | - |
| md2html_hash_anchor_and_internal_link_filter | md2html-hash-anchor-and-internal-link-filter | - | Hash both the anchor's `id` and the internal-link's `url ` simultaneously. | {'anchor_count':<anchor_count_dict>,'internal_link_record':<internal_link_record_list>} |
| md2html_increase_header_level_filter | md2html-increase-header-level-filter | - | Increase the header level by `1`. | - |
- `pandoc_filter.filters.md2md.convert_github_style_alert_to_hexo_style_alert.run_filter`
- [source](./src/pandoc_filter/filters/md2md/convert_github_style_alert_to_hexo_style_alert.py)
- command-line: `md2md-convert-github-style-alert-to-hexo-style-alert-filter`
- main features: Convert the [github-style alert](https://github.com/orgs/community/discussions/16925) to hexo-style alert.
- `pandoc_filter.filters.md2md.enhance_equation.run_filter`
- [source](./src/pandoc_filter/filters/md2md/enhance_equation.py)
- command-line: `md2md-enhance-equation-filter`
- main features: Enhance math equations.
- Runtime status (`doc.runtime_dict`): ` {'math':< bool >,'equations_count':<some_number>}`
- `pandoc_filter.filters.md2md.norm_footnote.run_filter`
- [source](./src/pandoc_filter/filters/md2md/norm_internal_link.py)
- command-line: `md2md-norm-footnote-filter`
- main features: Normalize the footnotes.
- `pandoc_filter.filters.md2md.norm_internal_link.run_filter`
- [source](./src/pandoc_filter/filters/md2md/norm_internal_link.py)
- command-line: ` md2md-norm-internal-link-filter`
- main features: Normalize internal links' URLs.
- `pandoc_filter.filters.md2md.upload_figure_to_aliyun.run_filter`
- [source](./src/pandoc_filter/filters/md2md/upload_figure_to_aliyun.py)
- command-line: ==Unsupported.==
- Additional Arguments: `doc_path`
- main features: Auto upload local pictures to Aliyun OSS.
- Runtime status (`doc.runtime_dict`): {'doc_path':<doc_path>,'oss_helper':<Oss_Helper>}
- `pandoc_filter.filters.md2html.centralize_figure.run_filter`
- [source](./src/pandoc_filter/filters/md2html/centralize_figure.py)
- command-line: `md2html-centralize-figure-filter`
- main features: ==Deprecated==
- `pandoc_filter.filters.md2html.enhance_footnote.run_filter`
- [source](./src/pandoc_filter/filters/md2html/enhance_footnote.py)
- command-line: `md2html-enhance-footnote-filter`
- main features: Enhance the footnote.
- `pandoc_filter.filters.md2html.enhance_link_like.run_filter`
- [source](./src/pandoc_filter/filters/md2html/enhance_link_like.py)
- command-line: `md2html-enhance-link-like-filter`
- main features: Enhance the link-like string to a `link` element.
- `pandoc_filter.filters.md2html.hash_anchor_and_internal_link.run_filter`
- [source](./src/pandoc_filter/filters/md2html/hash_anchor_and_internal_link.py)
- command-line: `md2html-hash-anchor-and-internal-link-filter`
- main features: Hash both the anchor's `id` and the internal-link's `url ` simultaneously.
- Runtime status (`doc.runtime_dict`): `{'anchor_count':<anchor_count_dict>,'internal_link_record':<internal_link_record_list>}`
- `pandoc_filter.filters.md2html.increase_header_level.run_filter`
- [source](./src/pandoc_filter/filters/md2html/increase_header_level.py)
- command-line: `md2html-increase-header-level-filter`
- main features: Increase the header level by `1`.

# Samples

Expand Down
10 changes: 8 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

- Modify `md2md-norm-footnote-filter`. Now, it deals with the footnote content as follows:
- Remove unnecessary `\n`.
- Remove link.
- Normalize many formats like emphasis(italic) and strong(bold).
- Remove markdown link.
- Normalize many markdown formats like emphasis(italic) and strong(bold).

- Add `md2html-enhance-footnote-filter`. This filter will enhance the footnote content as follows:
- upgrade the link like string to a `link` element.
- Remove unnecessary `\n`.
- Remove markdown link.
- Normalize many markdown formats like emphasis(italic) and strong(bold).

## Release 0.2.14

Expand Down
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ dependencies = [
"oauth2client"
]
[project.scripts]
md2md-convert-github-style-alert-to-hexo-style-alert-filter = "pandoc_filter:md2md_convert_github_style_alert_to_hexo_style_alert_filter"
md2md-enhance-equation-filter = "pandoc_filter:md2md_enhance_equation_filter"
md2md-norm-footnote-filter = "pandoc_filter:md2md_norm_footnote_filter"
md2md-norm-internal-link-filter = "pandoc_filter:md2md_norm_internal_link_filter"
md2html-centralize-figure-filter = "pandoc_filter:md2html_centralize_figure_filter"
md2html-enhance-link-like-filter = "pandoc_filter:md2html_enhance_link_like_filter"
md2html-hash-anchor-and-internal-link-filter = "pandoc_filter:md2html_hash_anchor_and_internal_link_filter"
md2html-increase-header-level-filter = "pandoc_filter:md2html_increase_header_level_filter"

md2md-convert-github-style-alert-to-hexo-style-alert-filter = "pandoc_filter.filters.md2md.convert_github_style_alert_to_hexo_style_alert:run_filter"
md2md-enhance-equation-filter = "pandoc_filter.filters.md2md.enhance_equation:run_filter"
md2md-norm-footnote-filter = "pandoc_filter.filters.md2md.norm_footnote:run_filter"
md2md-norm-internal-link-filter = "pandoc_filter.filters.md2md.norm_internal_link:run_filter"
md2html-centralize-figure-filter = "pandoc_filter.filters.md2html.centralize_figure:run_filter"
md2html-enhance-footnote-filter = "pandoc_filter.filters.md2html.enhance_footnote:run_filter"
md2html-enhance-link-like-filter = "pandoc_filter.filters.md2html.enhance_link_like:run_filter"
md2html-hash-anchor-and-internal-link-filter = "pandoc_filter.filters.md2html.hash_anchor_and_internal_link:run_filter"
md2html-increase-header-level-filter = "pandoc_filter.filters.md2html.increase_header_level:run_filter"
# OR
[tool.setuptools.packages.find]
# # All the following settings are optional:
Expand Down
30 changes: 30 additions & 0 deletions resources/inputs/test_md2html_footnote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: test_md2html_footnote
---
duplicate1.[^1]

duplicate2.[^2]

duplicate3.[^3]

[^1]: Deep Learning with Intel® AVX-512 and Intel® DL Boost
https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html
www.intel.cn

[^2]: Deep Learning with Intel® AVX-512222 and Intel® DL Boost https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html www.intel.cn

[^3]: Deep Learning with Intel® AVX-512 and Intel® DL Boost https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html www.intel.cn


footnot.[^footnote_with_link]

[^footnote_with_link]: 技术文档 [技术文档 | Microsoft Learn](https://learn.microsoft.com/zh-cn/docs/)

emphasis(italic).[^4]

strong(bold).[^5]

[^4]:《Sorting algorithm》, *Wikipedia*. 2024年3月19日. 见于: 2024年5月22日. [在线]. 载于: https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&oldid=1214598553#Stability


[^5]:《Sorting algorithm》, **Wikipedia**. 2024年3月19日. 见于: 2024年5月22日. [在线]. 载于: https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&oldid=1214598553#Stability
2 changes: 1 addition & 1 deletion resources/inputs/test_md2html_header_anchor_and_link.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: test_md2html_anchor_and_link
title: test_md2html_header_anchor_and_link
---
# 引用链接

Expand Down
7 changes: 6 additions & 1 deletion resources/inputs/test_md2md_footnote.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ www.intel.cn
[^3]: Deep Learning with Intel® AVX-512 and Intel® DL Boost https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html www.intel.cn


footnot.[^footnote_with_link]

[^footnote_with_link]: 技术文档 [技术文档 | Microsoft Learn](https://learn.microsoft.com/zh-cn/docs/)

emphasis(italic).[^4]

strong(bold).[^5]

[^4]:《Sorting algorithm》, *Wikipedia*. 2024年3月19日. 见于: 2024年5月22日. [在线]. 载于: https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&oldid=1214598553#Stability


[^5]:《Sorting algorithm》, **Wikipedia**. 2024年3月19日. 见于: 2024年5月22日. [在线]. 载于: https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&oldid=1214598553#Stability
[^5]:《Sorting algorithm》, **Wikipedia**. 2024年3月19日. 见于: 2024年5月22日. [在线]. 载于: https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&oldid=1214598553#Stability
219 changes: 219 additions & 0 deletions resources/outputs/test_md2html_footnote.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>test_md2html_footnote</title>
<style>
html {
color: #1a1a1a;
background-color: #fdfdfd;
}
body {
margin: 0 auto;
max-width: 36em;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 50px;
hyphens: auto;
overflow-wrap: break-word;
text-rendering: optimizeLegibility;
font-kerning: normal;
}
@media (max-width: 600px) {
body {
font-size: 0.9em;
padding: 12px;
}
h1 {
font-size: 1.8em;
}
}
@media print {
html {
background-color: white;
}
body {
background-color: transparent;
color: black;
font-size: 12pt;
}
p, h2, h3 {
orphans: 3;
widows: 3;
}
h2, h3, h4 {
page-break-after: avoid;
}
}
p {
margin: 1em 0;
}
a {
color: #1a1a1a;
}
a:visited {
color: #1a1a1a;
}
img {
max-width: 100%;
}
svg {
height: auto;
max-width: 100%;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 1.4em;
}
h5, h6 {
font-size: 1em;
font-style: italic;
}
h6 {
font-weight: normal;
}
ol, ul {
padding-left: 1.7em;
margin-top: 1em;
}
li > ol, li > ul {
margin-top: 0;
}
blockquote {
margin: 1em 0 1em 1.7em;
padding-left: 1em;
border-left: 2px solid #e6e6e6;
color: #606060;
}
code {
font-family: Menlo, Monaco, Consolas, 'Lucida Console', monospace;
font-size: 85%;
margin: 0;
hyphens: manual;
}
pre {
margin: 1em 0;
overflow: auto;
}
pre code {
padding: 0;
overflow: visible;
overflow-wrap: normal;
}
.sourceCode {
background-color: transparent;
overflow: visible;
}
hr {
background-color: #1a1a1a;
border: none;
height: 1px;
margin: 1em 0;
}
table {
margin: 1em 0;
border-collapse: collapse;
width: 100%;
overflow-x: auto;
display: block;
font-variant-numeric: lining-nums tabular-nums;
}
table caption {
margin-bottom: 0.75em;
}
tbody {
margin-top: 0.5em;
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
}
th {
border-top: 1px solid #1a1a1a;
padding: 0.25em 0.5em 0.25em 0.5em;
}
td {
padding: 0.125em 0.5em 0.25em 0.5em;
}
header {
margin-bottom: 4em;
text-align: center;
}
#TOC li {
list-style: none;
}
#TOC ul {
padding-left: 1.3em;
}
#TOC > ul {
padding-left: 0;
}
#TOC a:not(:hover) {
text-decoration: none;
}
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
</style>
</head>
<body>
<header id="title-block-header">
<h1 class="title">test_md2html_footnote</h1>
</header>
<p>duplicate1.<a href="#fn1" class="footnote-ref" id="fnref1"
role="doc-noteref"><sup>1</sup></a></p>
<p>duplicate2.<a href="#fn2" class="footnote-ref" id="fnref2"
role="doc-noteref"><sup>2</sup></a></p>
<p>duplicate3.<a href="#fn3" class="footnote-ref" id="fnref3"
role="doc-noteref"><sup>3</sup></a></p>
<p>footnot.<a href="#fn4" class="footnote-ref" id="fnref4"
role="doc-noteref"><sup>4</sup></a></p>
<p>emphasis(italic).<a href="#fn5" class="footnote-ref" id="fnref5"
role="doc-noteref"><sup>5</sup></a></p>
<p>strong(bold).<a href="#fn6" class="footnote-ref" id="fnref6"
role="doc-noteref"><sup>6</sup></a></p>
<section id="footnotes" class="footnotes footnotes-end-of-document"
role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>Deep Learning with Intel® AVX-512 and Intel® DL Boost <a
href="https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html">https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html</a>
<a href="https://www.intel.cn">www.intel.cn</a> <a href="#fnref1"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>Deep Learning with Intel® AVX-512222 and Intel® DL Boost
<a
href="https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html">https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html</a>
<a href="https://www.intel.cn">www.intel.cn</a> <a href="#fnref2"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn3"><p>Deep Learning with Intel® AVX-512 and Intel® DL Boost <a
href="https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html">https://www.intel.cn/content/www/cn/zh/developer/articles/guide/deep-learning-with-avx512-and-dl-boost.html</a>
<a href="https://www.intel.cn">www.intel.cn</a> <a href="#fnref3"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn4"><p>技术文档 技术文档 | Microsoft Learn <a href="#fnref4"
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn5"><p>《Sorting algorithm》, Wikipedia. 2024年3月19日. 见于:
2024年5月22日. [在线]. 载于: <a
href="https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&amp;oldid=1214598553#Stability">https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&amp;oldid=1214598553#Stability</a>
<a href="#fnref5" class="footnote-back"
role="doc-backlink">↩︎</a></p></li>
<li id="fn6"><p>《Sorting algorithm》, Wikipedia. 2024年3月19日. 见于:
2024年5月22日. [在线]. 载于: <a
href="https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&amp;oldid=1214598553#Stability">https://en.wikipedia.org/w/index.php?title=Sorting_algorithm&amp;oldid=1214598553#Stability</a>
<a href="#fnref6" class="footnote-back"
role="doc-backlink">↩︎</a></p></li>
</ol>
</section>
</body>
</html>
Loading

0 comments on commit 924682d

Please sign in to comment.